Skip to content

BUG: op(frame, series) raising NotImplementedError with extension dtypes #34311

Closed
@jorisvandenbossche

Description

@jorisvandenbossche
In [1]: df = pd.DataFrame(np.random.randint(0, 100, (10, 3)), dtype="Int64", columns=['a', 'b', 'c']) 

In [2]: s = pd.Series([1, 2, 3], dtype="int64", index=["a", "b", "c"])

In [3]: df + s 
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-3-c26e56e5136b> in <module>
----> 1 df + s

~/scipy/pandas/pandas/core/ops/__init__.py in f(self, other, axis, level, fill_value)
    715             axis = self._get_axis_number(axis) if axis is not None else 1
    716             new_data = _combine_series_frame(
--> 717                 self, other, pass_op, axis=axis, str_rep=str_rep
    718             )
    719         else:

~/scipy/pandas/pandas/core/ops/__init__.py in _combine_series_frame(left, right, func, axis, str_rep)
    516 
    517         array_op = get_array_op(func, str_rep=str_rep)
--> 518         bm = left._mgr.apply(array_op, right=rvalues.T, align_keys=["right"])
    519         return type(left)(bm)
    520 

~/scipy/pandas/pandas/core/internals/managers.py in apply(self, f, align_keys, **kwargs)
    393 
    394             if callable(f):
--> 395                 applied = b.apply(f, **kwargs)
    396             else:
    397                 applied = getattr(b, f)(**kwargs)

~/scipy/pandas/pandas/core/internals/blocks.py in apply(self, func, **kwargs)
    334         """
    335         with np.errstate(all="ignore"):
--> 336             result = func(self.values, **kwargs)
    337 
    338         return self._split_op_result(result)

~/scipy/pandas/pandas/core/ops/array_ops.py in arithmetic_op(left, right, op, str_rep)
    198     if should_extension_dispatch(lvalues, rvalues) or isinstance(rvalues, Timedelta):
    199         # Timedelta is included because numexpr will fail on it, see GH#31457
--> 200         res_values = op(lvalues, rvalues)
    201 
    202     else:

~/scipy/pandas/pandas/core/ops/common.py in new_method(self, other)
     63         other = item_from_zerodim(other)
     64 
---> 65         return method(self, other)
     66 
     67     return new_method

~/scipy/pandas/pandas/core/arrays/integer.py in integer_arithmetic_method(self, other)
    578 
    579             if getattr(other, "ndim", 0) > 1:
--> 580                 raise NotImplementedError("can only perform ops with 1-d structures")
    581 
    582             if isinstance(other, IntegerArray):

NotImplementedError: can only perform ops with 1-d structures

In [4]: df.astype(int) + s  
Out[4]: 
    a   b   c
0  86  53  66
1  77  26  56
2  11   5  45
3  97  21  84
4  20  72  38
5  62  45   7
6  91  34  20
7  26   5  98
8  18  55  66
9  86  33  80

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExtensionArrayExtending pandas with custom dtypes or arrays.Numeric OperationsArithmetic, Comparison, and Logical operationsRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions