Skip to content

Commit 34f1265

Browse files
authored
COMPAT: clean up warnings (pandas-dev#19003)
1 parent 461221d commit 34f1265

25 files changed

+227
-212
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/core/dtypes/missing.py

+4
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ def array_equivalent(left, right, strict_nan=False):
316316

317317
# NaNs can occur in float and complex arrays.
318318
if is_float_dtype(left) or is_complex_dtype(left):
319+
320+
# empty
321+
if not (np.prod(left.shape) and np.prod(right.shape)):
322+
return True
319323
return ((left == right) | (isna(left) & isna(right))).all()
320324

321325
# numpy will will not allow this type of datetimelike vs integer comparison

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/io/test_parquet.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import numpy as np
99
import pandas as pd
10-
from pandas.compat import PY3, is_platform_windows
10+
from pandas.compat import PY3, is_platform_windows, is_platform_mac
1111
from pandas.io.parquet import (to_parquet, read_parquet, get_engine,
1212
PyArrowImpl, FastParquetImpl)
1313
from pandas.util import testing as tm
@@ -174,8 +174,8 @@ def test_options_get_engine(fp, pa):
174174
assert isinstance(get_engine('fastparquet'), FastParquetImpl)
175175

176176

177-
@pytest.mark.xfail(is_platform_windows(),
178-
reason="reading pa metadata failing on Windows")
177+
@pytest.mark.xfail(is_platform_windows() or is_platform_mac(),
178+
reason="reading pa metadata failing on Windows/mac")
179179
def test_cross_engine_pa_fp(df_cross_compat, pa, fp):
180180
# cross-compat with differing reading/writing engines
181181

pandas/tests/plotting/test_misc.py

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ def test_parallel_coordinates(self):
206206
def test_parallel_coordinates_with_sorted_labels(self):
207207
""" For #15908 """
208208
from pandas.plotting import parallel_coordinates
209+
209210
df = DataFrame({"feat": [i for i in range(30)],
210211
"class": [2 for _ in range(10)] +
211212
[3 for _ in range(10)] +

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])

0 commit comments

Comments
 (0)