Skip to content

REF: avoid broadcasting of Series to DataFrame in ops for ArrayManager #40482

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

8 changes: 7 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@
)
from pandas.core.array_algos.take import take_2d_multi
from pandas.core.arraylike import OpsMixin
from pandas.core.arrays import ExtensionArray
from pandas.core.arrays import (
ExtensionArray,
TimedeltaArray,
)
from pandas.core.arrays.sparse import SparseFrameAccessor
from pandas.core.construction import (
extract_array,
Expand Down Expand Up @@ -6675,6 +6678,9 @@ def _dispatch_frame_op(self, right, func: Callable, axis: Optional[int] = None):

right = right._values

if isinstance(right, TimedeltaArray):
right = right._data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. this is AM-only right?
  2. wont the array_op call just re-wrap this?
  3. if not, will something like DataFrame[int] + Series[timedelta64ns] fail to raise because of this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. if this is a hack as the commit message suggests, then a comment would be worthwhile

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #40482 (comment) for the general explanation of in which case this happens. It was not my intention to keep this, I am hoping to find a better solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah I saw that, thought about commenting, but decided that "last time i handled that by reshaping to 2D" wouldn't be something you'd find that helpful.


arrays = [
array_op(_left, _right)
for _left, _right in zip(self._iter_column_arrays(), right)
Expand Down