Skip to content

Commit

Permalink
DO NOT MERGE: convert deprecation warnings into errors
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Nov 16, 2023
1 parent 2ae7f9b commit 95299b5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 69 deletions.
62 changes: 28 additions & 34 deletions python/lsst/daf/butler/dimensions/_coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@
__all__ = ("DataCoordinate", "DataId", "DataIdKey", "DataIdValue", "SerializedDataCoordinate")

import numbers
import warnings
from abc import abstractmethod
from collections.abc import Iterable, Iterator, Mapping, Set
from typing import TYPE_CHECKING, Any, ClassVar, Literal, cast, overload

from deprecated.sphinx import deprecated
from lsst.daf.butler._compat import _BaseModelCompat
from lsst.sphgeom import IntersectionRegion, Region
from lsst.utils.introspection import find_outside_stacklevel

from .._named import NamedKeyMapping, NamedValueAbstractSet, NameLookupMapping
from .._timespan import Timespan
Expand Down Expand Up @@ -216,13 +214,10 @@ def standardize(
)
if graph is not None:
# TODO: remove argument on DM-41326.
warnings.warn(
raise FutureWarning(

Check warning on line 217 in python/lsst/daf/butler/dimensions/_coordinate.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_coordinate.py#L217

Added line #L217 was not covered by tests
"The 'graph' argument to DataCoordinate.standardize is deprecated in favor of the "
"'dimensions' argument, and will be removed after v27.",
category=FutureWarning,
stacklevel=find_outside_stacklevel("lsst.daf.butler"),
"'dimensions' argument, and will be removed after v27."
)
dimensions = graph.names
if dimensions is not None:
dimensions = universe.conform(dimensions)
del graph # make sure we don't actualy use this below
Expand All @@ -243,13 +238,10 @@ def standardize(
if mapping.hasFull():
new_mapping.update((name, mapping[name]) for name in mapping.dimensions.implied)
elif isinstance(mapping, NamedKeyMapping):
warnings.warn(
raise FutureWarning(

Check warning on line 241 in python/lsst/daf/butler/dimensions/_coordinate.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_coordinate.py#L241

Added line #L241 was not covered by tests
"Passing a NamedKeyMapping to DataCoordinate.standardize is deprecated, and will be "
"removed after v27.",
category=FutureWarning,
stacklevel=find_outside_stacklevel("lsst.daf.butler"),
"removed after v27."
)
new_mapping.update(mapping.byName())
elif mapping is not None:
new_mapping.update(mapping)
new_mapping.update(kwargs)
Expand Down Expand Up @@ -346,6 +338,7 @@ def makeEmpty(universe: DimensionUniverse) -> DataCoordinate:
"removed after v27.",
version="v27",
category=FutureWarning,
action="error",
)
def fromRequiredValues(graph: DimensionGraph, values: tuple[DataIdValue, ...]) -> DataCoordinate:
"""Construct a `DataCoordinate` from required dimension values.
Expand Down Expand Up @@ -411,6 +404,7 @@ def from_required_values(dimensions: DimensionGroup, values: tuple[DataIdValue,
"removed after v27.",
version="v27",
category=FutureWarning,
action="error",
)
def fromFullValues(graph: DimensionGraph, values: tuple[DataIdValue, ...]) -> DataCoordinate:
"""Construct a `DataCoordinate` from all dimension values.
Expand Down Expand Up @@ -497,6 +491,7 @@ def __lt__(self, other: Any) -> bool:
".mapping and .required attributes, and will be dropped after v27.",
version="v27",
category=FutureWarning,
action="error",
)
def __iter__(self) -> Iterator[Dimension]:
return iter(self.keys())
Expand All @@ -507,6 +502,7 @@ def __iter__(self) -> Iterator[Dimension]:
".mapping and .required attributes, and will be dropped after v27.",
version="v27",
category=FutureWarning,
action="error",
)
def __len__(self) -> int:
return len(self.keys())
Expand All @@ -517,6 +513,7 @@ def __len__(self) -> int:
".mapping and .required attributes, and will be dropped after v27.",
version="v27",
category=FutureWarning,
action="error",
)
def keys(self) -> NamedValueAbstractSet[Dimension]: # type: ignore
return self.graph.required
Expand All @@ -528,6 +525,7 @@ def keys(self) -> NamedValueAbstractSet[Dimension]: # type: ignore
"attribute, and will be dropped after v27.",
version="v27",
category=FutureWarning,
action="error",
)
def names(self) -> Set[str]:
"""Names of the required dimensions identified by this data ID.
Expand Down Expand Up @@ -655,6 +653,7 @@ def dimensions(self) -> DimensionGroup:
"DataCoordinate.graph is deprecated in favor of .dimensions, and will be dropped after v27.",
version="v27",
category=FutureWarning,
action="error",
)
def graph(self) -> DimensionGraph:
"""Dimensions identified by this data ID (`DimensionGraph`).
Expand Down Expand Up @@ -687,6 +686,7 @@ def hasFull(self) -> bool:
"DataCoordinate.full is deprecated in favor of .mapping, and will be dropped after v27.",
version="v27",
category=FutureWarning,
action="error",
)
@abstractmethod
def full(self) -> NamedKeyMapping[Dimension, DataIdValue]:
Expand All @@ -708,6 +708,7 @@ def full(self) -> NamedKeyMapping[Dimension, DataIdValue]:
"after v27.",
version="v27",
category=FutureWarning,
action="error",
)
def values_tuple(self) -> tuple[DataIdValue, ...]:
"""Return the required values (only) of this data ID as a tuple.
Expand Down Expand Up @@ -844,6 +845,7 @@ def pack(self, name: str, *, returnMaxBits: Literal[False]) -> int:
"Deprecated in favor of configurable dimension packers. Will be removed after v26.",
version="v26",
category=FutureWarning,
action="error",
)
def pack(self, name: str, *, returnMaxBits: bool = False) -> tuple[int, int] | int:
"""Pack this data ID into an integer.
Expand Down Expand Up @@ -1026,12 +1028,9 @@ def __str__(self) -> str:

