Skip to content

Commit 69a0a0d

Browse files
took care of review comments
1 parent 8f0fdf6 commit 69a0a0d

File tree

6 files changed

+31
-41
lines changed

6 files changed

+31
-41
lines changed

pandas/_testing.py

+26
Original file line numberDiff line numberDiff line change
@@ -2757,3 +2757,29 @@ def convert_rows_list_to_csv_str(rows_list: List[str]):
27572757
sep = os.linesep
27582758
expected = sep.join(rows_list) + sep
27592759
return expected
2760+
2761+
2762+
def allow_na_ops(obj: Any) -> bool:
2763+
"""Whether to skip test cases including NaN"""
2764+
is_bool_index = isinstance(obj, Index) and obj.is_boolean()
2765+
return not is_bool_index and obj._can_hold_na
2766+
2767+
2768+
def check_ops_properties_valid(obj: Any, op: str) -> None:
2769+
""" Validates that certain properties are available """
2770+
if isinstance(obj, Series):
2771+
expected = Series(getattr(obj.index, op), index=obj.index, name="a")
2772+
else:
2773+
expected = getattr(obj, op)
2774+
2775+
result = getattr(obj, op)
2776+
2777+
# these could be series, arrays or scalars
2778+
if isinstance(result, Series) and isinstance(expected, Series):
2779+
assert_series_equal(result, expected)
2780+
elif isinstance(result, Index) and isinstance(expected, Index):
2781+
assert_index_equal(result, expected)
2782+
elif isinstance(result, np.ndarray) and isinstance(expected, np.ndarray):
2783+
assert_numpy_array_equal(result, expected)
2784+
else:
2785+
assert result == expected

pandas/tests/base/test_ops.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
Timestamp,
3131
)
3232
import pandas._testing as tm
33-
from pandas.tests.base.utils import allow_na_ops
3433

3534

3635
class Ops:
@@ -261,7 +260,7 @@ def test_value_counts_unique_nunique_null(self, null_obj):
261260
klass = type(o)
262261
values = o._ndarray_values
263262

264-
if not allow_na_ops(o):
263+
if not tm.allow_na_ops(o):
265264
continue
266265

267266
# special assign to the numpy array
@@ -742,7 +741,7 @@ def test_fillna(self):
742741
o = orig.copy()
743742
klass = type(o)
744743

745-
if not allow_na_ops(o):
744+
if not tm.allow_na_ops(o):
746745
continue
747746

748747
if needs_i8_conversion(o):

pandas/tests/base/utils.py

-32
This file was deleted.

pandas/tests/indexes/datetimes/test_ops.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
date_range,
1919
)
2020
import pandas._testing as tm
21-
from pandas.tests.base.utils import check_ops_properties_valid
2221

2322
from pandas.tseries.offsets import BDay, BMonthEnd, CDay, Day, Hour
2423

@@ -30,7 +29,7 @@ class TestDatetimeIndexOps:
3029
def test_valid_ops_properties(self, op, index_or_series_obj):
3130
obj = index_or_series_obj
3231
if isinstance(obj, DatetimeIndex):
33-
check_ops_properties_valid(obj, op)
32+
tm.check_ops_properties_valid(obj, op)
3433

3534
@pytest.mark.parametrize("op", DatetimeIndex._datetimelike_ops)
3635
def test_invalid_ops_properties(self, op, index_or_series_obj):

pandas/tests/indexes/period/test_ops.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
from pandas import DatetimeIndex, Index, NaT, PeriodIndex, Series, TimedeltaIndex
66
import pandas._testing as tm
77
from pandas.core.arrays import PeriodArray
8-
from pandas.tests.base.utils import check_ops_properties_valid
98

109

1110
class TestPeriodIndexOps:
1211
@pytest.mark.parametrize("op", PeriodArray._datetimelike_ops)
1312
def test_valid_ops_properties(self, op, index_or_series_obj):
1413
obj = index_or_series_obj
1514
if isinstance(obj, PeriodIndex):
16-
check_ops_properties_valid(obj, op)
15+
tm.check_ops_properties_valid(obj, op)
1716

1817
@pytest.mark.parametrize("op", PeriodArray._datetimelike_ops)
1918
def test_invalid_ops_properties(self, op, index_or_series_obj):

pandas/tests/indexes/timedeltas/test_ops.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pandas as pd
99
from pandas import DatetimeIndex, PeriodIndex, Series, TimedeltaIndex, timedelta_range
1010
import pandas._testing as tm
11-
from pandas.tests.base.utils import check_ops_properties_valid
1211

1312
from pandas.tseries.offsets import Day, Hour
1413

@@ -18,7 +17,7 @@ class TestTimedeltaIndexOps:
1817
def test_valid_ops_properties(self, op, index_or_series_obj):
1918
obj = index_or_series_obj
2019
if isinstance(obj, TimedeltaIndex):
21-
check_ops_properties_valid(obj, op)
20+
tm.check_ops_properties_valid(obj, op)
2221

2322
@pytest.mark.parametrize("op", TimedeltaIndex._datetimelike_ops)
2423
def test_invalid_ops_properties(self, op, index_or_series_obj):

0 commit comments

Comments
 (0)