Skip to content

BUG: Operations not implemented for non-1D ExtensionArrays #20

@Nadav-Zilberberg

Description

@Nadav-Zilberberg

Reproducible Example

mypy: ignore-errors

import pandas as pd
import numpy as np
import pandas._testing as tm

df = pd.DataFrame(np.arange(50).reshape(10, 5)).notna().values

-> works

NP_array = pd.array([i for i in range(10)], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]).reshape(10,1) #dtype: NumpyExtensionArray

-> doesnt work (NotImplemented)

EA_array = pd.array([i for i in range(10)], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape(10,1) #dtype: IntExtensionArray

print(df * NP_array)

NotImplementedError: can only perform ops with 1-d structures

print(df * EA_array)
Issue Description
I was working on creating test cases for ExtensionArrays following comments on PR pandas-dev#61828 when I realized that I could not use the '&' operation on EAs like I could with NP arrays.

After a bit of digging around, it appears they both call self._logical_method, but whereas NP returns NotImplemented and continues operation, EA raises an error.

If someone wants to take a look while I work on something else, they are more than welcome to, otherwise I can work out a fix when I come back to it.

I have found that to be the case for both '*' and '&' so it's probably something deeper there

Expected Behavior
Operators should function the same for both Numpy arrays and other ExtensionArrays

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions