Skip to content

Commit

Permalink
took care of review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
SaturnFromTitan committed Jan 23, 2020
1 parent 8f0fdf6 commit 69a0a0d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 41 deletions.
26 changes: 26 additions & 0 deletions pandas/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2757,3 +2757,29 @@ def convert_rows_list_to_csv_str(rows_list: List[str]):
sep = os.linesep
expected = sep.join(rows_list) + sep
return expected


def allow_na_ops(obj: Any) -> bool:
"""Whether to skip test cases including NaN"""
is_bool_index = isinstance(obj, Index) and obj.is_boolean()
return not is_bool_index and obj._can_hold_na


def check_ops_properties_valid(obj: Any, op: str) -> None:
""" Validates that certain properties are available """
if isinstance(obj, Series):
expected = Series(getattr(obj.index, op), index=obj.index, name="a")
else:
expected = getattr(obj, op)

result = getattr(obj, op)

# these could be series, arrays or scalars
if isinstance(result, Series) and isinstance(expected, Series):
assert_series_equal(result, expected)
elif isinstance(result, Index) and isinstance(expected, Index):
assert_index_equal(result, expected)
elif isinstance(result, np.ndarray) and isinstance(expected, np.ndarray):
assert_numpy_array_equal(result, expected)
else:
assert result == expected
5 changes: 2 additions & 3 deletions pandas/tests/base/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
Timestamp,
)
import pandas._testing as tm
from pandas.tests.base.utils import allow_na_ops


class Ops:
Expand Down Expand Up @@ -261,7 +260,7 @@ def test_value_counts_unique_nunique_null(self, null_obj):
klass = type(o)
values = o._ndarray_values

if not allow_na_ops(o):
if not tm.allow_na_ops(o):
continue

# special assign to the numpy array
Expand Down Expand Up @@ -742,7 +741,7 @@ def test_fillna(self):
o = orig.copy()
klass = type(o)

if not allow_na_ops(o):
if not tm.allow_na_ops(o):
continue

if needs_i8_conversion(o):
Expand Down
32 changes: 0 additions & 32 deletions pandas/tests/base/utils.py

This file was deleted.

3 changes: 1 addition & 2 deletions pandas/tests/indexes/datetimes/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
date_range,
)
import pandas._testing as tm
from pandas.tests.base.utils import check_ops_properties_valid

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

Expand All @@ -30,7 +29,7 @@ class TestDatetimeIndexOps:
def test_valid_ops_properties(self, op, index_or_series_obj):
obj = index_or_series_obj
if isinstance(obj, DatetimeIndex):
check_ops_properties_valid(obj, op)
tm.check_ops_properties_valid(obj, op)

@pytest.mark.parametrize("op", DatetimeIndex._datetimelike_ops)
def test_invalid_ops_properties(self, op, index_or_series_obj):
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexes/period/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
from pandas import DatetimeIndex, Index, NaT, PeriodIndex, Series, TimedeltaIndex
import pandas._testing as tm
from pandas.core.arrays import PeriodArray
from pandas.tests.base.utils import check_ops_properties_valid


class TestPeriodIndexOps:
@pytest.mark.parametrize("op", PeriodArray._datetimelike_ops)
def test_valid_ops_properties(self, op, index_or_series_obj):
obj = index_or_series_obj
if isinstance(obj, PeriodIndex):
check_ops_properties_valid(obj, op)
tm.check_ops_properties_valid(obj, op)

@pytest.mark.parametrize("op", PeriodArray._datetimelike_ops)
def test_invalid_ops_properties(self, op, index_or_series_obj):
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexes/timedeltas/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pandas as pd
from pandas import DatetimeIndex, PeriodIndex, Series, TimedeltaIndex, timedelta_range
import pandas._testing as tm
from pandas.tests.base.utils import check_ops_properties_valid

from pandas.tseries.offsets import Day, Hour

Expand All @@ -18,7 +17,7 @@ class TestTimedeltaIndexOps:
def test_valid_ops_properties(self, op, index_or_series_obj):
obj = index_or_series_obj
if isinstance(obj, TimedeltaIndex):
check_ops_properties_valid(obj, op)
tm.check_ops_properties_valid(obj, op)

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

0 comments on commit 69a0a0d

Please sign in to comment.