Skip to content

Commit 39ced29

Browse files
committed
clarified according to comments
1 parent 5ad024c commit 39ced29

File tree

4 files changed

+39
-61
lines changed

4 files changed

+39
-61
lines changed

pandas/conftest.py

+32-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,18 +123,41 @@ 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)
131133
def cython_table_items(request):
132134
return request.param
133135

134136

137+
def _get_cython_table_params(ndframe, func_names_and_expected):
138+
"""combine frame, functions from SelectionMixin._cython_table
139+
keys and expected result.
140+
141+
Parameters
142+
----------
143+
ndframe : DataFrame or Series
144+
func_names_and_expected : Sequence of two items
145+
The first item is a name of a NDFrame method ('sum', 'prod') etc.
146+
The second item is the expected return value
147+
148+
Returns
149+
-------
150+
results : list
151+
List of three items (DataFrame, function, expected result)
152+
"""
153+
results = []
154+
for func_name, expected in func_names_and_expected:
155+
results.append((ndframe, func_name, expected))
156+
results += [(ndframe, func, expected) for func, name in _cython_table
157+
if name == func_name]
158+
return results
159+
160+
135161
@pytest.fixture(params=['__eq__', '__ne__', '__le__',
136162
'__lt__', '__ge__', '__gt__'])
137163
def all_compare_operators(request):

pandas/core/frame.py

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

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

60916092
agg = aggregate
60926093

6094+
@Appender(_shared_docs['transform'] % _shared_doc_kwargs)
60936095
def transform(self, func, axis=0, *args, **kwargs):
60946096
axis = self._get_axis_number(axis)
60956097
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.conftest 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)
1617
import pandas.util.testing as tm
18+
from pandas.conftest import _get_cython_table_params
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):

0 commit comments

Comments
 (0)