Skip to content

Commit 6134d10

Browse files
committed
(fix): remove unnecessary casting + nbytes
1 parent bddccce commit 6134d10

File tree

4 files changed

+5
-24
lines changed

4 files changed

+5
-24
lines changed

xarray/core/indexing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,10 @@ def copy(self, deep: bool = True) -> Self:
19261926
array = self.array.copy(deep=True) if deep else self.array
19271927
return type(self)(array, self._dtype)
19281928

1929+
@property
1930+
def nbytes(self) -> int:
1931+
return self.array.nbytes
1932+
19291933

19301934
class PandasMultiIndexingAdapter(PandasIndexingAdapter):
19311935
"""Handles explicit indexing for a pandas.MultiIndex.

xarray/core/variable.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ def _maybe_wrap_data(data):
192192
if isinstance(data, pd.Index):
193193
return PandasIndexingAdapter(data)
194194
if isinstance(data, pd.api.extensions.ExtensionArray):
195-
if isinstance(data.dtype, pd.Int64Dtype | pd.Float64Dtype | pd.StringDtype):
196-
return np.array(data)
197195
return PandasExtensionArray(data)
198196
return data
199197

xarray/tests/test_dataset.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4380,13 +4380,7 @@ def test_setitem_pandas(self) -> None:
43804380
ds = self.make_example_math_dataset()
43814381
ds["x"] = np.arange(3)
43824382
ds_copy = ds.copy()
4383-
series = ds["bar"].to_pandas()
4384-
# to_pandas will actually give the result where the internal array of the series is a NumpyExtensionArray
4385-
# but ds["bar"] is a numpy array.
4386-
# TODO: should assert_equal be updated to handle?
4387-
assert (ds["bar"] == series).all()
4388-
del ds["bar"]
4389-
del ds_copy["bar"]
4383+
ds_copy["bar"] = ds["bar"].to_pandas()
43904384
assert_equal(ds, ds_copy)
43914385

43924386
def test_setitem_auto_align(self) -> None:
@@ -4977,19 +4971,6 @@ def test_to_and_from_dataframe(self) -> None:
49774971
expected = pd.DataFrame([[]], index=idx)
49784972
assert expected.equals(actual), (expected, actual)
49794973

4980-
def test_from_dataframe_int_float_str_pandas_dtype(self) -> None:
4981-
df = pd.DataFrame([1, 2, 3], dtype=pd.Int64Dtype())
4982-
ds = xr.Dataset.from_dataframe(df)
4983-
assert isinstance(ds[0].data, np.ndarray)
4984-
4985-
df = pd.DataFrame([1, 2, 3], dtype=pd.Float64Dtype())
4986-
ds = xr.Dataset.from_dataframe(df)
4987-
assert isinstance(ds[0].data, np.ndarray)
4988-
4989-
df = pd.DataFrame(["1", "2", "3"], dtype=pd.StringDtype())
4990-
ds = xr.Dataset.from_dataframe(df)
4991-
assert isinstance(ds[0].data, np.ndarray)
4992-
49934974
def test_from_dataframe_categorical_dtype_index(self) -> None:
49944975
cat = pd.CategoricalIndex(list("abcd"))
49954976
df = pd.DataFrame({"f": [0, 1, 2, 3]}, index=cat)

xarray/tests/test_pandas_to_xarray.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ def index_flat(request):
104104
index fixture, but excluding MultiIndex cases.
105105
"""
106106
key = request.param
107-
if key in ["bool-object", "bool-dtype", "nullable_bool", "repeats"]:
108-
pytest.xfail(reason="doesn't work")
109107
return indices_dict[key].copy()
110108

111109

0 commit comments

Comments
 (0)