Skip to content

ENH: df.add fill_value NotImplementedError #13488

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

Closed
neverforgit opened this issue Jun 19, 2016 · 4 comments
Closed

ENH: df.add fill_value NotImplementedError #13488

neverforgit opened this issue Jun 19, 2016 · 4 comments
Assignees
Labels
Enhancement Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Needs Discussion Requires discussion from core team before further action Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@neverforgit
Copy link

neverforgit commented Jun 19, 2016

It appears that fill_value option for the df.add() method is not actually implemented in the source code. This was brought up in a StackOverflow question.

piRSquared is the user that identified it.

The following are all copied from that SO post.

Code Sample, a copy-pastable example if possible

import pandas as pd
import numpy as np

np.random.seed([3,1415])
df = pd.DataFrame(np.random.choice((1, 2, np.nan), (5, 5)))
s = pd.Series(range(5))
df.add(s, fill_value=0)
>>>
  ---------------------------------------------------------------------------
  NotImplementedError                       Traceback (most recent call last)
  <ipython-input-18-ce2809aeda79> in <module>()
  ----> 1 df.add(s, fill_value=0)

  /Users/daddy30000/anaconda/lib/python2.7/site-packages/pandas/core/ops.pyc in f(self, other, axis, level, fill_value)
     1060             return self._combine_frame(other, na_op, fill_value, level)
     1061         elif isinstance(other, ABCSeries):
  -> 1062             return self._combine_series(other, na_op, fill_value, axis, level)
     1063         elif isinstance(other, (list, tuple)):
     1064             if axis is not None and self._get_axis_name(axis) == 'index':

  /Users/daddy30000/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in _combine_series(self, other, func, fill_value, axis, level)
     3511             else:
     3512                 return self._combine_match_columns(other, func, level=level,
  -> 3513                                                    fill_value=fill_value)
     3514         return self._combine_series_infer(other, func, level=level,
     3515                                           fill_value=fill_value)

  /Users/daddy30000/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in _combine_match_columns(self, other, func, level, fill_value)
     3542         if fill_value is not None:
     3543             raise NotImplementedError("fill_value %r not supported" %
  -> 3544                                       fill_value)
     3545
     3546         new_data = left._data.eval(func=func, other=right,

  NotImplementedError: fill_value 0 not supported

Expected Output

   0    1     2     3    4  
0  1.0  1.0  2.0  3.0  4.0  
1  2.0  3.0  2.0  4.0  4.0  
2  1.0  1.0  3.0  4.0  4.0  
3  1.0  1.0  2.0  4.0  6.0  
4  1.0  3.0  4.0  3.0  5.0

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Darwin
OS-release: 15.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.1
setuptools: 21.2.1
Cython: 0.22.1
numpy: 1.11.0
scipy: 0.15.1
statsmodels: 0.6.1
xarray: None
IPython: 3.2.0
sphinx: 1.3.1
patsy: 0.3.0
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: 1.0.0
tables: 3.2.0
numexpr: 2.4.3
matplotlib: 1.4.3
openpyxl: 1.8.5
xlrd: 0.9.3
xlwt: 1.0.0
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.5
pymysql: None
psycopg2: 2.5.4 (dt dec pq3 ext)
jinja2: 2.7.3
boto: 2.38.0
pandas_datareader: None
@jreback
Copy link
Contributor

jreback commented Jun 19, 2016

simply df.fillna(0).add(s).

I'll mark it, but these things are generally would need outside patches.

@jreback jreback added Enhancement Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Reshaping Concat, Merge/Join, Stack/Unstack, Explode Difficulty Novice labels Jun 19, 2016
@jreback jreback added this to the Next Major Release milestone Jun 19, 2016
@jreback jreback changed the title df.add fill_value NotImplementedError ENH: df.add fill_value NotImplementedError Jun 19, 2016
evectant pushed a commit to evectant/pandas that referenced this issue Jun 1, 2017
evectant pushed a commit to evectant/pandas that referenced this issue Jun 2, 2017
@MTKnife
Copy link

MTKnife commented Mar 15, 2018

simply df.fillna(0).add(s).

That works for some use cases, but it doesn't work when you want to add two objects with different indices. E.g.:

foo = DataFrame([[1, 2, 3], [4, 5, 6]])
bar = Series([7, 8, 9, 10])

If I want to add these two together, I'd like to be able to assume that missing columns in "foo" are 0 values (it's the kind of thing that can happen easily when you're adding new data to old data--in my case, a vocabulary that expands over time), like this:

foo.add(bar, axis = 0, fill_value = 0)

Yes, I can still do this by reindexing "foo" before calling "add", but that involves more work than a simple "fillna") call. Not only is it a pain, but it prevents me from taking advantage of polymorphism: for example, right now I'm working on an application where the argument of an "add" can be either a DataFrame or a Series, and the app worked fine while the argument was a DataFrame, leaving me with a bug that I discovered only when I accidentally supplied a set of arguments that created a Series.

@jbrockmendel jbrockmendel added the Numeric Operations Arithmetic, Comparison, and Logical operations label Dec 11, 2019
@jonathanrhughes
Copy link

take

jonathanrhughes added a commit to jonathanrhughes/pandas that referenced this issue Feb 28, 2020
@mroeschke mroeschke added Needs Discussion Requires discussion from core team before further action and removed Reshaping Concat, Merge/Join, Stack/Unstack, Explode good first issue labels May 1, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@mroeschke
Copy link
Member

Superseded by #32608 so closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Needs Discussion Requires discussion from core team before further action Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
7 participants