Skip to content

CLN: Add axis kwarg to Series wrapper for compat #5352

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

Merged
merged 1 commit into from
Oct 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pandas/core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,9 @@ def _flex_method_SERIES(op, name, str_rep=None, default_axis=None,
""" % name

@Appender(doc)
def f(self, other, level=None, fill_value=None):
def flex_wrapper(self, other, level=None, fill_value=None, axis=0):
# validate axis
self._get_axis_number(axis)
if isinstance(other, pd.Series):
return self._binop(other, op, level=level, fill_value=fill_value)
elif isinstance(other, (pa.Array, pd.Series, list, tuple)):
Expand All @@ -675,8 +677,8 @@ def f(self, other, level=None, fill_value=None):
return self._constructor(op(self.values, other),
self.index).__finalize__(self)

f.__name__ = name
return f
flex_wrapper.__name__ = name
return flex_wrapper

series_flex_funcs = dict(flex_arith_method=_flex_method_SERIES,
radd_func=_radd_compat,
Expand Down
26 changes: 18 additions & 8 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3241,21 +3241,31 @@ def _check_fill(meth, op, a, b, fill_value=0):
a = Series([nan, 1., 2., 3., nan], index=np.arange(5))
b = Series([nan, 1, nan, 3, nan, 4.], index=np.arange(6))

ops = [Series.add, Series.sub, Series.mul, Series.pow,
Series.truediv, Series.div]
equivs = [operator.add, operator.sub, operator.mul, operator.pow,
operator.truediv]
pairings = []
for op in ['add', 'sub', 'mul', 'pow', 'truediv', 'floordiv']:
fv = 0
lop = getattr(Series, op)
lequiv = getattr(operator, op)
rop = getattr(Series, 'r' + op)
# bind op at definition time...
requiv = lambda x, y, op=op: getattr(operator, op)(y, x)
pairings.append((lop, lequiv, fv))
pairings.append((rop, requiv, fv))

if compat.PY3:
equivs.append(operator.truediv)
pairings.append((Series.div, operator.truediv, 1))
pairings.append((Series.rdiv, lambda x, y: operator.truediv(y, x), 1))
else:
equivs.append(operator.div)
fillvals = [0, 0, 1, 1]
pairings.append((Series.div, operator.div, 1))
pairings.append((Series.rdiv, lambda x, y: operator.div(y, x), 1))

for op, equiv_op, fv in zip(ops, equivs, fillvals):
for op, equiv_op, fv in pairings:
result = op(a, b)
exp = equiv_op(a, b)
assert_series_equal(result, exp)
_check_fill(op, equiv_op, a, b, fill_value=fv)
# should accept axis=0 or axis='rows'
op(a, b, axis=0)

def test_combine_first(self):
values = tm.makeIntIndex(20).values.astype(float)
Expand Down