Skip to content

Commit 72c2a3f

Browse files
committed
TST: show deprecation config options as FutureWarnings
STYLE: clean some pytest / linting warnings xref pandas-dev#19004, dateutil deprecation warnings
1 parent e957dcd commit 72c2a3f

19 files changed

+39
-39
lines changed

appveyor.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ environment:
1515
# See: http://stackoverflow.com/a/13751649/163740
1616
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\ci\\run_with_env.cmd"
1717
clone_folder: C:\projects\pandas
18+
PANDAS_TESTING_MODE: "deprecate"
1819

1920
matrix:
2021

doc/source/whatsnew/v0.23.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Other API Changes
207207
- :func:`wide_to_long` previously kept numeric-like suffixes as ``object`` dtype. Now they are cast to numeric if possible (:issue:`17627`)
208208
- In :func:`read_excel`, the ``comment`` argument is now exposed as a named parameter (:issue:`18735`)
209209
- Rearranged the order of keyword arguments in :func:`read_excel()` to align with :func:`read_csv()` (:issue:`16672`)
210+
- The options ``html.border`` and ``mode.use_inf_as_null`` were deprecated in prior versions, these will now show ``FutureWarning`` rather than a ``DeprecationWarning`` (:issue:`19003`)
210211

211212
.. _whatsnew_0230.deprecations:
212213

pandas/core/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def _warn_if_deprecated(key):
613613
if d:
614614
if d.msg:
615615
print(d.msg)
616-
warnings.warn(d.msg, DeprecationWarning)
616+
warnings.warn(d.msg, FutureWarning)
617617
else:
618618
msg = "'{key}' is deprecated".format(key=key)
619619
if d.removal_ver:
@@ -624,7 +624,7 @@ def _warn_if_deprecated(key):
624624
else:
625625
msg += ', please refrain from using it.'
626626

627-
warnings.warn(msg, DeprecationWarning)
627+
warnings.warn(msg, FutureWarning)
628628
return True
629629
return False
630630

pandas/tests/frame/test_constructors.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@ def test_constructor_error_msgs(self):
328328

329329
# wrong size axis labels
330330
with tm.assert_raises_regex(ValueError, "Shape of passed values "
331-
"is \(3, 2\), indices "
332-
"imply \(3, 1\)"):
331+
r"is \(3, 2\), indices "
332+
r"imply \(3, 1\)"):
333333
DataFrame(np.random.rand(2, 3), columns=['A', 'B', 'C'], index=[1])
334334

335335
with tm.assert_raises_regex(ValueError, "Shape of passed values "
336-
"is \(3, 2\), indices "
337-
"imply \(2, 2\)"):
336+
r"is \(3, 2\), indices "
337+
r"imply \(2, 2\)"):
338338
DataFrame(np.random.rand(2, 3), columns=['A', 'B'], index=[1, 2])
339339

340340
with tm.assert_raises_regex(ValueError, "If using all scalar "
@@ -1220,12 +1220,12 @@ def test_constructor_from_items(self):
12201220
def test_constructor_from_items_scalars(self):
12211221
# GH 17312
12221222
with tm.assert_raises_regex(ValueError,
1223-
'The value in each \(key, value\) '
1223+
r'The value in each \(key, value\) '
12241224
'pair must be an array, Series, or dict'):
12251225
DataFrame.from_items([('A', 1), ('B', 4)])
12261226

12271227
with tm.assert_raises_regex(ValueError,
1228-
'The value in each \(key, value\) '
1228+
r'The value in each \(key, value\) '
12291229
'pair must be an array, Series, or dict'):
12301230
DataFrame.from_items([('A', 1), ('B', 2)], columns=['col1'],
12311231
orient='index')

pandas/tests/frame/test_query_eval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,6 @@ def test_invalid_type_for_operator_raises(self, parser, engine):
10401040
ops = '+', '-', '*', '/'
10411041
for op in ops:
10421042
with tm.assert_raises_regex(TypeError,
1043-
"unsupported operand type\(s\) "
1043+
r"unsupported operand type\(s\) "
10441044
"for .+: '.+' and '.+'"):
10451045
df.eval('a {0} b'.format(op), engine=engine, parser=parser)

pandas/tests/groupby/test_nth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_nth(self):
175175
df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=['A', 'B'])
176176
g = df.groupby('A')
177177
# PR 17493, related to issue 11038
178-
# test Series.nth with True for dropna produces DeprecationWarning
178+
# test Series.nth with True for dropna produces FutureWarning
179179
with assert_produces_warning(FutureWarning):
180180
result = g.B.nth(0, dropna=True)
181181
expected = g.B.first()

