-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: restructure internal extension arrays tests (split between /arrays and /extension) #22026
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
Changes from 12 commits
f3e3085
6408ee0
de10591
1c40fd7
facfc44
6edec38
39e46c9
cb1350f
5574c11
a17deda
41b2615
8cf71e9
edcb3da
96a9a8b
700c405
c28cab9
6ced029
c2644cb
db2836c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# -*- coding: utf-8 -*- | ||
import pytest | ||
import numpy as np | ||
|
||
from pandas import Index, IntervalIndex, date_range, timedelta_range | ||
from pandas.core.arrays import IntervalArray | ||
import pandas.util.testing as tm | ||
|
||
|
||
@pytest.fixture(params=[ | ||
(Index([0, 2, 4]), Index([1, 3, 5])), | ||
(Index([0., 1., 2.]), Index([1., 2., 3.])), | ||
(timedelta_range('0 days', periods=3), | ||
timedelta_range('1 day', periods=3)), | ||
(date_range('20170101', periods=3), date_range('20170102', periods=3)), | ||
(date_range('20170101', periods=3, tz='US/Eastern'), | ||
date_range('20170102', periods=3, tz='US/Eastern'))], | ||
ids=lambda x: str(x[0].dtype)) | ||
def left_right_dtypes(request): | ||
""" | ||
Fixture for building an IntervalArray from various dtypes | ||
""" | ||
return request.param | ||
|
||
|
||
class TestMethods(object): | ||
|
||
@pytest.mark.parametrize('repeats', [0, 1, 5]) | ||
def test_repeat(self, left_right_dtypes, repeats): | ||
left, right = left_right_dtypes | ||
result = IntervalArray.from_arrays(left, right).repeat(repeats) | ||
expected = IntervalArray.from_arrays( | ||
left.repeat(repeats), right.repeat(repeats)) | ||
tm.assert_extension_array_equal(result, expected) | ||
|
||
@pytest.mark.parametrize('bad_repeats, msg', [ | ||
(-1, 'negative dimensions are not allowed'), | ||
('foo', r'invalid literal for (int|long)\(\) with base 10')]) | ||
def test_repeat_errors(self, bad_repeats, msg): | ||
array = IntervalArray.from_breaks(range(4)) | ||
with tm.assert_raises_regex(ValueError, msg): | ||
array.repeat(bad_repeats) | ||
|
||
@pytest.mark.parametrize('new_closed', [ | ||
'left', 'right', 'both', 'neither']) | ||
def test_set_closed(self, closed, new_closed): | ||
# GH 21670 | ||
array = IntervalArray.from_breaks(range(10), closed=closed) | ||
result = array.set_closed(new_closed) | ||
expected = IntervalArray.from_breaks(range(10), closed=new_closed) | ||
tm.assert_extension_array_equal(result, expected) | ||
|
||
|
||
class TestSetitem(object): | ||
|
||
def test_set_na(self, left_right_dtypes): | ||
left, right = left_right_dtypes | ||
result = IntervalArray.from_arrays(left, right) | ||
result[0] = np.nan | ||
|
||
expected_left = Index([left._na_value] + list(left[1:])) | ||
expected_right = Index([right._na_value] + list(right[1:])) | ||
expected = IntervalArray.from_arrays(expected_left, expected_right) | ||
|
||
tm.assert_extension_array_equal(result, expected) | ||
|
||
|
||
def test_repr_matches(): | ||
idx = IntervalIndex.from_breaks([1, 2, 3]) | ||
a = repr(idx) | ||
b = repr(idx.values) | ||
assert a.replace("Index", "Array") == b |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,9 @@ def get_op_from_name(self, op_name): | |
def check_opname(self, s, op_name, other, exc=NotImplementedError): | ||
op = self.get_op_from_name(op_name) | ||
|
||
self._check_op(s, op, other, exc) | ||
self._check_op(s, op, other, op_name, exc) | ||
|
||
def _check_op(self, s, op, other, exc=NotImplementedError): | ||
def _check_op(self, s, op, other, op_name, exc=NotImplementedError): | ||
if exc is None: | ||
result = op(s, other) | ||
expected = s.combine(other, op) | ||
|
@@ -69,7 +69,8 @@ def test_arith_series_with_array(self, data, all_arithmetic_operators): | |
# ndarray & other series | ||
op_name = all_arithmetic_operators | ||
s = pd.Series(data) | ||
self.check_opname(s, op_name, [s.iloc[0]] * len(s), exc=TypeError) | ||
self.check_opname(s, op_name, pd.Series([s.iloc[0]] * len(s)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar as what Tom said below: |
||
exc=TypeError) | ||
|
||
def test_divmod(self, data): | ||
s = pd.Series(data) | ||
|
@@ -113,5 +114,5 @@ def test_compare_scalar(self, data, all_compare_operators): | |
def test_compare_array(self, data, all_compare_operators): | ||
op_name = all_compare_operators | ||
s = pd.Series(data) | ||
other = [0] * len(data) | ||
other = pd.Series([data[0]] * len(data)) | ||
jorisvandenbossche marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self._compare_other(s, data, op_name, other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what surfaces the error here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When testing with Int8 dtype, you get an overflow warning for summing the scalars (the
a + b
below)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm ok, maybe we should actually move this to the integer tests rather than here then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is fine to ignore it here (it's numpy behaviour to warn, not something we need to test), but it's true that we might want to add explicit test for the behaviour we want on the Series level in the integer tests.
The behaviour currently to silently ignore it in the case of series is consistent with a Series with numpy dtype int8:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i understand though this may be indicative of an error in other extension types. ok for now