Skip to content

Commit 04104a7

Browse files
committed
fine grained catching warnings in tests
1 parent f8800dc commit 04104a7

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

pandas/core/window.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1688,10 +1688,13 @@ def dataframe_from_int_dict(data, frame_template):
16881688
raise ValueError("'arg1' columns are not unique")
16891689
if not arg2.columns.is_unique:
16901690
raise ValueError("'arg2' columns are not unique")
1691-
X, Y = arg1.align(arg2, join='outer')
1691+
with warnings.catch_warnings(record=True):
1692+
X, Y = arg1.align(arg2, join='outer')
16921693
X = X + 0 * Y
16931694
Y = Y + 0 * X
1694-
res_columns = arg1.columns.union(arg2.columns)
1695+
1696+
with warnings.catch_warnings(record=True):
1697+
res_columns = arg1.columns.union(arg2.columns)
16951698
for col in res_columns:
16961699
if col in X and col in Y:
16971700
results[col] = f(X[col], Y[col])

pandas/tests/test_window.py

+24-26
Original file line numberDiff line numberDiff line change
@@ -1723,15 +1723,13 @@ def test_no_flex(self, f):
17231723

17241724
# DataFrame methods (which do not call _flex_binary_moment())
17251725

1726-
with warnings.catch_warnings(record=True):
1727-
1728-
results = [f(df) for df in self.df1s]
1729-
for (df, result) in zip(self.df1s, results):
1730-
tm.assert_index_equal(result.index, df.columns)
1731-
tm.assert_index_equal(result.columns, df.columns)
1732-
for i, result in enumerate(results):
1733-
if i > 0:
1734-
self.compare(result, results[0])
1726+
results = [f(df) for df in self.df1s]
1727+
for (df, result) in zip(self.df1s, results):
1728+
tm.assert_index_equal(result.index, df.columns)
1729+
tm.assert_index_equal(result.columns, df.columns)
1730+
for i, result in enumerate(results):
1731+
if i > 0:
1732+
self.compare(result, results[0])
17351733

17361734
@pytest.mark.parametrize(
17371735
'f', [lambda x: x.expanding().cov(pairwise=True),
@@ -1805,24 +1803,24 @@ def test_pairwise_with_other(self, f):
18051803
lambda x, y: x.ewm(com=3).corr(y, pairwise=False), ])
18061804
def test_no_pairwise_with_other(self, f):
18071805

1808-
with warnings.catch_warnings(record=True):
1809-
1810-
# DataFrame with another DataFrame, pairwise=False
1811-
results = [f(df, self.df2) if df.columns.is_unique else None
1812-
for df in self.df1s]
1813-
for (df, result) in zip(self.df1s, results):
1814-
if result is not None:
1806+
# DataFrame with another DataFrame, pairwise=False
1807+
results = [f(df, self.df2) if df.columns.is_unique else None
1808+
for df in self.df1s]
1809+
for (df, result) in zip(self.df1s, results):
1810+
if result is not None:
1811+
with catch_warnings(record=True):
1812+
# we can have int and str columns
18151813
expected_index = df.index.union(self.df2.index)
18161814
expected_columns = df.columns.union(self.df2.columns)
1817-
tm.assert_index_equal(result.index, expected_index)
1818-
tm.assert_index_equal(result.columns, expected_columns)
1819-
else:
1820-
tm.assertRaisesRegexp(
1821-
ValueError, "'arg1' columns are not unique", f, df,
1822-
self.df2)
1823-
tm.assertRaisesRegexp(
1824-
ValueError, "'arg2' columns are not unique", f,
1825-
self.df2, df)
1815+
tm.assert_index_equal(result.index, expected_index)
1816+
tm.assert_index_equal(result.columns, expected_columns)
1817+
else:
1818+
tm.assertRaisesRegexp(
1819+
ValueError, "'arg1' columns are not unique", f, df,
1820+
self.df2)
1821+
tm.assertRaisesRegexp(
1822+
ValueError, "'arg2' columns are not unique", f,
1823+
self.df2, df)
18261824

18271825
@pytest.mark.parametrize(
18281826
'f', [lambda x, y: x.expanding().cov(y),
@@ -2664,7 +2662,7 @@ def test_rolling_functions_window_non_shrinkage_binary(self):
26642662
columns=Index(['A', 'B'], name='foo'),
26652663
index=Index(range(4), name='bar'))
26662664
df_expected = DataFrame(
2667-
columns=Index(['A', 'B']),
2665+
columns=Index(['A', 'B'], name='foo'),
26682666
index=pd.MultiIndex.from_product([df.index, df.columns],
26692667
names=['bar', 'foo']),
26702668
dtype='float64')

0 commit comments

Comments
 (0)