Skip to content

Commit 61d4e80

Browse files
jbrockmendelyehoshuadimarsky
authored andcommitted
CLN: address xfails (pandas-dev#46287)
1 parent 1857cfd commit 61d4e80

File tree

16 files changed

+25
-76
lines changed

16 files changed

+25
-76
lines changed

pandas/core/arrays/_mixins.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,8 @@ def _concat_same_type(
222222
raise ValueError("to_concat must have the same dtype (tz)", dtypes)
223223

224224
new_values = [x._ndarray for x in to_concat]
225-
new_values = np.concatenate(new_values, axis=axis)
226-
# error: Argument 1 to "_from_backing_data" of "NDArrayBackedExtensionArray" has
227-
# incompatible type "List[ndarray]"; expected "ndarray"
228-
return to_concat[0]._from_backing_data(new_values) # type: ignore[arg-type]
225+
new_arr = np.concatenate(new_values, axis=axis)
226+
return to_concat[0]._from_backing_data(new_arr)
229227

230228
@doc(ExtensionArray.searchsorted)
231229
def searchsorted(

pandas/core/arrays/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ def _sub_datetimelike_scalar(self, other):
10951095

10961096
_sub_datetime_arraylike = _sub_datetimelike_scalar
10971097

1098-
def _sub_period(self, other):
1098+
def _sub_period(self, other: Period):
10991099
# Overridden by PeriodArray
11001100
raise TypeError(f"cannot subtract Period from a {type(self).__name__}")
11011101

pandas/core/arrays/period.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,7 @@ def _cast_quantile_result(self, res_values: np.ndarray) -> np.ndarray:
707707
# ------------------------------------------------------------------
708708
# Arithmetic Methods
709709

710-
def _sub_datelike(self, other):
711-
assert other is not NaT
712-
return NotImplemented
713-
714-
def _sub_period(self, other):
710+
def _sub_period(self, other: Period):
715711
# If the operation is well-defined, we return an object-Index
716712
# of DateOffsets. Null entries are filled with pd.NaT
717713
self._check_compatible_with(other)

pandas/core/arrays/sparse/array.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,10 @@ def _first_fill_value_loc(self):
838838
return np.searchsorted(diff, 2) + 1
839839

840840
def unique(self: SparseArrayT) -> SparseArrayT:
841-
uniques = list(algos.unique(self.sp_values))
841+
uniques = algos.unique(self.sp_values)
842842
fill_loc = self._first_fill_value_loc()
843843
if fill_loc >= 0:
844-
uniques.insert(fill_loc, self.fill_value)
844+
uniques = np.insert(uniques, fill_loc, self.fill_value)
845845
return type(self)._from_sequence(uniques, dtype=self.dtype)
846846

847847
def _values_for_factorize(self):
@@ -1351,8 +1351,6 @@ def to_dense(self) -> np.ndarray:
13511351
"""
13521352
return np.asarray(self, dtype=self.sp_values.dtype)
13531353

1354-
_internal_get_values = to_dense
1355-
13561354
def _where(self, mask, value):
13571355
# NB: may not preserve dtype, e.g. result may be Sparse[float64]
13581356
# while self is Sparse[int64]

pandas/core/arrays/sparse/dtype.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ def update_dtype(self, dtype) -> SparseDtype:
354354
if not isinstance(dtype, np.dtype):
355355
raise TypeError("sparse arrays of extension dtypes not supported")
356356

357-
fill_value = astype_nansafe(np.array(self.fill_value), dtype).item()
357+
fvarr = astype_nansafe(np.array(self.fill_value), dtype)
358+
# NB: not fv_0d.item(), as that casts dt64->int
359+
fill_value = fvarr[0]
358360
dtype = cls(dtype, fill_value=fill_value)
359361

360362
return dtype

pandas/core/dtypes/cast.py

+7
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ def trans(x):
379379
if np.allclose(new_result, result, equal_nan=True, rtol=0.0, atol=atol):
380380
return new_result
381381

382+
elif dtype.kind == result.dtype.kind == "c":
383+
new_result = result.astype(dtype)
384+
385+
if array_equivalent(new_result, result):
386+
# TODO: use tolerance like we do for float?
387+
return new_result
388+
382389
return result
383390

384391

pandas/tests/arrays/sparse/test_array.py

-4
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ def test_dense_repr(self, vals, fill_value):
127127
res = arr.to_dense()
128128
tm.assert_numpy_array_equal(res, vals)
129129

130-
res2 = arr._internal_get_values()
131-
132-
tm.assert_numpy_array_equal(res2, vals)
133-
134130
@pytest.mark.parametrize("fix", ["arr", "zarr"])
135131
def test_pickle(self, fix, request):
136132
obj = request.getfixturevalue(fix)

pandas/tests/arrays/sparse/test_astype.py

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ def test_astype_all(self, any_real_numpy_dtype):
8585
np.array([0, 1], dtype="datetime64[ns]"),
8686
dtype=SparseDtype("datetime64[ns]", Timestamp("1970")),
8787
),
88-
marks=[pytest.mark.xfail(reason="NumPy-7619")],
8988
),
9089
(
9190
SparseArray([0, 1, 10]),

pandas/tests/extension/base/methods.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_value_counts_default_dropna(self, data):
2727
def test_value_counts(self, all_data, dropna):
2828
all_data = all_data[:10]
2929
if dropna:
30-
other = np.array(all_data[~all_data.isna()])
30+
other = all_data[~all_data.isna()]
3131
else:
3232
other = all_data
3333

@@ -50,6 +50,10 @@ def test_value_counts_with_normalize(self, data):
5050
expected = pd.Series(0.0, index=result.index)
5151
expected[result > 0] = 1 / len(values)
5252

53+
if isinstance(data.dtype, pd.core.dtypes.dtypes.BaseMaskedDtype):
54+
# TODO(GH#44692): avoid special-casing
55+
expected = expected.astype("Float64")
56+
5357
self.assert_series_equal(result, expected)
5458

5559
def test_count(self, data_missing):

pandas/tests/extension/test_boolean.py

-8
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,6 @@ def test_searchsorted(self, data_for_sorting, as_series):
226226
sorter = np.array([1, 0])
227227
assert data_for_sorting.searchsorted(a, sorter=sorter) == 0
228228

229-
@pytest.mark.xfail(reason="uses nullable integer")
230-
def test_value_counts(self, all_data, dropna):
231-
return super().test_value_counts(all_data, dropna)
232-
233-
@pytest.mark.xfail(reason="uses nullable integer")
234-
def test_value_counts_with_normalize(self, data):
235-
super().test_value_counts_with_normalize(data)
236-
237229
def test_argmin_argmax(self, data_for_sorting, data_missing_for_sorting):
238230
# override because there are only 2 unique values
239231

pandas/tests/extension/test_floating.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -173,24 +173,7 @@ class TestMissing(base.BaseMissingTests):
173173

174174

175175
class TestMethods(base.BaseMethodsTests):
176-
@pytest.mark.parametrize("dropna", [True, False])
177-
def test_value_counts(self, all_data, dropna):
178-
all_data = all_data[:10]
179-
if dropna:
180-
other = np.array(all_data[~all_data.isna()])
181-
else:
182-
other = all_data
183-
184-
result = pd.Series(all_data).value_counts(dropna=dropna).sort_index()
185-
expected = pd.Series(other).value_counts(dropna=dropna).sort_index()
186-
expected = expected.astype("Int64")
187-
expected.index = expected.index.astype(all_data.dtype)
188-
189-
self.assert_series_equal(result, expected)
190-
191-
@pytest.mark.xfail(reason="uses nullable integer")
192-
def test_value_counts_with_normalize(self, data):
193-
super().test_value_counts_with_normalize(data)
176+
pass
194177

195178

196179
class TestCasting(base.BaseCastingTests):

pandas/tests/extension/test_integer.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,7 @@ class TestMissing(base.BaseMissingTests):
196196

197197

198198
class TestMethods(base.BaseMethodsTests):
199-
@pytest.mark.parametrize("dropna", [True, False])
200-
def test_value_counts(self, all_data, dropna):
201-
all_data = all_data[:10]
202-
if dropna:
203-
other = np.array(all_data[~all_data.isna()])
204-
else:
205-
other = all_data
206-
207-
result = pd.Series(all_data).value_counts(dropna=dropna).sort_index()
208-
expected = pd.Series(other).value_counts(dropna=dropna).sort_index()
209-
expected = expected.astype("Int64")
210-
expected.index = expected.index.astype(all_data.dtype)
211-
212-
self.assert_series_equal(result, expected)
213-
214-
@pytest.mark.xfail(reason="uses nullable integer")
215-
def test_value_counts_with_normalize(self, data):
216-
super().test_value_counts_with_normalize(data)
199+
pass
217200

218201

219202
class TestCasting(base.BaseCastingTests):

pandas/tests/groupby/transform/test_transform.py

+1
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ def test_null_group_str_reducer_series(request, dropna, reduction_func):
14631463
tm.assert_series_equal(result, expected)
14641464

14651465

1466+
@pytest.mark.filterwarnings("ignore:tshift is deprecated:FutureWarning")
14661467
def test_null_group_str_transformer_series(request, dropna, transformation_func):
14671468
# GH 17093
14681469
if transformation_func == "tshift":

pandas/tests/indexes/test_any_index.py

-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ def test_mutability(index):
4848

4949
def test_map_identity_mapping(index, request):
5050
# GH#12766
51-
if index.dtype == np.complex64:
52-
mark = pytest.mark.xfail(
53-
reason="maybe_downcast_to_dtype doesn't handle complex"
54-
)
55-
request.node.add_marker(mark)
5651

5752
result = index.map(lambda x: x)
5853
if index.dtype == object and result.dtype == bool:

pandas/tests/indexes/test_base.py

-5
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,6 @@ def test_map_dictlike(self, index, mapper, request):
540540
elif not index.is_unique:
541541
# Cannot map duplicated index
542542
return
543-
if index.dtype == np.complex64 and not isinstance(mapper(index, index), Series):
544-
mark = pytest.mark.xfail(
545-
reason="maybe_downcast_to_dtype doesn't handle complex"
546-
)
547-
request.node.add_marker(mark)
548543

549544
rng = np.arange(len(index), 0, -1)
550545

pandas/tests/series/test_ufunc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def test_multiply(self, values_for_np_reduce, box_with_array, request):
284284
obj = box(values)
285285

286286
if isinstance(values, pd.core.arrays.SparseArray) and box is not pd.Index:
287-
mark = pytest.mark.xfail(reason="SparseArray has no 'mul'")
287+
mark = pytest.mark.xfail(reason="SparseArray has no 'prod'")
288288
request.node.add_marker(mark)
289289

290290
if values.dtype.kind in "iuf":

0 commit comments

Comments
 (0)