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

API: Series/DataFrame logical op NaN propagation #13896

Closed
sinhrks opened this issue Aug 3, 2016 · 1 comment · Fixed by #29531
Closed

API: Series/DataFrame logical op NaN propagation #13896

sinhrks opened this issue Aug 3, 2016 · 1 comment · Fixed by #29531
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented Aug 3, 2016

The same as #13806, but for discuss differences with DataFrame.

pd.Series([True, False, np.nan]) | pd.Series([True, False, True])
#0     True
#1    False
#2    False
# dtype: bool

pd.Series([True, False, True]) | pd.Series([True, False, np.nan])
#0     True
#1    False
#2     True
# dtype: bool

pd.DataFrame([True, False, np.nan]) | pd.DataFrame([True, False, True])
#        0
#0   True
#1  False
#2    NaN

pd.DataFrame([True, False, True]) | pd.DataFrame([True, False, np.nan])
#        0
#0   True
#1  False
#2    NaN

There looks to be 2 points:

1. NaN comparison result

As @TomAugspurger described in #13806, the basic rule is below. Based on this, DataFrame result is incorrect.

In [40]: float('nan') or 1
Out[40]: nan

In [41]: 1 or float('nan')
Out[41]: 1

2. filling NaN result

Series fills NaN included in the result with False. DataFrame should also?

@sinhrks sinhrks added API Design Numeric Operations Arithmetic, Comparison, and Logical operations labels Aug 3, 2016
@sinhrks sinhrks changed the title Series/DataFrame logical op NaN propagation API: Series/DataFrame logical op NaN propagation Aug 3, 2016
@jorisvandenbossche jorisvandenbossche added this to the 0.19.0 milestone Aug 18, 2016
@jreback jreback modified the milestones: 0.19.0, Next Major Release Sep 28, 2016
@jorisvandenbossche jorisvandenbossche modified the milestones: 1.0, Next Major Release Oct 26, 2016
@mroeschke
Copy link
Member

This looks fixed on master. Could use a test:

In [96]: pd.Series([True, False, np.nan]) | pd.Series([True, False, True])
    ...:
Out[96]:
0     True
1    False
2    False
dtype: bool

In [97]: pd.Series([True, False, True]) | pd.Series([True, False, np.nan])
    ...:
Out[97]:
0     True
1    False
2     True
dtype: bool

In [98]: pd.DataFrame([True, False, np.nan]) | pd.DataFrame([True, False, True])
    ...:
Out[98]:
       0
0   True
1  False
2  False

In [99]: pd.DataFrame([True, False, True]) | pd.DataFrame([True, False, np.nan])
    ...:
Out[99]:
       0
0   True
1  False
2   True

In [100]: pd.__version__
Out[100]: '0.26.0.dev0+593.g9d45934af'

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed API Design Numeric Operations Arithmetic, Comparison, and Logical operations labels Oct 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants