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

Unexpected behavior with binary operators and fill_value #12723

Closed
jcrist opened this issue Mar 28, 2016 · 3 comments
Closed

Unexpected behavior with binary operators and fill_value #12723

jcrist opened this issue Mar 28, 2016 · 3 comments
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@jcrist
Copy link
Contributor

jcrist commented Mar 28, 2016

From dask/dask#1063. fill_value doesn't seem to apply if the argument to a binary operator is a constant, but works fine for other arguments:

In [1]: import pandas as pd

In [2]: df = pd.DataFrame(range(10), columns=['foo'])

In [3]: df2 = df.copy()

In [4]: df2.iloc[0] = None

In [5]: df2.add(2, fill_value=0)
Out[5]:
    foo
0   NaN
1   3.0
2   4.0
3   5.0
4   6.0
5   7.0
6   8.0
7   9.0
8  10.0
9  11.0

In [6]: df2.add(df, fill_value=0)
Out[6]:
    foo
0   0.0
1   2.0
2   4.0
3   6.0
4   8.0
5  10.0
6  12.0
7  14.0
8  16.0
9  18.0

In [7]: pd.__version__
Out[7]: u'0.18.0rc2+2.g19e40a0'

From the docstring I'd expect it to be equivalent to df2.fillna(0).add(2). If this is intended behavior, then the docstring should be updated to clarify this.

@facaiy
Copy link
Contributor

facaiy commented Apr 4, 2016

I'd like to take a try.

@facaiy
Copy link
Contributor

facaiy commented Apr 4, 2016

It breaks here.

return self._combine_const(other, na_op) miss fill_value parameter.

So, we can fix it before the method or in the method of DataFrame,
which method is better?

@facaiy
Copy link
Contributor

facaiy commented Apr 4, 2016

The fix is not complete, I find that the unexpected behavior exists also in Series.

@sinhrks sinhrks changed the title Unexpected behavior with behavior with binary operators and fill_value Unexpected behavior with binary operators and fill_value Apr 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants