Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

depr(python): Deprecate Series methods is_boolean and is_utf8 #12457

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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