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

assert_series_equal considers Nan is not different from real value #5731

Closed
2 tasks done
mingi3314 opened this issue Dec 7, 2022 · 1 comment · Fixed by #5732
Closed
2 tasks done

assert_series_equal considers Nan is not different from real value #5731

mingi3314 opened this issue Dec 7, 2022 · 1 comment · Fixed by #5732
Labels
bug Something isn't working python Related to Python Polars

Comments

@mingi3314
Copy link

Polars version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Issue description

assert_series_equal considers both Nan and real value as same.

I think this is because testing.asserts._assert_series_inner only check both left and right are null or not.

(left.is_null() != right.is_null()).any()

For example, let left is a series filled with nan values, and right is a series filled with a real values.
Then left.is_null() returns a series filled with False, and right.is_null() returns a series filled with False.
So both series are considered as same when checking missing values.

Suggestion

So, how about change

(left.is_null() != right.is_null()).any()
like as follows?

(left.fill_nan(None).is_null() != right.fill_nan(None).is_null()).any() 

If it's okay, can I work on it and submit a pull request?

Reproducible example

import polars as pl
from polars.testing import assert_series_equal

arr1 = pl.Series("a", [1.0, 2.0, 3.0, 4.0, 5.0])
arr2 = pl.Series("b", [1.0, 2.0, 3.0, 4.0, float("nan")])
arr3 = pl.Series("c", [1.0, 2.0, 3.0, 4.0, None])

assert_series_equal(arr1, arr2, check_names=False) # case 1
assert_series_equal(arr1, arr3, check_names=False) # case 2

Expected behavior

both case 1 and case 2 must raise AssertionError: Series are different
however, only case 2 raise AssertionError, whereas case 1 is considered as equal series

Installed versions

---Version info---
Polars: 0.15.2
Index type: UInt32
Platform: Linux-5.15.74.2-microsoft-standard-WSL2-x86_64-with-glibc2.31
Python: 3.9.12 (main, Apr 26 2022, 13:27:20) 
[GCC 9.4.0]
---Optional dependencies---
pyarrow: <not installed>
pandas: 1.5.2
numpy: 1.22.4
fsspec: <not installed>
connectorx: <not installed>
xlsx2csv: <not installed>
matplotlib: 3.5.2
@alexander-beedie
Copy link
Collaborator

@mingi3314; many thanks for the bug report - I found another edge-case while investigating your report, so ended-up extending the assert test coverage and fixing them both 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants