Frame ops prelims - de-duplicate, remove unused kwargs by jbrockmendel · Pull Request #19522 · pandas-dev/pandas (original) (raw)
Starting in on making DataFrame ops consistent with Series and Index ops. As a first pass, this goes through and removes some duplicate code and unused arguments.
Changes logic in exactly two corner cases: arithmetic operations frame.op(series, axis=None, fill_value=not_none)
where one of series
or frame
has length zero. axis
needs to be specifically passed as None
to hit the changed case.
ser = pd.Series([])
df = pd.DataFrame([[1, 2], [3, 4]])
>>> df.add(ser, axis=None, fill_value='E')
>>> ser.to_frame().sub(df[0], axis=None, fill_value=3)
will now raise instead of returning
>>> df.add(ser, axis=None, fill_value='E')
0 1
0 NaN NaN
1 NaN NaN
>>> ser.to_frame().sub(df[0], axis=None, fill_value=3)
Empty DataFrame
Columns: [0]
Index: []