From 089031857f6fa8b9e9ae7743bc71875aebac2d68 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Tue, 14 Nov 2023 19:31:40 +0100 Subject: [PATCH] depr(python): Deprecate Series methods `is_boolean` and `is_utf8` --- py-polars/polars/series/series.py | 64 ++++++++++++---------- py-polars/tests/unit/series/test_series.py | 5 +- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/py-polars/polars/series/series.py b/py-polars/polars/series/series.py index 0bdd2852a7a0..38fa88ce429b 100644 --- a/py-polars/polars/series/series.py +++ b/py-polars/polars/series/series.py @@ -1594,13 +1594,13 @@ def describe( stats[f"{p:.0%}"] = s.quantile(p) stats["max"] = s.max() - elif self.is_boolean(): + elif self.dtype == Boolean: stats = { "count": self.len(), "null_count": self.null_count(), "sum": self.sum(), } - elif self.is_utf8(): + elif self.dtype == Utf8: stats = { "count": self.len(), "null_count": self.null_count(), @@ -3961,32 +3961,6 @@ def is_between( .to_series() ) - def is_boolean(self) -> bool: - """ - Check if this Series is a Boolean. - - Examples - -------- - >>> s = pl.Series("a", [True, False, True]) - >>> s.is_boolean() - True - - """ - return self.dtype is Boolean - - def is_utf8(self) -> bool: - """ - Check if this Series datatype is a Utf8. - - Examples - -------- - >>> s = pl.Series("x", ["a", "b", "c"]) - >>> s.is_utf8() - True - - """ - return self.dtype is Utf8 - def view(self, *, ignore_nulls: bool = False) -> SeriesView: """ Get a view into this Series data with a numpy array. @@ -6948,6 +6922,40 @@ def is_temporal(self, excluding: OneOrMoreDataTypes | None = None) -> bool: return self.dtype.is_temporal() + @deprecate_function("Use `Series.dtype == pl.Boolean` instead.", version="0.19.14") + def is_boolean(self) -> bool: + """ + Check if this Series is a Boolean. + + .. deprecated:: 0.19.14 + Use `Series.dtype == pl.Boolean` instead. + + Examples + -------- + >>> s = pl.Series("a", [True, False, True]) + >>> s.is_boolean() # doctest: +SKIP + True + + """ + return self.dtype is Boolean + + @deprecate_function("Use `Series.dtype == pl.Utf8` instead.", version="0.19.14") + def is_utf8(self) -> bool: + """ + Check if this Series datatype is a Utf8. + + .. deprecated:: 0.19.14 + Use `Series.dtype == pl.Utf8` instead. + + Examples + -------- + >>> s = pl.Series("x", ["a", "b", "c"]) + >>> s.is_utf8() # doctest: +SKIP + True + + """ + return self.dtype is Utf8 + # Keep the `list` and `str` properties below at the end of the definition of Series, # as to not confuse mypy with the type annotation `str` and `list` diff --git a/py-polars/tests/unit/series/test_series.py b/py-polars/tests/unit/series/test_series.py index 172180701d6e..0fc5b3578165 100644 --- a/py-polars/tests/unit/series/test_series.py +++ b/py-polars/tests/unit/series/test_series.py @@ -545,7 +545,10 @@ def test_series_dtype_is() -> None: assert not s.dtype.is_numeric() s = pl.Series("s", ["testing..."]) - assert s.is_utf8() + with pytest.deprecated_call(): + assert s.is_utf8() is True + with pytest.deprecated_call(): + assert s.is_boolean() is False s = pl.Series("s", [], dtype=pl.Decimal(precision=20, scale=15)) assert not s.dtype.is_float()