Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ def test_is_nan_or_none():
is_nan_or_none(pl.Series([np.nan, 1.0, None])).to_numpy(),
np.array([True, False, True]),
)
for values in (["a", None, "b"], [True, None, False], [1, None, 2]):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move these to the is_nan test

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved them to test_is_nan in a4c1d45. They check is_nan on string, boolean, integer and categorical series, and is_nan_or_none on the same series.

np.testing.assert_equal(
is_nan_or_none(pl.Series(values)).to_numpy(),
np.array([False, True, False]),
)
np.testing.assert_equal(
is_nan_or_none(
pl.Series(["a", None, "b"], dtype=pl.Categorical)
).to_numpy(),
np.array([False, True, False]),
)


def test_vertical_concat_pd():
Expand Down
4 changes: 4 additions & 0 deletions utilsforecast/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ def is_none(s: Series) -> Series:


def is_nan_or_none(s: Series) -> Series:
if isinstance(s, pl_Series) and not s.dtype.is_float():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move this to the is_nan function. in the polars branch we can check if its float and call is_nan and otherwise return a series filled with false

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a4c1d45. is_nan now calls is_nan only for polars float columns and returns an all-false series otherwise, and is_nan_or_none is back to is_nan(s) | is_none(s).

# polars only supports is_nan on numeric columns and only floats
# can hold NaN, so other columns (e.g. strings) can only have nulls
return s.is_null()
return is_nan(s) | is_none(s)


Expand Down