def __getitem__(self, key: DimensionElement | str) -> DimensionRecord | None:
if isinstance(key, DimensionElement):
warnings.warn(
"Using Dimension keys in DataCoordinate is deprecated and will not be supported after v27.",
category=FutureWarning,
stacklevel=find_outside_stacklevel("lsst.daf.butler"),
raise FutureWarning(

Check warning on line 1031 in python/lsst/daf/butler/dimensions/_coordinate.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_coordinate.py#L1031

Added line #L1031 was not covered by tests
"Using Dimension keys in DataCoordinate is deprecated and will not be supported after v27."
)
key = key.name
return self._target._record(key)

# TODO: fix on DM-41326.
Expand All @@ -1040,6 +1039,7 @@ def __getitem__(self, key: DimensionElement | str) -> DimensionRecord | None:
"v27. Use DataCoordinate.dimensions.elements to get the names of all dimension elements instead.",
version="v27",
category=FutureWarning,
action="error",
)
def __iter__(self) -> Iterator[DimensionElement]:
return iter(self.keys())
Expand All @@ -1058,6 +1058,7 @@ def keys(self) -> NamedValueAbstractSet[DimensionElement]: # type: ignore
"will be removed after v27.",
version="v27",
category=FutureWarning,
action="error",
)
def names(self) -> Set[str]:
# Docstring inherited from `NamedKeyMapping`.
Expand Down Expand Up @@ -1103,12 +1104,9 @@ def __getitem__(self, key: DataIdKey) -> DataIdValue:
# Docstring inherited from DataCoordinate.
# TODO: remove on DM-41326.
if isinstance(key, Dimension):
warnings.warn(
"Using Dimension keys in DataCoordinate is deprecated and will not be supported after v27.",
category=FutureWarning,
stacklevel=find_outside_stacklevel("lsst.daf.butler"),
raise FutureWarning(

Check warning on line 1107 in python/lsst/daf/butler/dimensions/_coordinate.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_coordinate.py#L1107

Added line #L1107 was not covered by tests
"Using Dimension keys in DataCoordinate is deprecated and will not be supported after v27."
)
key = key.name
index = self._dimensions._data_coordinate_indices[key]
try:
return self._values[index]
Expand All @@ -1124,6 +1122,7 @@ def __getitem__(self, key: DataIdKey) -> DataIdValue:
"Use `dict(data_id.required)` as an exact replacement for `data_id.byName()`.",
version="v27",
category=FutureWarning,
action="error",
)
def byName(self) -> dict[str, DataIdValue]:
# Docstring inheritance.
Expand Down Expand Up @@ -1265,10 +1264,8 @@ def expanded(
for d in self._dimensions.implied
)
if isinstance(records, NamedKeyMapping):
warnings.warn(
"NamedKeyMappings will not be accepted after v27; pass a Mapping with str keys instead.",
stacklevel=find_outside_stacklevel("lsst.daf.butler"),
category=FutureWarning,
raise FutureWarning(

Check warning on line 1267 in python/lsst/daf/butler/dimensions/_coordinate.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_coordinate.py#L1267

Added line #L1267 was not covered by tests
"NamedKeyMappings will not be accepted after v27; pass a Mapping with str keys instead."
)
return _ExpandedTupleDataCoordinate(self._dimensions, values, records)

Expand Down Expand Up @@ -1335,6 +1332,7 @@ def union(self, other: DataCoordinate) -> DataCoordinate:
"DataCoordinate.full is deprecated in favor of .mapping, and will be dropped after v27.",
version="v27",
category=FutureWarning,
action="error",
)
def full(self) -> NamedKeyMapping[Dimension, DataIdValue]:
# Docstring inherited.
Expand All @@ -1345,10 +1343,8 @@ def expanded(
) -> DataCoordinate:
# Docstring inherited from DataCoordinate
if isinstance(records, NamedKeyMapping):
warnings.warn(
"NamedKeyMappings will not be accepted after v27; pass a Mapping with str keys instead.",
stacklevel=find_outside_stacklevel("lsst.daf.butler"),
category=FutureWarning,
raise FutureWarning(

Check warning on line 1346 in python/lsst/daf/butler/dimensions/_coordinate.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_coordinate.py#L1346

Added line #L1346 was not covered by tests
"NamedKeyMappings will not be accepted after v27; pass a Mapping with str keys instead."
)
return _ExpandedTupleDataCoordinate(self._dimensions, self._values, records)

Expand Down Expand Up @@ -1406,10 +1402,8 @@ def expanded(
) -> DataCoordinate:
# Docstring inherited from DataCoordinate.
if isinstance(records, NamedKeyMapping):
warnings.warn(
"NamedKeyMappings will not be accepted after v27; pass a Mapping with str keys instead.",
stacklevel=find_outside_stacklevel("lsst.daf.butler"),
category=FutureWarning,
raise FutureWarning(

Check warning on line 1405 in python/lsst/daf/butler/dimensions/_coordinate.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_coordinate.py#L1405

Added line #L1405 was not covered by tests
"NamedKeyMappings will not be accepted after v27; pass a Mapping with str keys instead."
)
return self

Expand Down
11 changes: 3 additions & 8 deletions python/lsst/daf/butler/dimensions/_data_coordinate_iterable.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@
"DataCoordinateSequence",
)

import warnings
from abc import abstractmethod
from collections.abc import Collection, Iterable, Iterator, Sequence, Set
from typing import Any, overload

from deprecated.sphinx import deprecated
from lsst.utils.introspection import find_outside_stacklevel

from ._coordinate import DataCoordinate
from ._graph import DimensionGraph
Expand Down Expand Up @@ -84,6 +82,7 @@ def fromScalar(dataId: DataCoordinate) -> _ScalarDataCoordinateIterable:
"Deprecated in favor of .dimensions; will be removed after v26.",
category=FutureWarning,
version="v27",
action="error",
)
def graph(self) -> DimensionGraph:
"""Dimensions identified by these data IDs (`DimensionGraph`)."""
Expand Down Expand Up @@ -312,17 +311,13 @@ def __init__(
"universe must be provided, either directly or via dimensions, dataIds, or graph."
)
if graph is not None:
warnings.warn(
raise FutureWarning(

Check warning on line 314 in python/lsst/daf/butler/dimensions/_data_coordinate_iterable.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_data_coordinate_iterable.py#L314

Added line #L314 was not covered by tests
"The 'graph' argument to DataCoordinateIterable constructors is deprecated in favor of "
" passing an iterable of dimension names as the 'dimensions' argument, and wil be removed "
"after v27.",
stacklevel=find_outside_stacklevel("lsst.daf.butler"),
category=FutureWarning,
"after v27."
)
if dimensions is not None:
dimensions = universe.conform(dimensions)
elif graph is not None:
dimensions = graph.as_group()
del graph # Avoid accidental use later.
if dimensions is None:
raise TypeError("Exactly one of 'graph' or (preferably) 'dimensions' must be provided.")

Check warning on line 323 in python/lsst/daf/butler/dimensions/_data_coordinate_iterable.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_data_coordinate_iterable.py#L323

Added line #L323 was not covered by tests
Expand Down
41 changes: 14 additions & 27 deletions python/lsst/daf/butler/dimensions/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@

__all__ = ["DimensionGraph", "SerializedDimensionGraph"]

import warnings
from collections.abc import Iterable, Iterator, Mapping, Set
from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, cast

from deprecated.sphinx import deprecated
from lsst.daf.butler._compat import _BaseModelCompat
from lsst.utils.classes import cached_getter, immutable
from lsst.utils.introspection import find_outside_stacklevel

from .._named import NamedValueAbstractSet, NameMappingSetView
from .._topology import TopologicalFamily, TopologicalSpace
Expand Down Expand Up @@ -90,6 +88,7 @@ def __init__(self, keys: Set[str], universe: DimensionUniverse):
+ "Use a dict comprehension and DimensionUniverse indexing to construct a mapping when needed.",
version="v27",
category=FutureWarning,
action="error",
)
def asMapping(self) -> Mapping[str, _T]:
return super().asMapping()

