-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: Implement maximally-specific/strict fixtures for arithmetic tests #23734
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 3 commits
86f3810
375fdb4
f8a3988
27c2ce1
df74b6b
9c07638
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,22 @@ | |
import pandas as pd | ||
|
||
from pandas.compat import long | ||
from pandas.core.arrays import PeriodArray, DatetimeArrayMixin as DatetimeArray | ||
import pandas.util.testing as tm | ||
|
||
|
||
# ------------------------------------------------------------------ | ||
# Helper Functions | ||
|
||
def id_func(x): | ||
if isinstance(x, tuple): | ||
assert len(x) == 2 | ||
return x[0].__name__ + '-' + str(x[1]) | ||
else: | ||
return x.__name__ | ||
|
||
|
||
# ------------------------------------------------------------------ | ||
|
||
@pytest.fixture(params=[1, np.array(1, dtype=np.int64)]) | ||
def one(request): | ||
# zero-dim integer array behaves like an integer | ||
|
@@ -137,7 +150,7 @@ def mismatched_freq(request): | |
# ------------------------------------------------------------------ | ||
|
||
@pytest.fixture(params=[pd.Index, pd.Series, pd.DataFrame], | ||
ids=lambda x: x.__name__) | ||
ids=id_func) | ||
def box(request): | ||
""" | ||
Several array-like containers that should have effectively identical | ||
|
@@ -150,42 +163,86 @@ def box(request): | |
pd.Series, | ||
pytest.param(pd.DataFrame, | ||
marks=pytest.mark.xfail(strict=True))], | ||
ids=lambda x: x.__name__) | ||
ids=id_func) | ||
def box_df_fail(request): | ||
""" | ||
Fixture equivalent to `box` fixture but xfailing the DataFrame case. | ||
""" | ||
return request.param | ||
|
||
|
||
@pytest.fixture(params=[(pd.Index, False), | ||
(pd.Series, False), | ||
@pytest.fixture(params=[pd.Index, pd.Series, pd.DataFrame, tm.to_array], | ||
ids=id_func) | ||
def box4(request): | ||
""" | ||
Fixture to test on each of Index, Series, DataFrame, and pandas Array | ||
classes. | ||
""" | ||
return request.param | ||
|
||
|
||
@pytest.fixture(params=[pd.Index, | ||
pd.Series, | ||
(pd.DataFrame, False), | ||
pytest.param((pd.DataFrame, True), | ||
marks=pytest.mark.xfail(strict=True))], | ||
ids=lambda x: x[0].__name__ + '-' + str(x[1])) | ||
def box_transpose_fail(request): | ||
(pd.DataFrame, True), | ||
tm.to_array], | ||
ids=id_func) | ||
def box5(request): | ||
""" | ||
Fixture similar to `box` but testing both transpose cases for DataFrame, | ||
with the tranpose=True case xfailed. | ||
Like `box4`, but the DataFrame case with box transpose=True and | ||
transpose=False | ||
""" | ||
# GH#23620 | ||
return request.param | ||
|
||
|
||
@pytest.fixture(params=[pd.Index, pd.Series, pd.DataFrame, PeriodArray], | ||
ids=lambda x: x.__name__) | ||
def box_with_period(request): | ||
@pytest.fixture(params=[pd.Index, | ||
pd.Series, | ||
(pd.DataFrame, False), | ||
pytest.param((pd.DataFrame, True), | ||
marks=pytest.mark.xfail(strict=True)), | ||
tm.to_array], | ||
ids=id_func) | ||
def box5_tfail(request): | ||
""" | ||
Like `box`, but specific to PeriodDtype for also testing PeriodArray | ||
Like `box5`, but xfailing the transposed DataFrame case | ||
""" | ||
# GH#23620 | ||
return request.param | ||
|
||
|
||
@pytest.fixture(params=[pd.Index, pd.Series, pd.DataFrame, DatetimeArray], | ||
ids=lambda x: x.__name__) | ||
def box_with_datetime(request): | ||
# Construct tuples of the form (box, tz) over all our box classes and | ||
# the timezones in tz_naive_fixture. We then xfail the cases where the box | ||
# is a DataFrame-with-transpose and the timezone is not tz-naive (i.e. None) | ||
boxes = [pd.Index, | ||
pd.Series, | ||
(pd.DataFrame, False), | ||
(pd.DataFrame, True), | ||
tm.to_array] | ||
|
||
# copied from pandas.conftest tz_naive_fixture | ||
TIMEZONES = [None, 'UTC', 'US/Eastern', 'Asia/Tokyo', 'dateutil/US/Pacific', | ||
'dateutil/Asia/Singapore'] | ||
|
||
params = [(x, y) for x in boxes for y in TIMEZONES] | ||
for n in range(len(params)): | ||
tup = params[n] | ||
if isinstance(tup[0], tuple) and tup[0][1] is True and tup[1] is not None: | ||
# i.e. (DataFrame, True, tzinfo) excluding the no-tzinfo case | ||
param = pytest.param(tup, marks=pytest.mark.xfail(strict=True)) | ||
params[n] = param | ||
|
||
|
||
@pytest.fixture(params=params) | ||
def box5_and_tz(request): | ||
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. Do we think this is really needed? (all the timezones) Because with all combinations, you get a quite combinatorial explosion (using this makes a single test into 30 tests) (I don't know how much it is used) 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. combinatorial explosion is an entirely reasonable concern. Note that this fixture is taking the place of existing usages of More generally the timezone fixtures may be leading to more tests than we really need/want, especially given the overhead of pytest collection. Two thoughts on this I've been mulling over:
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. Yes, in general those fixtures are certainly good. There is for example one place where it is combined with the Maybe more specific for this case: are both 'US/Eastern' and 'Asia/Tokyo' needed? (did we had bugs in the past that were related to that?) 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. No idea about why tz_naive_fixture includes exactly what it does. If "the tests are unnecessarily thorough" is the biggest problem we have this week, it's a pretty darn good week. 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. so the timezones that are chosen, have been sources of (since fixed) bugs in the past. We have a pretty good representative sample of various edge cases on timezones and i think we have just about the right amount, not too few and not too many, after all its just 2 per timezone library type + UTC + None. |
||
""" | ||
Like `box`, but specific to datetime64 for also testing DatetimeArray | ||
Fixture to test over Index, Series, DataFrame, and pandas Array, also | ||
providing timezones, xfailing timezone-aware cases with transposed | ||
DataFrame | ||
""" | ||
return request.param | ||
|
||
|
||
# aliases so we can use the same fixture twice in a test | ||
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. these need self-obvious names |
||
box4b = box4 | ||
box5b = box5 |
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.
so my comment above was fairly general in nature. I don't think you need to test tz's other than [None, 'UTC'] or maybe use 'US/Eastern' rather than UTC to make sure that no times are shifted.
you actually just care if there IS a timezone or not.