Skip to content

Commit

Permalink
TST: follow-up to Test nested pandas array pandas-dev#24993 (pandas-d…
Browse files Browse the repository at this point in the history
…ev#25155)

* revert changes to tests in pandas-devgh-24993

* Test nested PandasArray

* isort test_numpy.py

* change NP_VERSION_INFO

* use LooseVersion

* add _np_version_under1p16

* remove blank line from merge master

* add doctstrings to fixtures
  • Loading branch information
simonjayhawkins authored and Pingviinituutti committed Feb 28, 2019
1 parent 9896bb1 commit 154e98b
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 531 deletions.
17 changes: 6 additions & 11 deletions pandas/tests/extension/base/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,14 @@ def test_groupby_extension_transform(self, data_for_grouping):

self.assert_series_equal(result, expected)

@pytest.mark.parametrize('op', [
lambda x: 1,
lambda x: [1] * len(x),
lambda x: pd.Series([1] * len(x)),
lambda x: x,
], ids=['scalar', 'list', 'series', 'object'])
def test_groupby_extension_apply(self, data_for_grouping, op):
def test_groupby_extension_apply(
self, data_for_grouping, groupby_apply_op):
df = pd.DataFrame({"A": [1, 1, 2, 2, 3, 3, 1, 4],
"B": data_for_grouping})
df.groupby("B").apply(op)
df.groupby("B").A.apply(op)
df.groupby("A").apply(op)
df.groupby("A").B.apply(op)
df.groupby("B").apply(groupby_apply_op)
df.groupby("B").A.apply(groupby_apply_op)
df.groupby("A").apply(groupby_apply_op)
df.groupby("A").B.apply(groupby_apply_op)

def test_in_numeric_groupby(self, data_for_grouping):
df = pd.DataFrame({"A": [1, 1, 2, 2, 3, 3, 1, 4],
Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/extension/base/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ def test_shift_fill_value(self, data):
expected = data.take([2, 3, 0, 0])
self.assert_extension_array_equal(result, expected)

@pytest.mark.parametrize("as_frame", [True, False])
def test_hash_pandas_object_works(self, data, as_frame):
# https://github.com/pandas-dev/pandas/issues/23066
data = pd.Series(data)
Expand All @@ -250,7 +249,6 @@ def test_hash_pandas_object_works(self, data, as_frame):
b = pd.util.hash_pandas_object(data)
self.assert_equal(a, b)

@pytest.mark.parametrize("as_series", [True, False])
def test_searchsorted(self, data_for_sorting, as_series):
b, c, a = data_for_sorting
arr = type(data_for_sorting)._from_sequence([a, b, c])
Expand All @@ -275,7 +273,6 @@ def test_searchsorted(self, data_for_sorting, as_series):
sorter = np.array([1, 2, 0])
assert data_for_sorting.searchsorted(a, sorter=sorter) == 0

@pytest.mark.parametrize("as_frame", [True, False])
def test_where_series(self, data, na_value, as_frame):
assert data[0] != data[1]
cls = type(data)
Expand Down Expand Up @@ -309,8 +306,6 @@ def test_where_series(self, data, na_value, as_frame):
expected = expected.to_frame(name='a')
self.assert_equal(result, expected)

@pytest.mark.parametrize("use_numpy", [True, False])
@pytest.mark.parametrize("as_series", [True, False])
@pytest.mark.parametrize("repeats", [0, 1, 2, [1, 2, 3]])
def test_repeat(self, data, repeats, as_series, use_numpy):
arr = type(data)._from_sequence(data[:3], dtype=data.dtype)
Expand All @@ -327,7 +322,6 @@ def test_repeat(self, data, repeats, as_series, use_numpy):

self.assert_equal(result, expected)

@pytest.mark.parametrize("use_numpy", [True, False])
@pytest.mark.parametrize('repeats, kwargs, error, msg', [
(2, dict(axis=1), ValueError, "'axis"),
(-1, dict(), ValueError, "negative"),
Expand Down
8 changes: 3 additions & 5 deletions pandas/tests/extension/base/missing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import pytest

import pandas as pd
import pandas.util.testing as tm
Expand Down Expand Up @@ -89,14 +88,13 @@ def test_fillna_series(self, data_missing):
result = ser.fillna(ser)
self.assert_series_equal(result, ser)

@pytest.mark.parametrize('method', ['ffill', 'bfill'])
def test_fillna_series_method(self, data_missing, method):
def test_fillna_series_method(self, data_missing, fillna_method):
fill_value = data_missing[1]

if method == 'ffill':
if fillna_method == 'ffill':
data_missing = data_missing[::-1]

result = pd.Series(data_missing).fillna(method=method)
result = pd.Series(data_missing).fillna(method=fillna_method)
expected = pd.Series(data_missing._from_sequence(
[fill_value, fill_value], dtype=data_missing.dtype))

Expand Down
1 change: 0 additions & 1 deletion pandas/tests/extension/base/setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def test_setitem_sequence(self, data, box_in_series):
assert data[0] == original[1]
assert data[1] == original[0]

@pytest.mark.parametrize('as_array', [True, False])
def test_setitem_sequence_mismatched_length_raises(self, data, as_array):
ser = pd.Series(data)
original = ser.copy()
Expand Down
57 changes: 57 additions & 0 deletions pandas/tests/extension/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pytest

from pandas import Series


@pytest.fixture
def dtype():
Expand Down Expand Up @@ -108,3 +110,58 @@ def data_for_grouping():
def box_in_series(request):
"""Whether to box the data in a Series"""
return request.param


@pytest.fixture(params=[
lambda x: 1,
lambda x: [1] * len(x),
lambda x: Series([1] * len(x)),
lambda x: x,
], ids=['scalar', 'list', 'series', 'object'])
def groupby_apply_op(request):
"""
Functions to test groupby.apply().
"""
return request.param


@pytest.fixture(params=[True, False])
def as_frame(request):
"""
Boolean fixture to support Series and Series.to_frame() comparison testing.
"""
return request.param


@pytest.fixture(params=[True, False])
def as_series(request):
"""
Boolean fixture to support arr and Series(arr) comparison testing.
"""
return request.param


@pytest.fixture(params=[True, False])
def use_numpy(request):
"""
Boolean fixture to support comparison testing of ExtensionDtype array
and numpy array.
"""
return request.param


@pytest.fixture(params=['ffill', 'bfill'])
def fillna_method(request):
"""
Parametrized fixture giving method parameters 'ffill' and 'bfill' for
Series.fillna(method=<method>) testing.
"""
return request.param


@pytest.fixture(params=[True, False])
def as_array(request):
"""
Boolean fixture to support ExtensionDtype _from_sequence method testing.
"""
return request.param
Empty file.
38 changes: 0 additions & 38 deletions pandas/tests/extension/numpy_/conftest.py

This file was deleted.

182 changes: 0 additions & 182 deletions pandas/tests/extension/numpy_/test_numpy.py

This file was deleted.

Loading

0 comments on commit 154e98b

Please sign in to comment.