Check warning on line 94 in python/lsst/daf/butler/dimensions/_graph.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_graph.py#L94

Added line #L94 was not covered by tests
Expand All @@ -99,6 +98,7 @@ def asMapping(self) -> Mapping[str, _T]:
_NVAS_DEPRECATION_MSG + "Use DimensionUniverse for DimensionElement lookups.",
version="v27",
category=FutureWarning,
action="error",
)
def __getitem__(self, key: str | _T) -> _T:
return super().__getitem__(key)

Check warning on line 104 in python/lsst/daf/butler/dimensions/_graph.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_graph.py#L104

Added line #L104 was not covered by tests
Expand All @@ -107,71 +107,56 @@ def __contains__(self, key: Any) -> bool:
from ._elements import DimensionElement

if isinstance(key, DimensionElement):
warnings.warn(
_NVAS_DEPRECATION_MSG + "'in' expressions must use str keys.",
category=FutureWarning,
stacklevel=find_outside_stacklevel("lsst.daf.butler."),
)
raise FutureWarning(_NVAS_DEPRECATION_MSG + "'in' expressions must use str keys.")

Check warning on line 110 in python/lsst/daf/butler/dimensions/_graph.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_graph.py#L110

Added line #L110 was not covered by tests
return super().__contains__(key)

