Skip to content

Commit

Permalink
depr(python): Deprecate DataType method is_not (#12458)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego authored Nov 14, 2023
1 parent ab3c445 commit 23c367b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
12 changes: 11 additions & 1 deletion py-polars/polars/datatypes/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/utils/_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/unit/datatypes/test_duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
5 changes: 3 additions & 2 deletions py-polars/tests/unit/datatypes/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 23c367b

Please sign in to comment.