Skip to content

Commit 6a84598

Browse files
move _get_cython_table_params into pandas/_testing.py (#32981)
1 parent 4b64f98 commit 6a84598

File tree

4 files changed

+44
-46
lines changed

4 files changed

+44
-46
lines changed

pandas/_testing.py

+31
Original file line numberDiff line numberDiff line change
@@ -2662,3 +2662,34 @@ def external_error_raised(
26622662
import pytest
26632663

26642664
return pytest.raises(expected_exception, match=None)
2665+
2666+
2667+
cython_table = pd.core.base.SelectionMixin._cython_table.items()
2668+
2669+
2670+
def get_cython_table_params(ndframe, func_names_and_expected):
2671+
"""
2672+
Combine frame, functions from SelectionMixin._cython_table
2673+
keys and expected result.
2674+
2675+
Parameters
2676+
----------
2677+
ndframe : DataFrame or Series
2678+
func_names_and_expected : Sequence of two items
2679+
The first item is a name of a NDFrame method ('sum', 'prod') etc.
2680+
The second item is the expected return value.
2681+
2682+
Returns
2683+
-------
2684+
list
2685+
List of three items (DataFrame, function, expected result)
2686+
"""
2687+
results = []
2688+
for func_name, expected in func_names_and_expected:
2689+
results.append((ndframe, func_name, expected))
2690+
results += [
2691+
(ndframe, func, expected)
2692+
for func, name in cython_table
2693+
if name == func_name
2694+
]
2695+
return results

pandas/conftest.py

+1-32
Original file line numberDiff line numberDiff line change
@@ -1119,10 +1119,7 @@ def spmatrix(request):
11191119
return getattr(sparse, request.param + "_matrix")
11201120

11211121

1122-
_cython_table = pd.core.base.SelectionMixin._cython_table.items()
1123-
1124-
1125-
@pytest.fixture(params=list(_cython_table))
1122+
@pytest.fixture(params=list(tm.cython_table))
11261123
def cython_table_items(request):
11271124
"""
11281125
Yields a tuple of a function and its corresponding name. Correspond to
@@ -1131,34 +1128,6 @@ def cython_table_items(request):
11311128
return request.param
11321129

11331130

1134-
def _get_cython_table_params(ndframe, func_names_and_expected):
1135-
"""
1136-
Combine frame, functions from SelectionMixin._cython_table
1137-
keys and expected result.
1138-
1139-
Parameters
1140-
----------
1141-
ndframe : DataFrame or Series
1142-
func_names_and_expected : Sequence of two items
1143-
The first item is a name of a NDFrame method ('sum', 'prod') etc.
1144-
The second item is the expected return value.
1145-
1146-
Returns
1147-
-------
1148-
list
1149-
List of three items (DataFrame, function, expected result)
1150-
"""
1151-
results = []
1152-
for func_name, expected in func_names_and_expected:
1153-
results.append((ndframe, func_name, expected))
1154-
results += [
1155-
(ndframe, func, expected)
1156-
for func, name in _cython_table
1157-
if name == func_name
1158-
]
1159-
return results
1160-
1161-
11621131
@pytest.fixture(
11631132
params=[
11641133
getattr(pd.offsets, o)

pandas/tests/frame/test_apply.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import pandas as pd
1313
from pandas import DataFrame, MultiIndex, Series, Timestamp, date_range, notna
1414
import pandas._testing as tm
15-
from pandas.conftest import _get_cython_table_params
1615
from pandas.core.apply import frame_apply
1716
from pandas.core.base import SpecificationError
1817

@@ -1323,7 +1322,7 @@ def func(group_col):
13231322
@pytest.mark.parametrize(
13241323
"df, func, expected",
13251324
chain(
1326-
_get_cython_table_params(
1325+
tm.get_cython_table_params(
13271326
DataFrame(),
13281327
[
13291328
("sum", Series(dtype="float64")),
@@ -1338,7 +1337,7 @@ def func(group_col):
13381337
("median", Series(dtype="float64")),
13391338
],
13401339
),
1341-
_get_cython_table_params(
1340+
tm.get_cython_table_params(
13421341
DataFrame([[np.nan, 1], [1, 2]]),
13431342
[
13441343
("sum", Series([1.0, 3])),
@@ -1365,10 +1364,10 @@ def test_agg_cython_table(self, df, func, expected, axis):
13651364
@pytest.mark.parametrize(
13661365
"df, func, expected",
13671366
chain(
1368-
_get_cython_table_params(
1367+
tm.get_cython_table_params(
13691368
DataFrame(), [("cumprod", DataFrame()), ("cumsum", DataFrame())]
13701369
),
1371-
_get_cython_table_params(
1370+
tm.get_cython_table_params(
13721371
DataFrame([[np.nan, 1], [1, 2]]),
13731372
[
13741373
("cumprod", DataFrame([[np.nan, 1], [1, 2]])),
@@ -1390,7 +1389,7 @@ def test_agg_cython_table_transform(self, df, func, expected, axis):
13901389

13911390
@pytest.mark.parametrize(
13921391
"df, func, expected",
1393-
_get_cython_table_params(
1392+
tm.get_cython_table_params(
13941393
DataFrame([["a", "b"], ["b", "a"]]), [["cumprod", TypeError]]
13951394
),
13961395
)

pandas/tests/series/test_apply.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import pandas as pd
1010
from pandas import DataFrame, Index, Series, isna
1111
import pandas._testing as tm
12-
from pandas.conftest import _get_cython_table_params
1312
from pandas.core.base import SpecificationError
1413

1514

@@ -356,7 +355,7 @@ def test_non_callable_aggregates(self):
356355
@pytest.mark.parametrize(
357356
"series, func, expected",
358357
chain(
359-
_get_cython_table_params(
358+
tm.get_cython_table_params(
360359
Series(dtype=np.float64),
361360
[
362361
("sum", 0),
@@ -371,7 +370,7 @@ def test_non_callable_aggregates(self):
371370
("median", np.nan),
372371
],
373372
),
374-
_get_cython_table_params(
373+
tm.get_cython_table_params(
375374
Series([np.nan, 1, 2, 3]),
376375
[
377376
("sum", 6),
@@ -386,7 +385,7 @@ def test_non_callable_aggregates(self):
386385
("median", 2),
387386
],
388387
),
389-
_get_cython_table_params(
388+
tm.get_cython_table_params(
390389
Series("a b c".split()),
391390
[
392391
("sum", "abc"),
@@ -411,21 +410,21 @@ def test_agg_cython_table(self, series, func, expected):
411410
@pytest.mark.parametrize(
412411
"series, func, expected",
413412
chain(
414-
_get_cython_table_params(
413+
tm.get_cython_table_params(
415414
Series(dtype=np.float64),
416415
[
417416
("cumprod", Series([], Index([]), dtype=np.float64)),
418417
("cumsum", Series([], Index([]), dtype=np.float64)),
419418
],
420419
),
421-
_get_cython_table_params(
420+
tm.get_cython_table_params(
422421
Series([np.nan, 1, 2, 3]),
423422
[
424423
("cumprod", Series([np.nan, 1, 2, 6])),
425424
("cumsum", Series([np.nan, 1, 3, 6])),
426425
],
427426
),
428-
_get_cython_table_params(
427+
tm.get_cython_table_params(
429428
Series("a b c".split()), [("cumsum", Series(["a", "ab", "abc"]))]
430429
),
431430
),
@@ -440,7 +439,7 @@ def test_agg_cython_table_transform(self, series, func, expected):
440439
@pytest.mark.parametrize(
441440
"series, func, expected",
442441
chain(
443-
_get_cython_table_params(
442+
tm.get_cython_table_params(
444443
Series("a b c".split()),
445444
[
446445
("mean", TypeError), # mean raises TypeError

0 commit comments

Comments
 (0)