Skip to content

Commit 73595b3

Browse files
committed
split tests
1 parent b4a12a5 commit 73595b3

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

pandas/tests/series/test_analytics.py

+32-23
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
from pandas import (Series, Categorical, DataFrame, isna, notna,
1414
bdate_range, date_range, _np_version_under1p10,
1515
CategoricalIndex)
16-
from pandas.core.dtypes.common import (
17-
is_float_dtype, is_integer_dtype, is_datetimelike)
1816
from pandas.core.index import MultiIndex
1917
from pandas.core.indexes.datetimes import Timestamp
2018
from pandas.core.indexes.timedeltas import Timedelta
@@ -1948,6 +1946,10 @@ def test_mode_sortwarning(self):
19481946

19491947
class TestNLargestNSmallest(object):
19501948

1949+
@pytest.fixture(params=['nlargest', 'nsmallest'])
1950+
def method(self, request):
1951+
return request.param
1952+
19511953
@pytest.mark.parametrize(
19521954
"r", [Series([3., 2, 1, 2, '5'], dtype='object'),
19531955
Series([3., 2, 1, 2, 5], dtype='object'),
@@ -2030,33 +2032,40 @@ def test_n(self, n):
20302032
expected = s.sort_values().head(n)
20312033
assert_series_equal(result, expected)
20322034

2033-
@pytest.mark.parametrize('dtype', [
2034-
'int8', 'int16', 'int32', 'int64',
2035-
'uint8', 'uint16', 'uint32', 'uint64',
2036-
'float16', 'float32', 'float64',
2037-
'datetime64[ns]', 'timedelta64[ns]'])
2038-
@pytest.mark.parametrize('method', ['nsmallest', 'nlargest'])
2039-
def test_boundary(self, method, dtype):
2040-
# GH 21426
2041-
if is_float_dtype(dtype):
2042-
min_val, max_val = np.finfo(dtype).min, np.finfo(dtype).max
2043-
min_2nd, max_2nd = np.nextafter([min_val, max_val], 0, dtype=dtype)
2044-
vals = [min_val, min_2nd, max_2nd, max_val]
2045-
elif is_integer_dtype(dtype):
2046-
min_val, max_val = np.iinfo(dtype).min, np.iinfo(dtype).max
2047-
vals = [min_val, min_val + 1, max_val - 1, max_val]
2048-
elif is_datetimelike(dtype):
2049-
# use int64 bounds and +1 to min_val since true minimum is NaT
2050-
# (include min_val/NaT at end to maintain same expected_idxr)
2051-
min_val, max_val = np.iinfo('int64').min, np.iinfo('int64').max
2052-
vals = [min_val + 1, min_val + 2, max_val - 1, max_val, min_val]
2053-
2035+
def _check_nselect_boundary(self, vals, dtype, method):
2036+
# helper function for 'test_boundary_dtype' tests
20542037
s = Series(vals, dtype=dtype)
20552038
result = getattr(s, method)(3)
20562039
expected_idxr = [0, 1, 2] if method == 'nsmallest' else [3, 2, 1]
20572040
expected = s.loc[expected_idxr]
20582041
tm.assert_series_equal(result, expected)
20592042

2043+
@pytest.mark.parametrize('dtype', [
2044+
'int8', 'int16', 'int32', 'int64',
2045+
'uint8', 'uint16', 'uint32', 'uint64'])
2046+
def test_boundary_integer(self, method, dtype):
2047+
# GH 21426
2048+
min_val, max_val = np.iinfo(dtype).min, np.iinfo(dtype).max
2049+
vals = [min_val, min_val + 1, max_val - 1, max_val]
2050+
self._check_nselect_boundary(vals, dtype, method)
2051+
2052+
@pytest.mark.parametrize('dtype', ['float16', 'float32', 'float64'])
2053+
def test_boundary_float(self, method, dtype):
2054+
# GH 21426
2055+
min_val, max_val = np.finfo(dtype).min, np.finfo(dtype).max
2056+
min_2nd, max_2nd = np.nextafter([min_val, max_val], 0, dtype=dtype)
2057+
vals = [min_val, min_2nd, max_2nd, max_val]
2058+
self._check_nselect_boundary(vals, dtype, method)
2059+
2060+
@pytest.mark.parametrize('dtype', ['datetime64[ns]', 'timedelta64[ns]'])
2061+
def test_boundary_datetimelike(self, method, dtype):
2062+
# GH 21426
2063+
# use int64 bounds and +1 to min_val since true minimum is NaT
2064+
# (include min_val/NaT at end to maintain same expected_idxr)
2065+
min_val, max_val = np.iinfo('int64').min, np.iinfo('int64').max
2066+
vals = [min_val + 1, min_val + 2, max_val - 1, max_val, min_val]
2067+
self._check_nselect_boundary(vals, dtype, method)
2068+
20602069

20612070
class TestCategoricalSeriesAnalytics(object):
20622071

0 commit comments

Comments
 (0)