Skip to content

Avoid listifying left/right operand in ExtensionArray ops dispatching #22922

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

We now have the follow code in the ExtensionArray ops dispatching:

pandas/pandas/core/ops.py

Lines 1169 to 1192 in 2f1b842

# TODO(jreback)
# we need to listify to avoid ndarray, or non-same-type extension array
# dispatching
if is_extension_array_dtype(left):
new_left = left.values
if isinstance(right, np.ndarray):
# handle numpy scalars, this is a PITA
# TODO(jreback)
new_right = lib.item_from_zerodim(right)
if is_scalar(new_right):
new_right = [new_right]
new_right = list(new_right)
elif is_extension_array_dtype(right) and type(left) != type(right):
new_right = list(new_right)
else:
new_right = right
else:
new_left = list(left.values)
new_right = right

There are a few places where we convert the values to a list, which should be avoided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExtensionArrayExtending pandas with custom dtypes or arrays.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions