Skip to content

Commit 9887344

Browse files
tptopper-123
tp
authored andcommitted
add conftest cython_table_items + a few corrections
1 parent 4be0fd9 commit 9887344

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

pandas/conftest.py

+15-3
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
9+
from pandas.compat import PY3, PY36
1010
import pandas.util._test_decorators as td
1111

1212

@@ -64,15 +64,15 @@ def spmatrix(request):
6464
ids=lambda x: "axis {!r}".format(x))
6565
def axis(request):
6666
"""
67-
Fixture for returning the axis numbers of a dataframe.
67+
Fixture for returning the axis numbers of a DataFrame.
6868
"""
6969
return request.param
7070

7171

7272
@pytest.fixture(params=[0, 'index'], ids=lambda x: "axis {!r}".format(x))
7373
def axis_series(request):
7474
"""
75-
Fixture for returning the axis numbers of a series.
75+
Fixture for returning the axis numbers of a Series.
7676
"""
7777
return request.param
7878

@@ -120,6 +120,18 @@ def all_arithmetic_operators(request):
120120
return request.param
121121

122122

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__)
128+
129+
130+
@pytest.fixture(params=_cython_table)
131+
def cython_table_items(request):
132+
return request.param
133+
134+
123135
@pytest.fixture(params=['__eq__', '__ne__', '__le__',
124136
'__lt__', '__ge__', '__gt__'])
125137
def all_compare_operators(request):

pandas/core/frame.py

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

60816081
def _aggregate(self, arg, axis=0, *args, **kwargs):
6082-
if axis in {1, 'columns'}:
6082+
axis = self._get_axis_number(axis)
6083+
if axis == 1:
60836084
result, how = (super(DataFrame, self.T)
60846085
._aggregate(arg, *args, **kwargs))
60856086
result = result.T if result is not None else result
@@ -6089,7 +6090,8 @@ def _aggregate(self, arg, axis=0, *args, **kwargs):
60896090
agg = aggregate
60906091

60916092
def transform(self, func, axis=0, *args, **kwargs):
6092-
if axis in {1, 'columns'}:
6093+
axis = self._get_axis_number(axis)
6094+
if axis == 1:
60936095
return super(DataFrame, self.T).transform(func, *args, **kwargs).T
60946096
return super(DataFrame, self).transform(func, *args, **kwargs)
60956097

pandas/tests/frame/test_apply.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,12 @@ def _get_cython_table_params(frame, func_names_and_expected):
4040
results : list
4141
List of three items (DataFrame, function, expected result)
4242
"""
43-
table = pd.core.base.SelectionMixin._cython_table
44-
if compat.PY36:
45-
table = list(table.items())
46-
else: # dicts have random order in Python<3.6, which xdist doesn't like
47-
table = sorted(((key, value) for key, value in table.items()),
48-
key=lambda x: x[0].__class__.__name__)
43+
from pandas.conftest import _cython_table
4944
results = []
5045
for func_name, expected in func_names_and_expected:
5146
results.append((frame, func_name, expected))
52-
results += [
53-
(frame, func, expected) for func, name in table
54-
if name == func_name]
47+
results += [(frame, func, expected) for func, name in _cython_table
48+
if name == func_name]
5549
return results
5650

5751

pandas/tests/series/test_apply.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,12 @@ def _get_cython_table_params(series, func_names_and_expected):
3535
results : list
3636
List of three items (Series, function, expected result)
3737
"""
38-
table = pd.core.base.SelectionMixin._cython_table
39-
if compat.PY36:
40-
table = list(table.items())
41-
else: # dicts have random order in Python<3.6, which xdist doesn't like
42-
table = sorted(((key, value) for key, value in table.items()),
43-
key=lambda x: x[0].__class__.__name__)
38+
from pandas.conftest import _cython_table
4439
results = []
4540
for func_name, expected in func_names_and_expected:
4641
results.append((series, func_name, expected))
4742
results += [
48-
(series, func, expected) for func, name in table
43+
(series, func, expected) for func, name in _cython_table
4944
if name == func_name]
5045
return results
5146

0 commit comments

Comments
 (0)