-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
[CLN] parametrize and cleanup a bunch of tests #22093
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 all commits
de8348b
0b8f10b
72f27d4
38e4e5a
32c5c83
d7d2e26
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 |
---|---|---|
|
@@ -74,29 +74,29 @@ def test_corr_non_numeric(self): | |
tm.assert_frame_equal(result, expected) | ||
|
||
@td.skip_if_no_scipy | ||
def test_corr_nooverlap(self): | ||
@pytest.mark.parametrize('meth', ['pearson', 'kendall', 'spearman']) | ||
def test_corr_nooverlap(self, meth): | ||
# nothing in common | ||
for meth in ['pearson', 'kendall', 'spearman']: | ||
df = DataFrame({'A': [1, 1.5, 1, np.nan, np.nan, np.nan], | ||
'B': [np.nan, np.nan, np.nan, 1, 1.5, 1], | ||
'C': [np.nan, np.nan, np.nan, np.nan, | ||
np.nan, np.nan]}) | ||
rs = df.corr(meth) | ||
assert isna(rs.loc['A', 'B']) | ||
assert isna(rs.loc['B', 'A']) | ||
assert rs.loc['A', 'A'] == 1 | ||
assert rs.loc['B', 'B'] == 1 | ||
assert isna(rs.loc['C', 'C']) | ||
df = DataFrame({'A': [1, 1.5, 1, np.nan, np.nan, np.nan], | ||
'B': [np.nan, np.nan, np.nan, 1, 1.5, 1], | ||
'C': [np.nan, np.nan, np.nan, np.nan, | ||
np.nan, np.nan]}) | ||
rs = df.corr(meth) | ||
assert isna(rs.loc['A', 'B']) | ||
assert isna(rs.loc['B', 'A']) | ||
assert rs.loc['A', 'A'] == 1 | ||
assert rs.loc['B', 'B'] == 1 | ||
assert isna(rs.loc['C', 'C']) | ||
|
||
@td.skip_if_no_scipy | ||
def test_corr_constant(self): | ||
@pytest.mark.parametrize('meth', ['pearson', 'spearman']) | ||
def test_corr_constant(self, meth): | ||
# constant --> all NA | ||
|
||
for meth in ['pearson', 'spearman']: | ||
df = DataFrame({'A': [1, 1, 1, np.nan, np.nan, np.nan], | ||
'B': [np.nan, np.nan, np.nan, 1, 1, 1]}) | ||
rs = df.corr(meth) | ||
assert isna(rs.values).all() | ||
df = DataFrame({'A': [1, 1, 1, np.nan, np.nan, np.nan], | ||
'B': [np.nan, np.nan, np.nan, 1, 1, 1]}) | ||
rs = df.corr(meth) | ||
assert isna(rs.values).all() | ||
|
||
def test_corr_int(self): | ||
# dtypes other than float64 #1761 | ||
|
@@ -658,21 +658,21 @@ def test_numeric_only_flag(self, meth): | |
pytest.raises(TypeError, lambda: getattr(df2, meth)( | ||
axis=1, numeric_only=False)) | ||
|
||
def test_mixed_ops(self): | ||
@pytest.mark.parametrize('op', ['mean', 'std', 'var', | ||
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 have these as fixtures? 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. Not AFAICT 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. cython_table_items yields these (well it yields them all, maybe need to make a subset) 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.
Consider:
There are good use cases for fixtures, this isn't near the top of that list. |
||
'skew', 'kurt', 'sem']) | ||
def test_mixed_ops(self, op): | ||
# GH 16116 | ||
df = DataFrame({'int': [1, 2, 3, 4], | ||
'float': [1., 2., 3., 4.], | ||
'str': ['a', 'b', 'c', 'd']}) | ||
|
||
for op in ['mean', 'std', 'var', 'skew', | ||
'kurt', 'sem']: | ||
result = getattr(df, op)() | ||
assert len(result) == 2 | ||
|
||
with pd.option_context('use_bottleneck', False): | ||
result = getattr(df, op)() | ||
assert len(result) == 2 | ||
|
||
with pd.option_context('use_bottleneck', False): | ||
result = getattr(df, op)() | ||
assert len(result) == 2 | ||
|
||
def test_cumsum(self): | ||
self.tsframe.loc[5:10, 0] = nan | ||
self.tsframe.loc[10:15, 1] = nan | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -674,29 +674,12 @@ def _check_align(self, a, b, axis, fill_axis, how, method, limit=None): | |
assert_frame_equal(aa, ea) | ||
assert_frame_equal(ab, eb) | ||
|
||
def test_align_fill_method_inner(self): | ||
for meth in ['pad', 'bfill']: | ||
for ax in [0, 1, None]: | ||
for fax in [0, 1]: | ||
self._check_align_fill('inner', meth, ax, fax) | ||
|
||
def test_align_fill_method_outer(self): | ||
for meth in ['pad', 'bfill']: | ||
for ax in [0, 1, None]: | ||
for fax in [0, 1]: | ||
self._check_align_fill('outer', meth, ax, fax) | ||
|
||
def test_align_fill_method_left(self): | ||
for meth in ['pad', 'bfill']: | ||
for ax in [0, 1, None]: | ||
for fax in [0, 1]: | ||
self._check_align_fill('left', meth, ax, fax) | ||
|
||
def test_align_fill_method_right(self): | ||
for meth in ['pad', 'bfill']: | ||
for ax in [0, 1, None]: | ||
for fax in [0, 1]: | ||
self._check_align_fill('right', meth, ax, fax) | ||
@pytest.mark.parametrize('meth', ['pad', 'bfill']) | ||
@pytest.mark.parametrize('ax', [0, 1, None]) | ||
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. we have the axis arg as a fixture (though may need to add another one which adds None to it) 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. ok for sure need to use the fixture (but again can come back later on this) |
||
@pytest.mark.parametrize('fax', [0, 1]) | ||
@pytest.mark.parametrize('how', ['inner', 'outer', 'left', 'right']) | ||
def test_align_fill_method(self, how, meth, ax, fax): | ||
self._check_align_fill(how, meth, ax, fax) | ||
|
||
def _check_align_fill(self, kind, meth, ax, fax): | ||
left = self.frame.iloc[0:4, :10] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -855,21 +855,21 @@ def _test_stack_with_multiindex(multiindex): | |
dtype=df.dtypes[0]) | ||
assert_frame_equal(result, expected) | ||
|
||
def test_stack_preserve_categorical_dtype(self): | ||
@pytest.mark.parametrize('ordered', [False, True]) | ||
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. I think ordered is a fixture already 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. Not in conftest. 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. pandas/tests//arrays/categorical/conftest.py maybe can simply move it to top level and use it 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. Honestly, I would love to create a helper in |
||
@pytest.mark.parametrize('labels', [list("yxz"), list("yxy")]) | ||
def test_stack_preserve_categorical_dtype(self, ordered, labels): | ||
# GH13854 | ||
for ordered in [False, True]: | ||
for labels in [list("yxz"), list("yxy")]: | ||
cidx = pd.CategoricalIndex(labels, categories=list("xyz"), | ||
ordered=ordered) | ||
df = DataFrame([[10, 11, 12]], columns=cidx) | ||
result = df.stack() | ||
|
||
# `MutliIndex.from_product` preserves categorical dtype - | ||
# it's tested elsewhere. | ||
midx = pd.MultiIndex.from_product([df.index, cidx]) | ||
expected = Series([10, 11, 12], index=midx) | ||
|
||
tm.assert_series_equal(result, expected) | ||
cidx = pd.CategoricalIndex(labels, categories=list("xyz"), | ||
ordered=ordered) | ||
df = DataFrame([[10, 11, 12]], columns=cidx) | ||
result = df.stack() | ||
|
||
# `MutliIndex.from_product` preserves categorical dtype - | ||
# it's tested elsewhere. | ||
midx = pd.MultiIndex.from_product([df.index, cidx]) | ||
expected = Series([10, 11, 12], index=midx) | ||
|
||
tm.assert_series_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("level", [0, 'baz']) | ||
def test_unstack_swaplevel_sortlevel(self, level): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1038,9 +1038,10 @@ def test_add_raises(self): | |
dt1 + dt2 | ||
|
||
boxes = [lambda x: x, lambda x: pd.Series([x]), lambda x: pd.Index([x])] | ||
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. maybe move these 2 lines to the top of the file? 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. If we use them more than once it makes sense, but ATM they are defined right next to where they are used, which is pretty ideal. |
||
ids = ['identity', 'Series', 'Index'] | ||
|
||
@pytest.mark.parametrize('lbox', boxes) | ||
@pytest.mark.parametrize('rbox', boxes) | ||
@pytest.mark.parametrize('lbox', boxes, ids=ids) | ||
@pytest.mark.parametrize('rbox', boxes, ids=ids) | ||
def test_add_timestamp_raises(self, rbox, lbox): | ||
# GH # 17983 | ||
ts = pd.Timestamp('2017') | ||
|
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.
should make this a fixture