Skip to content
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

Add support for PandasArray for pandas<2.1.0 #15786

Merged
merged 2 commits into from
May 21, 2024
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
40 changes: 29 additions & 11 deletions python/cudf/cudf/pandas/_wrappers/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,17 +386,35 @@ def Index__new__(cls, *args, **kwargs):
},
)

NumpyExtensionArray = make_final_proxy_type(
"NumpyExtensionArray",
_Unusable,
pd.arrays.NumpyExtensionArray,
fast_to_slow=_Unusable(),
slow_to_fast=_Unusable(),
additional_attributes={
"_ndarray": _FastSlowAttribute("_ndarray"),
"_dtype": _FastSlowAttribute("_dtype"),
},
)
try:
from pandas.arrays import NumpyExtensionArray as pd_NumpyExtensionArray

NumpyExtensionArray = make_final_proxy_type(
"NumpyExtensionArray",
_Unusable,
pd_NumpyExtensionArray,
fast_to_slow=_Unusable(),
slow_to_fast=_Unusable(),
additional_attributes={
"_ndarray": _FastSlowAttribute("_ndarray"),
"_dtype": _FastSlowAttribute("_dtype"),
},
)

except ImportError:
from pandas.arrays import PandasArray as pd_PandasArray

PandasArray = make_final_proxy_type(
"PandasArray",
_Unusable,
pd_PandasArray,
fast_to_slow=_Unusable(),
slow_to_fast=_Unusable(),
additional_attributes={
"_ndarray": _FastSlowAttribute("_ndarray"),
"_dtype": _FastSlowAttribute("_dtype"),
},
)

TimedeltaArray = make_final_proxy_type(
"TimedeltaArray",
Expand Down
8 changes: 6 additions & 2 deletions python/cudf/cudf_pandas_tests/test_cudf_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,8 +1241,12 @@ def test_pickle_groupby(dataframe):

def test_numpy_extension_array():
np_array = np.array([0, 1, 2, 3])
xarray = xpd.arrays.NumpyExtensionArray(np_array)
array = pd.arrays.NumpyExtensionArray(np_array)
try:
xarray = xpd.arrays.NumpyExtensionArray(np_array)
array = pd.arrays.NumpyExtensionArray(np_array)
except AttributeError:
xarray = xpd.arrays.PandasArray(np_array)
array = pd.arrays.PandasArray(np_array)

tm.assert_equal(xarray, array)

Expand Down
Loading