def __iter__(self) -> Iterator[_T]:
# TODO: Remove on DM-41326.
warnings.warn(
raise FutureWarning(

Check warning on line 115 in python/lsst/daf/butler/dimensions/_graph.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_graph.py#L115

Added line #L115 was not covered by tests
_NVAS_DEPRECATION_MSG
+ (
"In the future, iteration will yield str names; for now, use .names "
"to do the same without triggering this warning."
),
category=FutureWarning,
stacklevel=find_outside_stacklevel("lsst.daf.butler."),
)
)
return super().__iter__()

def __eq__(self, other: Any) -> bool:
# TODO: Remove on DM-41326.
warnings.warn(
raise FutureWarning(

Check warning on line 125 in python/lsst/daf/butler/dimensions/_graph.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_graph.py#L125

Added line #L125 was not covered by tests
_NVAS_DEPRECATION_MSG
+ (
"In the future, set-equality will assume str keys; for now, use .names "
"to do the same without triggering this warning."
),
category=FutureWarning,
stacklevel=find_outside_stacklevel("lsst.daf.butler."),
)
)
return super().__eq__(other)

def __le__(self, other: Set[Any]) -> bool:
# TODO: Remove on DM-41326.
warnings.warn(
raise FutureWarning(

Check warning on line 135 in python/lsst/daf/butler/dimensions/_graph.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_graph.py#L135

Added line #L135 was not covered by tests
_NVAS_DEPRECATION_MSG
+ (
"In the future, subset tests will assume str keys; for now, use .names "
"to do the same without triggering this warning."
),
category=FutureWarning,
stacklevel=find_outside_stacklevel("lsst.daf.butler."),
)
)
return super().__le__(other)

def __ge__(self, other: Set[Any]) -> bool:
# TODO: Remove on DM-41326.
warnings.warn(
raise FutureWarning(

Check warning on line 145 in python/lsst/daf/butler/dimensions/_graph.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/dimensions/_graph.py#L145

Added line #L145 was not covered by tests
_NVAS_DEPRECATION_MSG
+ (
"In the future, superset tests will assume str keys; for now, use .names "
"to do the same without triggering this warning."
),
category=FutureWarning,
stacklevel=find_outside_stacklevel("lsst.daf.butler."),
)
)
return super().__ge__(other)


# TODO: Remove on DM-41326.
@deprecated(
"DimensionGraph is deprecated in favor of DimensionGroup and will be removed after v27.",
category=FutureWarning,
version="v27",
action="error",
)
@immutable
class DimensionGraph:
Expand Down Expand Up @@ -500,6 +485,7 @@ def __and__(self, other: DimensionGroup | DimensionGraph) -> DimensionGraph:
"use .lookup_order. DimensionGraph will be removed after v27.",
category=FutureWarning,
version="v27",
action="error",
)
def primaryKeyTraversalOrder(self) -> tuple[DimensionElement, ...]:
"""A tuple of all elements in specific order.
Expand Down Expand Up @@ -531,6 +517,7 @@ def temporal(self) -> NamedValueAbstractSet[TopologicalFamily]:
"use .spatial or .temporal. DimensionGraph will be removed after v27.",
category=FutureWarning,
version="v27",
action="error",
)
def topology(self) -> Mapping[TopologicalSpace, NamedValueAbstractSet[TopologicalFamily]]:
"""Families of elements in this graph that can participate in
Expand Down

0 comments on commit 95299b5

Please sign in to comment.