Skip to content

Commit

Permalink
depr(python): Deprecate Series methods is_boolean and is_utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Nov 14, 2023
1 parent 891b586 commit 0890318
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
64 changes: 36 additions & 28 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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`

Expand Down
5 changes: 4 additions & 1 deletion py-polars/tests/unit/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0890318

Please sign in to comment.