pandas/tests/groupby/test_transform.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def test_transform_casting(self):
261261
9 B-053 b76cd912ff "2014-10-08 19:17:48"
262262
10 B-065 b76cd912ff "2014-10-08 19:21:38"
263263
"""
264-
df = pd.read_csv(StringIO(data), sep='\s+',
264+
df = pd.read_csv(StringIO(data), sep=r'\s+',
265265
index_col=[0], parse_dates=['DATETIME'])
266266

267267
result = df.groupby('ID3')['DATETIME'].transform(lambda x: x.diff())

pandas/tests/indexes/datetimes/test_date_range.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def test_daterange_bug_456(self):
402402
assert isinstance(result, DatetimeIndex)
403403

404404
def test_error_with_zero_monthends(self):
405-
msg = 'Offset <0 \* MonthEnds> did not increment date'
405+
msg = r'Offset <0 \* MonthEnds> did not increment date'
406406
with tm.assert_raises_regex(ValueError, msg):
407407
date_range('1/1/2000', '1/1/2001', freq=MonthEnd(0))
408408

pandas/tests/indexes/datetimes/test_tools.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ def test_dataframe(self, cache):
709709
'day': [4, 5]})
710710

711711
msg = ("cannot assemble the datetimes: time data .+ does not "
712-
"match format '%Y%m%d' \(match\)")
712+
r"match format '%Y%m%d' \(match\)")
713713
with tm.assert_raises_regex(ValueError, msg):
714714
to_datetime(df2, cache=cache)
715715
result = to_datetime(df2, errors='coerce', cache=cache)
@@ -719,15 +719,15 @@ def test_dataframe(self, cache):
719719

720720
# extra columns
721721
msg = ("extra keys have been passed to the datetime assemblage: "
722-
"\[foo\]")
722+
r"\[foo\]")
723723
with tm.assert_raises_regex(ValueError, msg):
724724
df2 = df.copy()
725725
df2['foo'] = 1
726726
to_datetime(df2, cache=cache)
727727

728728
# not enough
729-
msg = ('to assemble mappings requires at least that \[year, month, '
730-
'day\] be specified: \[.+\] is missing')
729+
msg = (r'to assemble mappings requires at least that \[year, month, '
730+
r'day\] be specified: \[.+\] is missing')
731731
for c in [['year'],
732732
['year', 'month'],
733733
['year', 'month', 'second'],

pandas/tests/indexes/interval/test_interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_constructors_empty(self, data, closed):
175175
def test_constructors_errors(self):
176176

177177
# scalar
178-
msg = ('IntervalIndex\(...\) must be called with a collection of '
178+
msg = (r'IntervalIndex\(...\) must be called with a collection of '
179179
'some kind, 5 was passed')
180180
with tm.assert_raises_regex(TypeError, msg):
181181
IntervalIndex(5)

pandas/tests/indexing/test_multiindex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def test_getitem_partial_int(self):
299299
# missing item:
300300
with tm.assert_raises_regex(KeyError, '1'):
301301
df[1]
302-
with tm.assert_raises_regex(KeyError, "'\[1\] not in index'"):
302+
with tm.assert_raises_regex(KeyError, r"'\[1\] not in index'"):
303303
df[[1]]
304304

305305
def test_loc_multiindex_indexer_none(self):

pandas/tests/io/formats/test_to_html.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1411,8 +1411,9 @@ def test_to_html_border_zero(self):
14111411
result = df.to_html(border=0)
14121412
assert 'border="0"' in result
14131413

1414+
@tm.capture_stdout
14141415
def test_display_option_warning(self):
1415-
with tm.assert_produces_warning(DeprecationWarning,
1416+
with tm.assert_produces_warning(FutureWarning,
14161417
check_stacklevel=False):
14171418
pd.options.html.border
14181419

pandas/tests/io/formats/test_to_latex.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,11 @@ def test_to_latex_longtable(self, frame):
424424

425425
df = DataFrame({'a': [1, 2]})
426426
with1column_result = df.to_latex(index=False, longtable=True)
427-
assert "\multicolumn{1}" in with1column_result
427+
assert r"\multicolumn{1}" in with1column_result
428428

429429
df = DataFrame({'a': [1, 2], 'b': [3, 4], 'c': [5, 6]})
430430
with3columns_result = df.to_latex(index=False, longtable=True)
431-
assert "\multicolumn{3}" in with3columns_result
431+
assert r"\multicolumn{3}" in with3columns_result
432432

433433
def test_to_latex_escape_special_chars(self):
434434
special_characters = ['&', '%', '$', '#', '_', '{', '}', '~', '^',

pandas/tests/reshape/merge/test_merge_asof.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ def test_on_float_by_int(self):
976976

977977
def test_merge_datatype_error(self):
978978
""" Tests merge datatype mismatch error """
979-
msg = 'merge keys \[0\] object and int64, must be the same type'
979+
msg = r'merge keys \[0\] object and int64, must be the same type'
980980

981981
left = pd.DataFrame({'left_val': [1, 5, 10],
982982
'a': ['a', 'b', 'c']})

pandas/tests/reshape/test_concat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ def test_concatlike_same_dtypes(self):
178178
tm.assert_series_equal(res, exp, check_index_type=True)
179179

180180
# cannot append non-index
181-
msg = ('cannot concatenate object of type \"(.+?)\";'
181+
msg = (r'cannot concatenate object of type \"(.+?)\";'
182182
' only pd.Series, pd.DataFrame, and pd.Panel'
183-
' \(deprecated\) objs are valid')
183+
r' \(deprecated\) objs are valid')
184184
with tm.assert_raises_regex(TypeError, msg):
185185
pd.Series(vals1).append(vals2)
186186

pandas/tests/scalar/test_interval.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_math_add(self, interval):
122122
actual += 1
123123
assert expected == actual
124124

125-
msg = "unsupported operand type\(s\) for \+"
125+
msg = r"unsupported operand type\(s\) for \+"
126126
with tm.assert_raises_regex(TypeError, msg):
127127
interval + Interval(1, 2)
128128

@@ -138,7 +138,7 @@ def test_math_sub(self, interval):
138138
actual -= 1
139139
assert expected == actual
140140

141-
msg = "unsupported operand type\(s\) for -"
141+
msg = r"unsupported operand type\(s\) for -"
142142
with tm.assert_raises_regex(TypeError, msg):
143143
interval - Interval(1, 2)
144144

@@ -158,11 +158,11 @@ def test_math_mult(self, interval):
158158
actual *= 2
159159
assert expected == actual
160160

161-
msg = "unsupported operand type\(s\) for \*"
161+
msg = r"unsupported operand type\(s\) for \*"
162162
with tm.assert_raises_regex(TypeError, msg):
163163
interval * Interval(1, 2)
164164

165-
msg = "can\'t multiply sequence by non-int"
165+
msg = r"can\'t multiply sequence by non-int"
166166
with tm.assert_raises_regex(TypeError, msg):
167167
interval * 'foo'
168168

@@ -175,7 +175,7 @@ def test_math_div(self, interval):
175175
actual /= 2.0
176176
assert expected == actual
177177

178-
msg = "unsupported operand type\(s\) for /"
178+
msg = r"unsupported operand type\(s\) for /"
179179
with tm.assert_raises_regex(TypeError, msg):
180180
interval / Interval(1, 2)
181181

pandas/tests/series/test_missing.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,9 @@ def test_isna_for_inf(self):
480480
def test_isnull_for_inf_deprecated(self):
481481
# gh-17115
482482
s = Series(['a', np.inf, np.nan, 1.0])
483-
with tm.assert_produces_warning(DeprecationWarning,
484-
check_stacklevel=False):
485-
pd.set_option('mode.use_inf_as_null', True)
483+
with pd.option_context('mode.use_inf_as_null', True):
486484
r = s.isna()
487485
dr = s.dropna()
488-
pd.reset_option('mode.use_inf_as_null')
489486

490487
e = Series([False, True, True, False])
491488
de = Series(['a', 1.0], index=[0, 3])

pandas/tests/test_algos.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,10 @@ def test_duplicated_with_nas(self):
788788
2, 4, 1, 5, 6]),
789789
np.array([1.1, 2.2, 1.1, np.nan, 3.3,
790790
2.2, 4.4, 1.1, np.nan, 6.6]),
791-
pytest.mark.xfail(reason="Complex bug. GH 16399")(
792-
np.array([1 + 1j, 2 + 2j, 1 + 1j, 5 + 5j, 3 + 3j,
793-
2 + 2j, 4 + 4j, 1 + 1j, 5 + 5j, 6 + 6j])
794-
),
791+
pytest.param(np.array([1 + 1j, 2 + 2j, 1 + 1j, 5 + 5j, 3 + 3j,
792+
2 + 2j, 4 + 4j, 1 + 1j, 5 + 5j, 6 + 6j]),
793+
marks=pytest.mark.xfail(reason="Complex bug. GH 16399")
794+
),
795795
np.array(['a', 'b', 'a', 'e', 'c',
796796
'b', 'd', 'a', 'e', 'f'], dtype=object),
797797
np.array([1, 2**63, 1, 3**5, 10, 2**63, 39, 1, 3**5, 7],

pandas/tests/test_multilevel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2289,7 +2289,7 @@ def test_reset_index_multiindex_columns(self):
22892289

22902290
# gh-16120: already existing column
22912291
with tm.assert_raises_regex(ValueError,
2292-
("cannot insert \('A', ''\), "
2292+
(r"cannot insert \('A', ''\), "
22932293
"already exists")):
22942294
df.rename_axis('A').reset_index()
22952295

@@ -2323,7 +2323,7 @@ def test_reset_index_multiindex_columns(self):
23232323
# ... which is incompatible with col_fill=None
23242324
with tm.assert_raises_regex(ValueError,
23252325
("col_fill=None is incompatible with "
2326-
"incomplete column name \('C', 'c'\)")):
2326+
r"incomplete column name \('C', 'c'\)")):
23272327
df2.rename_axis([('C', 'c')]).reset_index(col_fill=None)
23282328

23292329
# with col_level != 0

0 commit comments

Comments
 (0)