Skip to content

TST: fix fixture for numpy dtypes #23983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 70 additions & 45 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,14 @@ def tz_aware_fixture(request):
COMPLEX_DTYPES = [complex, "complex64", "complex128"]
STRING_DTYPES = [str, 'str', 'U']

TIME_DTYPES = ['datetime64[ns]', 'M8[ns]', 'timedelta64[ns]', 'm8[ns]']
BOOL_DTYPES = [bool, 'bool']
BYTES_DTYPES = [bytes, 'bytes']
OBJECT_DTYPES = [object, 'object']

ALL_REAL_DTYPES = FLOAT_DTYPES + ALL_INT_DTYPES
ALL_NUMPY_DTYPES = ALL_REAL_DTYPES + COMPLEX_DTYPES + STRING_DTYPES
ALL_NUMPY_DTYPES = (ALL_REAL_DTYPES + COMPLEX_DTYPES + STRING_DTYPES
+ TIME_DTYPES + BOOL_DTYPES + BYTES_DTYPES + OBJECT_DTYPES)


@pytest.fixture(params=STRING_DTYPES)
Expand All @@ -406,8 +412,9 @@ def float_dtype(request):
"""
Parameterized fixture for float dtypes.

* float32
* float64
* float
* 'float32'
* 'float64'
"""

return request.param
Expand All @@ -418,8 +425,9 @@ def complex_dtype(request):
"""
Parameterized fixture for complex dtypes.

* complex64
* complex128
* complex
* 'complex64'
* 'complex128'
"""

return request.param
Expand All @@ -430,10 +438,11 @@ def sint_dtype(request):
"""
Parameterized fixture for signed integer dtypes.

* int8
* int16
* int32
* int64
* int
* 'int8'
* 'int16'
* 'int32'
* 'int64'
"""

return request.param
Expand All @@ -444,10 +453,10 @@ def uint_dtype(request):
"""
Parameterized fixture for unsigned integer dtypes.

* uint8
* uint16
* uint32
* uint64
* 'uint8'
* 'uint16'
* 'uint32'
* 'uint64'
"""

return request.param
Expand All @@ -456,16 +465,17 @@ def uint_dtype(request):
@pytest.fixture(params=ALL_INT_DTYPES)
def any_int_dtype(request):
"""
Parameterized fixture for any integer dtypes.
Parameterized fixture for any integer dtype.

* int8
* uint8
* int16
* uint16
* int32
* uint32
* int64
* uint64
* int
* 'int8'
* 'uint8'
* 'int16'
* 'uint16'
* 'int32'
* 'uint32'
* 'int64'
* 'uint64'
"""

return request.param
Expand All @@ -474,18 +484,20 @@ def any_int_dtype(request):
@pytest.fixture(params=ALL_REAL_DTYPES)
def any_real_dtype(request):
"""
Parameterized fixture for any (purely) real numeric dtypes.
Parameterized fixture for any (purely) real numeric dtype.

* int8
* uint8
* int16
* uint16
* int32
* uint32
* int64
* uint64
* float32
* float64
* int
* 'int8'
* 'uint8'
* 'int16'
* 'uint16'
* 'int32'
* 'uint32'
* 'int64'
* 'uint64'
* float
* 'float32'
* 'float64'
"""

return request.param
Expand All @@ -496,21 +508,34 @@ def any_numpy_dtype(request):
"""
Parameterized fixture for all numpy dtypes.

* int8
* uint8
* int16
* uint16
* int32
* uint32
* int64
* uint64
* float32
* float64
* complex64
* complex128
* bool
* 'bool'
* int
* 'int8'
* 'uint8'
* 'int16'
* 'uint16'
* 'int32'
* 'uint32'
* 'int64'
* 'uint64'
* float
* 'float32'
* 'float64'
* complex
* 'complex64'
* 'complex128'
* str
* 'str'
* 'U'
* bytes
* 'bytes'
* 'datetime64[ns]'
* 'M8[ns]'
* 'timedelta64[ns]'
* 'm8[ns]'
* object
* 'object'
"""

return request.param
Expand Down
27 changes: 11 additions & 16 deletions pandas/tests/series/test_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,17 @@ def __ne__(self, other):
('last', Series([False, True, True, False, False, False, False])),
(False, Series([False, True, True, False, True, True, False]))
])
def test_drop_duplicates_non_bool(any_numpy_dtype, keep, expected):
tc = Series([1, 2, 3, 5, 3, 2, 4], dtype=np.dtype(any_numpy_dtype))

tm.assert_series_equal(tc.duplicated(keep=keep), expected)
tm.assert_series_equal(tc.drop_duplicates(keep=keep), tc[~expected])
sc = tc.copy()
sc.drop_duplicates(keep=keep, inplace=True)
tm.assert_series_equal(sc, tc[~expected])


@pytest.mark.parametrize('keep, expected',
[('first', Series([False, False, True, True])),
('last', Series([True, True, False, False])),
(False, Series([True, True, True, True]))])
def test_drop_duplicates_bool(keep, expected):
tc = Series([True, False, True, False])
def test_drop_duplicates(any_numpy_dtype, keep, expected):
tc = Series([1, 0, 3, 5, 3, 0, 4], dtype=np.dtype(any_numpy_dtype))

if tc.dtype == 'bool':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would just skip if bool here

# all non-zero values are True and hence duplicate
if keep == 'first':
expected = Series([False, False, True, True, True, True, True])
elif keep == 'last':
expected = Series([True, True, True, True, True, False, False])
else:
expected = Series([True] * 7)

tm.assert_series_equal(tc.duplicated(keep=keep), expected)
tm.assert_series_equal(tc.drop_duplicates(keep=keep), tc[~expected])
Expand Down