Skip to content

Commit 025a239

Browse files
authored
TST/CLN: Remove seldomly use items in _testing/__init__.py (#56344)
* Remove some sparse __init__ stuff * Remove empty pattern
1 parent b64d87b commit 025a239

File tree

5 files changed

+45
-52
lines changed

5 files changed

+45
-52
lines changed

pandas/_testing/__init__.py

-43
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from decimal import Decimal
44
import operator
55
import os
6-
import re
76
from sys import byteorder
87
from typing import (
98
TYPE_CHECKING,
@@ -27,7 +26,6 @@
2726
import pandas as pd
2827
from pandas import (
2928
ArrowDtype,
30-
Categorical,
3129
DataFrame,
3230
Index,
3331
MultiIndex,
@@ -243,9 +241,6 @@
243241
ALL_PYARROW_DTYPES = []
244242

245243

246-
EMPTY_STRING_PATTERN = re.compile("^$")
247-
248-
249244
arithmetic_dunder_methods = [
250245
"__add__",
251246
"__radd__",
@@ -353,42 +348,6 @@ def _constructor_sliced(self):
353348
return lambda *args, **kwargs: SubclassedSeries(*args, **kwargs)
354349

355350

356-
class SubclassedCategorical(Categorical):
357-
pass
358-
359-
360-
def _make_skipna_wrapper(alternative, skipna_alternative=None):
361-
"""
362-
Create a function for calling on an array.
363-
364-
Parameters
365-
----------
366-
alternative : function
367-
The function to be called on the array with no NaNs.
368-
Only used when 'skipna_alternative' is None.
369-
skipna_alternative : function
370-
The function to be called on the original array
371-
372-
Returns
373-
-------
374-
function
375-
"""
376-
if skipna_alternative:
377-
378-
def skipna_wrapper(x):
379-
return skipna_alternative(x.values)
380-
381-
else:
382-
383-
def skipna_wrapper(x):
384-
nona = x.dropna()
385-
if len(nona) == 0:
386-
return np.nan
387-
return alternative(nona)
388-
389-
return skipna_wrapper
390-
391-
392351
def convert_rows_list_to_csv_str(rows_list: list[str]) -> str:
393352
"""
394353
Convert list of CSV rows to single CSV-formatted string for current OS.
@@ -621,7 +580,6 @@ def shares_memory(left, right) -> bool:
621580
"convert_rows_list_to_csv_str",
622581
"DATETIME64_DTYPES",
623582
"decompress_file",
624-
"EMPTY_STRING_PATTERN",
625583
"ENDIAN",
626584
"ensure_clean",
627585
"external_error_raised",
@@ -654,7 +612,6 @@ def shares_memory(left, right) -> bool:
654612
"SIGNED_INT_EA_DTYPES",
655613
"SIGNED_INT_NUMPY_DTYPES",
656614
"STRING_DTYPES",
657-
"SubclassedCategorical",
658615
"SubclassedDataFrame",
659616
"SubclassedSeries",
660617
"TIMEDELTA64_DTYPES",

pandas/tests/arrays/categorical/test_subclass.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22
import pandas._testing as tm
33

44

5+
class SubclassedCategorical(Categorical):
6+
pass
7+
8+
59
class TestCategoricalSubclassing:
610
def test_constructor(self):
7-
sc = tm.SubclassedCategorical(["a", "b", "c"])
8-
assert isinstance(sc, tm.SubclassedCategorical)
11+
sc = SubclassedCategorical(["a", "b", "c"])
12+
assert isinstance(sc, SubclassedCategorical)
913
tm.assert_categorical_equal(sc, Categorical(["a", "b", "c"]))
1014

1115
def test_from_codes(self):
12-
sc = tm.SubclassedCategorical.from_codes([1, 0, 2], ["a", "b", "c"])
13-
assert isinstance(sc, tm.SubclassedCategorical)
16+
sc = SubclassedCategorical.from_codes([1, 0, 2], ["a", "b", "c"])
17+
assert isinstance(sc, SubclassedCategorical)
1418
exp = Categorical.from_codes([1, 0, 2], ["a", "b", "c"])
1519
tm.assert_categorical_equal(sc, exp)
1620

1721
def test_map(self):
18-
sc = tm.SubclassedCategorical(["a", "b", "c"])
22+
sc = SubclassedCategorical(["a", "b", "c"])
1923
res = sc.map(lambda x: x.upper(), na_action=None)
20-
assert isinstance(res, tm.SubclassedCategorical)
24+
assert isinstance(res, SubclassedCategorical)
2125
exp = Categorical(["A", "B", "C"])
2226
tm.assert_categorical_equal(res, exp)

pandas/tests/frame/test_reductions.py

+33-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,38 @@
4040
is_windows_or_is32 = is_platform_windows() or not IS64
4141

4242

43+
def make_skipna_wrapper(alternative, skipna_alternative=None):
44+
"""
45+
Create a function for calling on an array.
46+
47+
Parameters
48+
----------
49+
alternative : function
50+
The function to be called on the array with no NaNs.
51+
Only used when 'skipna_alternative' is None.
52+
skipna_alternative : function
53+
The function to be called on the original array
54+
55+
Returns
56+
-------
57+
function
58+
"""
59+
if skipna_alternative:
60+
61+
def skipna_wrapper(x):
62+
return skipna_alternative(x.values)
63+
64+
else:
65+
66+
def skipna_wrapper(x):
67+
nona = x.dropna()
68+
if len(nona) == 0:
69+
return np.nan
70+
return alternative(nona)
71+
72+
return skipna_wrapper
73+
74+
4375
def assert_stat_op_calc(
4476
opname,
4577
alternative,
@@ -96,7 +128,7 @@ def assert_stat_op_calc(
96128
def wrapper(x):
97129
return alternative(x.values)
98130

99-
skipna_wrapper = tm._make_skipna_wrapper(alternative, skipna_alternative)
131+
skipna_wrapper = make_skipna_wrapper(alternative, skipna_alternative)
100132
result0 = f(axis=0, skipna=False)
101133
result1 = f(axis=1, skipna=False)
102134
tm.assert_series_equal(

pandas/tests/io/json/test_normalize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_empty_array(self):
200200
)
201201
def test_accepted_input(self, data, record_path, exception_type):
202202
if exception_type is not None:
203-
with pytest.raises(exception_type, match=tm.EMPTY_STRING_PATTERN):
203+
with pytest.raises(exception_type, match=""):
204204
json_normalize(data, record_path=record_path)
205205
else:
206206
result = json_normalize(data, record_path=record_path)

pandas/tests/series/test_ufunc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def test_outer():
413413
ser = pd.Series([1, 2, 3])
414414
obj = np.array([1, 2, 3])
415415

416-
with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN):
416+
with pytest.raises(NotImplementedError, match=""):
417417
np.subtract.outer(ser, obj)
418418

419419

0 commit comments

Comments
 (0)