Skip to content

Commit 91465ee

Browse files
more test fixes
1 parent 8058d9a commit 91465ee

File tree

6 files changed

+19
-4
lines changed

6 files changed

+19
-4
lines changed

pandas/core/arrays/sparse/array.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,8 @@ def __getitem__(
975975
# _NestedSequence[Union[bool, int]]], ...]]"
976976
data_slice = self.to_dense()[key] # type: ignore[index]
977977
elif isinstance(key, slice):
978+
if key == slice(None):
979+
return type(self)._simple_new(self.sp_values, self.sp_index, self.dtype)
978980
# Avoid densifying when handling contiguous slices
979981
if key.step is None or key.step == 1:
980982
start = 0 if key.start is None else key.start

pandas/core/dtypes/astype.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
from pandas.core.dtypes.dtypes import (
2727
CategoricalDtype,
28+
DatetimeTZDtype,
2829
ExtensionDtype,
2930
IntervalDtype,
3031
NumpyEADtype,
@@ -286,7 +287,9 @@ def astype_is_view(dtype: DtypeObj, new_dtype: DtypeObj) -> bool:
286287
new_dtype = getattr(new_dtype, "numpy_dtype", new_dtype)
287288
return getattr(dtype, "unit", None) == getattr(new_dtype, "unit", None)
288289

289-
elif new_dtype == object and isinstance(dtype, (PeriodDtype, IntervalDtype)):
290+
elif new_dtype == object and isinstance(
291+
dtype, (DatetimeTZDtype, PeriodDtype, IntervalDtype)
292+
):
290293
return False
291294

292295
elif isinstance(dtype, CategoricalDtype) and not isinstance(

pandas/tests/base/test_conversion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def test_array(arr, attr, index_or_series):
285285
arr = getattr(arr, attr)
286286
result = getattr(result, attr)
287287

288-
assert result is arr
288+
assert np.shares_memory(result, arr)
289289

290290

291291
def test_array_multiindex_raises():

pandas/tests/extension/base/setitem.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,4 +510,9 @@ def test_readonly_propagates_to_numpy_array_method(self, data):
510510
# non-NA fill value should always result in a copy
511511
if data.isna().any():
512512
arr = data.to_numpy(copy=False, na_value=data[0])
513-
assert arr.flags.writeable
513+
if isinstance(data.dtype, pd.ArrowDtype) and data.dtype.kind == "f":
514+
# for float dtype, after the fillna, the conversion from pyarrow to
515+
# numpy is zero-copy, and pyarrow will mark the array as readonly
516+
assert not arr.flags.writeable
517+
else:
518+
assert arr.flags.writeable

pandas/tests/extension/json/array.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ def __array__(self, dtype=None, copy=None):
155155
raise ValueError(
156156
"Unable to avoid copy while creating an array as requested."
157157
)
158-
159158
if dtype is None:
160159
dtype = object
161160
if dtype == object:

pandas/tests/extension/json/test_json.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ def test_setitem_slice_array(self, data):
418418
def test_setitem_invalid(self, data, invalid_scalar):
419419
super().test_setitem_invalid(data, invalid_scalar)
420420

421+
@pytest.mark.xfail(
422+
reason="result readonly flag is incorrect and does not support na_value"
423+
)
424+
def test_readonly_propagates_to_numpy_array_method(self, data):
425+
super().test_readonly_propagates_to_numpy_array_method(data)
426+
421427
@pytest.mark.xfail(reason="only integer scalar arrays can be converted")
422428
def test_setitem_2d_values(self, data):
423429
super().test_setitem_2d_values(data)

0 commit comments

Comments
 (0)