Skip to content

Commit 06f1df7

Browse files
committed
clarified according to comments
1 parent 9887344 commit 06f1df7

File tree

5 files changed

+40
-61
lines changed

5 files changed

+40
-61
lines changed

pandas/conftest.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pandas
77
import numpy as np
88
import pandas as pd
9-
from pandas.compat import PY3, PY36
9+
from pandas.compat import PY3
1010
import pandas.util._test_decorators as td
1111

1212

@@ -69,6 +69,9 @@ def axis(request):
6969
return request.param
7070

7171

72+
axis_frame = axis
73+
74+
7275
@pytest.fixture(params=[0, 'index'], ids=lambda x: "axis {!r}".format(x))
7376
def axis_series(request):
7477
"""
@@ -120,11 +123,10 @@ def all_arithmetic_operators(request):
120123
return request.param
121124

122125

123-
_cython_table = list(pd.core.base.SelectionMixin._cython_table.items())
124-
if not PY36:
125-
# dicts have random order in Python<3.6, which xdist doesn't like
126-
_cython_table = sorted(((key, value) for key, value in _cython_table),
127-
key=lambda x: x[0].__class__.__name__)
126+
# use sorted as dicts in py<3.6 have random order, which xdist doesn't like
127+
_cython_table = sorted(((key, value) for key, value in
128+
pd.core.base.SelectionMixin._cython_table.items()),
129+
key=lambda x: x[0].__class__.__name__)
128130

129131

130132
@pytest.fixture(params=_cython_table)

pandas/core/frame.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6079,8 +6079,9 @@ def aggregate(self, func, axis=0, *args, **kwargs):
60796079
return result
60806080

60816081
def _aggregate(self, arg, axis=0, *args, **kwargs):
6082-
axis = self._get_axis_number(axis)
60836082
if axis == 1:
6083+
# NDFrame.aggregate returns a tuple, and we need to transpose
6084+
# only result
60846085
result, how = (super(DataFrame, self.T)
60856086
._aggregate(arg, *args, **kwargs))
60866087
result = result.T if result is not None else result
@@ -6089,6 +6090,7 @@ def _aggregate(self, arg, axis=0, *args, **kwargs):
60896090

60906091
agg = aggregate
60916092

6093+
@Appender(_shared_docs['transform'] % _shared_doc_kwargs)
60926094
def transform(self, func, axis=0, *args, **kwargs):
60936095
axis = self._get_axis_number(axis)
60946096
if axis == 1:

pandas/tests/frame/test_apply.py

+1-26
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,10 @@
2020
from pandas.util.testing import (assert_series_equal,
2121
assert_frame_equal)
2222
import pandas.util.testing as tm
23+
from pandas.util.testing import _get_cython_table_params
2324
from pandas.tests.frame.common import TestData
2425

2526

26-
def _get_cython_table_params(frame, func_names_and_expected):
27-
"""combine frame, functions from SelectionMixin._cython_table
28-
keys and expected result.
29-
30-
Parameters
31-
----------
32-
frame : DataFrame
33-
A symmetrical DataFrame
34-
func_names_and_expected : Sequence of two items
35-
The first item is a name of a NDFrame method ('sum', 'prod') etc.
36-
The second item is the expected return value
37-
38-
Returns
39-
-------
40-
results : list
41-
List of three items (DataFrame, function, expected result)
42-
"""
43-
from pandas.conftest import _cython_table
44-
results = []
45-
for func_name, expected in func_names_and_expected:
46-
results.append((frame, func_name, expected))
47-
results += [(frame, func, expected) for func, name in _cython_table
48-
if name == func_name]
49-
return results
50-
51-
5227
class TestDataFrameApply(TestData):
5328

5429
def test_apply(self):

pandas/tests/series/test_apply.py

+3-28
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,14 @@
1212
from pandas import (Index, Series, DataFrame, isna)
1313
from pandas.compat import lrange
1414
from pandas import compat
15-
from pandas.util.testing import assert_series_equal, assert_frame_equal
15+
from pandas.util.testing import (assert_series_equal,
16+
assert_frame_equal,
17+
_get_cython_table_params)
1618
import pandas.util.testing as tm
1719

1820
from .common import TestData
1921

2022

21-
def _get_cython_table_params(series, func_names_and_expected):
22-
"""combine series, functions from SelectionMixin._cython_table
23-
keys and expected result.
24-
25-
Parameters
26-
----------
27-
series : Series
28-
A Series
29-
func_names_and_expected : Sequence of two items
30-
The first item is a name of a NDFrame method ('sum', 'prod') etc.
31-
The second item is the expected return value
32-
33-
Returns
34-
-------
35-
results : list
36-
List of three items (Series, function, expected result)
37-
"""
38-
from pandas.conftest import _cython_table
39-
results = []
40-
for func_name, expected in func_names_and_expected:
41-
results.append((series, func_name, expected))
42-
results += [
43-
(series, func, expected) for func, name in _cython_table
44-
if name == func_name]
45-
return results
46-
47-
4823
class TestSeriesApply(TestData):
4924

5025
def test_apply(self):

pandas/util/testing.py

+25
Original file line numberDiff line numberDiff line change
@@ -2826,3 +2826,28 @@ def skipna_wrapper(x):
28262826
return alternative(nona)
28272827

28282828
return skipna_wrapper
2829+
2830+
2831+
def _get_cython_table_params(ndframe, func_names_and_expected):
2832+
"""combine frame, functions from SelectionMixin._cython_table
2833+
keys and expected result.
2834+
2835+
Parameters
2836+
----------
2837+
ndframe : DataFrame or Series
2838+
func_names_and_expected : Sequence of two items
2839+
The first item is a name of a NDFrame method ('sum', 'prod') etc.
2840+
The second item is the expected return value
2841+
2842+
Returns
2843+
-------
2844+
results : list
2845+
List of three items (DataFrame, function, expected result)
2846+
"""
2847+
from pandas.conftest import _cython_table
2848+
results = []
2849+
for func_name, expected in func_names_and_expected:
2850+
results.append((ndframe, func_name, expected))
2851+
results += [(ndframe, func, expected) for func, name in _cython_table
2852+
if name == func_name]
2853+
return results

0 commit comments

Comments
 (0)