From 23c367b59f410af5ec4e0a31ba749995366f6cb2 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Tue, 14 Nov 2023 21:41:28 +0100 Subject: [PATCH] depr(python): Deprecate DataType method `is_not` (#12458) --- py-polars/polars/datatypes/classes.py | 12 +++++++++++- py-polars/polars/utils/_construction.py | 2 +- py-polars/tests/unit/datatypes/test_duration.py | 2 +- py-polars/tests/unit/datatypes/test_struct.py | 5 +++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/py-polars/polars/datatypes/classes.py b/py-polars/polars/datatypes/classes.py index 39d6c989b9af..bec9d0983300 100644 --- a/py-polars/polars/datatypes/classes.py +++ b/py-polars/polars/datatypes/classes.py @@ -148,6 +148,9 @@ def is_not(self, other: PolarsDataType) -> bool: """ Check if this DataType is NOT the same as another DataType. + .. deprecated:: 0.19.14 + Use `not dtype.is_(...)` instead. + This is a stricter check than `self != other`, as it enforces an exact match of all dtype attributes for nested and/or uninitialised dtypes. @@ -160,10 +163,17 @@ def is_not(self, other: PolarsDataType) -> bool: -------- >>> pl.List != pl.List(pl.Int32) False - >>> pl.List.is_not(pl.List(pl.Int32)) + >>> pl.List.is_not(pl.List(pl.Int32)) # doctest: +SKIP True """ + from polars.utils.deprecation import issue_deprecation_warning + + issue_deprecation_warning( + "`DataType.is_not` is deprecated and will be removed in the next breaking release." + " Use `not dtype.is_(...)` instead.", + version="0.19.14", + ) return not self.is_(other) @classproperty diff --git a/py-polars/polars/utils/_construction.py b/py-polars/polars/utils/_construction.py index bef8d953587c..308bcbc9fb1e 100644 --- a/py-polars/polars/utils/_construction.py +++ b/py-polars/polars/utils/_construction.py @@ -542,7 +542,7 @@ def sequence_to_pyseries( return PySeries.new_object(name, values, strict) if dtype: srs = sequence_from_anyvalue_and_dtype_or_object(name, values, dtype) - if dtype.is_not(srs.dtype()): + if not dtype.is_(srs.dtype()): srs = srs.cast(dtype, strict=False) return srs return sequence_from_anyvalue_or_object(name, values) diff --git a/py-polars/tests/unit/datatypes/test_duration.py b/py-polars/tests/unit/datatypes/test_duration.py index f1e0959e8647..145608d47c00 100644 --- a/py-polars/tests/unit/datatypes/test_duration.py +++ b/py-polars/tests/unit/datatypes/test_duration.py @@ -15,4 +15,4 @@ def test_duration_cumsum() -> None: pl.Duration(time_unit="ms"), pl.Duration(time_unit="ns"), ): - assert df.schema["A"].is_not(duration_dtype) # type: ignore[arg-type] + assert df.schema["A"].is_(duration_dtype) is False # type: ignore[arg-type] diff --git a/py-polars/tests/unit/datatypes/test_struct.py b/py-polars/tests/unit/datatypes/test_struct.py index 12c076ff81c4..c04cc13b4b02 100644 --- a/py-polars/tests/unit/datatypes/test_struct.py +++ b/py-polars/tests/unit/datatypes/test_struct.py @@ -85,8 +85,9 @@ def test_struct_equality_strict() -> None: ) # strict - assert not (s1.is_(s2)) - assert s1.is_not(s2) + assert s1.is_(s2) is False + with pytest.deprecated_call(): + assert s1.is_not(s2) is True # permissive (default) assert s1 == s2