Skip to content

Commit

Permalink
clarified according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 committed Jul 26, 2018
1 parent 5ad024c commit 39ced29
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 61 deletions.
38 changes: 32 additions & 6 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas
import numpy as np
import pandas as pd
from pandas.compat import PY3, PY36
from pandas.compat import PY3
import pandas.util._test_decorators as td


Expand Down Expand Up @@ -69,6 +69,9 @@ def axis(request):
return request.param


axis_frame = axis


@pytest.fixture(params=[0, 'index'], ids=lambda x: "axis {!r}".format(x))
def axis_series(request):
"""
Expand Down Expand Up @@ -120,18 +123,41 @@ def all_arithmetic_operators(request):
return request.param


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


@pytest.fixture(params=_cython_table)
def cython_table_items(request):
return request.param


def _get_cython_table_params(ndframe, func_names_and_expected):
"""combine frame, functions from SelectionMixin._cython_table
keys and expected result.
Parameters
----------
ndframe : DataFrame or Series
func_names_and_expected : Sequence of two items
The first item is a name of a NDFrame method ('sum', 'prod') etc.
The second item is the expected return value
Returns
-------
results : list
List of three items (DataFrame, function, expected result)
"""
results = []
for func_name, expected in func_names_and_expected:
results.append((ndframe, func_name, expected))
results += [(ndframe, func, expected) for func, name in _cython_table
if name == func_name]
return results


@pytest.fixture(params=['__eq__', '__ne__', '__le__',
'__lt__', '__ge__', '__gt__'])
def all_compare_operators(request):
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6080,8 +6080,9 @@ def aggregate(self, func, axis=0, *args, **kwargs):
return result

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

agg = aggregate

@Appender(_shared_docs['transform'] % _shared_doc_kwargs)
def transform(self, func, axis=0, *args, **kwargs):
axis = self._get_axis_number(axis)
if axis == 1:
Expand Down
27 changes: 1 addition & 26 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,10 @@
from pandas.util.testing import (assert_series_equal,
assert_frame_equal)
import pandas.util.testing as tm
from pandas.conftest import _get_cython_table_params
from pandas.tests.frame.common import TestData


def _get_cython_table_params(frame, func_names_and_expected):
"""combine frame, functions from SelectionMixin._cython_table
keys and expected result.
Parameters
----------
frame : DataFrame
A symmetrical DataFrame
func_names_and_expected : Sequence of two items
The first item is a name of a NDFrame method ('sum', 'prod') etc.
The second item is the expected return value
Returns
-------
results : list
List of three items (DataFrame, function, expected result)
"""
from pandas.conftest import _cython_table
results = []
for func_name, expected in func_names_and_expected:
results.append((frame, func_name, expected))
results += [(frame, func, expected) for func, name in _cython_table
if name == func_name]
return results


class TestDataFrameApply(TestData):

def test_apply(self):
Expand Down
31 changes: 3 additions & 28 deletions pandas/tests/series/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,14 @@
from pandas import (Index, Series, DataFrame, isna)
from pandas.compat import lrange
from pandas import compat
from pandas.util.testing import assert_series_equal, assert_frame_equal
from pandas.util.testing import (assert_series_equal,
assert_frame_equal)
import pandas.util.testing as tm
from pandas.conftest import _get_cython_table_params

from .common import TestData


def _get_cython_table_params(series, func_names_and_expected):
"""combine series, functions from SelectionMixin._cython_table
keys and expected result.
Parameters
----------
series : Series
A Series
func_names_and_expected : Sequence of two items
The first item is a name of a NDFrame method ('sum', 'prod') etc.
The second item is the expected return value
Returns
-------
results : list
List of three items (Series, function, expected result)
"""
from pandas.conftest import _cython_table
results = []
for func_name, expected in func_names_and_expected:
results.append((series, func_name, expected))
results += [
(series, func, expected) for func, name in _cython_table
if name == func_name]
return results


class TestSeriesApply(TestData):

def test_apply(self):
Expand Down

0 comments on commit 39ced29

Please sign in to comment.