Skip to content

Commit af4e8fa

Browse files
committed
COMPAT: remove some deprecation warnings in 3.6
partion on #14679
1 parent 45543ec commit af4e8fa

22 files changed

+85
-82
lines changed

pandas/io/tests/json/test_pandas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ def test_to_jsonl(self):
971971
def test_latin_encoding(self):
972972
if compat.PY2:
973973
self.assertRaisesRegexp(
974-
TypeError, '\[unicode\] is not implemented as a table column')
974+
TypeError, r'\[unicode\] is not implemented as a table column')
975975
return
976976

977977
# GH 13774

pandas/io/tests/parser/common.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ def test_integer_overflow_bug(self):
836836
result = self.read_csv(StringIO(data), header=None, sep=' ')
837837
self.assertTrue(result[0].dtype == np.float64)
838838

839-
result = self.read_csv(StringIO(data), header=None, sep='\s+')
839+
result = self.read_csv(StringIO(data), header=None, sep=r'\s+')
840840
self.assertTrue(result[0].dtype == np.float64)
841841

842842
def test_catch_too_many_names(self):
@@ -852,7 +852,7 @@ def test_catch_too_many_names(self):
852852
def test_ignore_leading_whitespace(self):
853853
# see gh-3374, gh-6607
854854
data = ' a b c\n 1 2 3\n 4 5 6\n 7 8 9'
855-
result = self.read_table(StringIO(data), sep='\s+')
855+
result = self.read_table(StringIO(data), sep=r'\s+')
856856
expected = DataFrame({'a': [1, 4, 7], 'b': [2, 5, 8], 'c': [3, 6, 9]})
857857
tm.assert_frame_equal(result, expected)
858858

@@ -1052,7 +1052,7 @@ def test_uneven_lines_with_usecols(self):
10521052

10531053
# make sure that an error is still thrown
10541054
# when the 'usecols' parameter is not provided
1055-
msg = "Expected \d+ fields in line \d+, saw \d+"
1055+
msg = r"Expected \d+ fields in line \d+, saw \d+"
10561056
with tm.assertRaisesRegexp(ValueError, msg):
10571057
df = self.read_csv(StringIO(csv))
10581058

@@ -1122,7 +1122,7 @@ def test_raise_on_sep_with_delim_whitespace(self):
11221122
# see gh-6607
11231123
data = 'a b c\n1 2 3'
11241124
with tm.assertRaisesRegexp(ValueError, 'you can only specify one'):
1125-
self.read_table(StringIO(data), sep='\s', delim_whitespace=True)
1125+
self.read_table(StringIO(data), sep=r'\s', delim_whitespace=True)
11261126

11271127
def test_single_char_leading_whitespace(self):
11281128
# see gh-9710
@@ -1157,7 +1157,7 @@ def test_empty_lines(self):
11571157
[-70., .4, 1.]])
11581158
df = self.read_csv(StringIO(data))
11591159
tm.assert_numpy_array_equal(df.values, expected)
1160-
df = self.read_csv(StringIO(data.replace(',', ' ')), sep='\s+')
1160+
df = self.read_csv(StringIO(data.replace(',', ' ')), sep=r'\s+')
11611161
tm.assert_numpy_array_equal(df.values, expected)
11621162
expected = np.array([[1., 2., 4.],
11631163
[np.nan, np.nan, np.nan],
@@ -1189,14 +1189,14 @@ def test_regex_separator(self):
11891189
b 1 2 3 4
11901190
c 1 2 3 4
11911191
"""
1192-
df = self.read_table(StringIO(data), sep='\s+')
1192+
df = self.read_table(StringIO(data), sep=r'\s+')
11931193
expected = self.read_csv(StringIO(re.sub('[ ]+', ',', data)),
11941194
index_col=0)
11951195
self.assertIsNone(expected.index.name)
11961196
tm.assert_frame_equal(df, expected)
11971197

11981198
data = ' a b c\n1 2 3 \n4 5 6\n 7 8 9'
1199-
result = self.read_table(StringIO(data), sep='\s+')
1199+
result = self.read_table(StringIO(data), sep=r'\s+')
12001200
expected = DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
12011201
columns=['a', 'b', 'c'])
12021202
tm.assert_frame_equal(result, expected)
@@ -1580,7 +1580,7 @@ def test_temporary_file(self):
15801580
new_file.flush()
15811581
new_file.seek(0)
15821582

1583-
result = self.read_csv(new_file, sep='\s+', header=None)
1583+
result = self.read_csv(new_file, sep=r'\s+', header=None)
15841584
new_file.close()
15851585
expected = DataFrame([[0, 0]])
15861586
tm.assert_frame_equal(result, expected)

pandas/io/tests/test_pytables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ def test_latin_encoding(self):
987987

988988
if compat.PY2:
989989
self.assertRaisesRegexp(
990-
TypeError, '\[unicode\] is not implemented as a table column')
990+
TypeError, r'\[unicode\] is not implemented as a table column')
991991
return
992992

993993
values = [[b'E\xc9, 17', b'', b'a', b'b', b'c'],

pandas/tests/formats/test_format.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def has_vertically_truncated_repr(df):
8989
r = repr(df)
9090
only_dot_row = False
9191
for row in r.splitlines():
92-
if re.match('^[\.\ ]+$', row):
92+
if re.match(r'^[\.\ ]+$', row):
9393
only_dot_row = True
9494
return only_dot_row
9595

@@ -834,7 +834,7 @@ def check_with_width(df, col_space):
834834
# check that col_space affects HTML generation
835835
# and be very brittle about it.
836836
html = df.to_html(col_space=col_space)
837-
hdrs = [x for x in html.split("\n") if re.search("<th[>\s]", x)]
837+
hdrs = [x for x in html.split(r"\n") if re.search(r"<th[>\s]", x)]
838838
self.assertTrue(len(hdrs) > 0)
839839
for h in hdrs:
840840
self.assertTrue("min-width" in h)
@@ -1940,7 +1940,7 @@ def test_to_string(self):
19401940
float_format='%.5f'.__mod__)
19411941
lines = result.split('\n')
19421942
header = lines[0].strip().split()
1943-
joined = '\n'.join([re.sub('\s+', ' ', x).strip() for x in lines[1:]])
1943+
joined = '\n'.join([re.sub(r'\s+', ' ', x).strip() for x in lines[1:]])
19441944
recons = read_table(StringIO(joined), names=header,
19451945
header=None, sep=' ')
19461946
tm.assert_series_equal(recons['B'], biggie['B'])
@@ -3782,7 +3782,7 @@ def chck_ncols(self, s):
37823782
res = repr(s)
37833783
lines = res.split('\n')
37843784
lines = [line for line in repr(s).split('\n')
3785-
if not re.match('[^\.]*\.+', line)][:-1]
3785+
if not re.match(r'[^\.]*\.+', line)][:-1]
37863786
ncolsizes = len(set(len(line.strip()) for line in lines))
37873787
self.assertEqual(ncolsizes, 1)
37883788

@@ -3823,7 +3823,7 @@ def test_max_rows_eq_one(self):
38233823

38243824
def test_truncate_ndots(self):
38253825
def getndots(s):
3826-
return len(re.match('[^\.]*(\.*)', s).groups()[0])
3826+
return len(re.match(r'[^\.]*(\.*)', s).groups()[0])
38273827

38283828
s = Series([0, 2, 3, 6])
38293829
with option_context("display.max_rows", 2):

pandas/tests/frame/test_constructors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def test_constructor_error_msgs(self):
304304
'B': ['a', 'b', 'c']})
305305

306306
# wrong size ndarray, GH 3105
307-
msg = "Shape of passed values is \(3, 4\), indices imply \(3, 3\)"
307+
msg = r"Shape of passed values is \(3, 4\), indices imply \(3, 3\)"
308308
with tm.assertRaisesRegexp(ValueError, msg):
309309
DataFrame(np.arange(12).reshape((4, 3)),
310310
columns=['foo', 'bar', 'baz'],
@@ -316,11 +316,11 @@ def test_constructor_error_msgs(self):
316316

317317
# wrong size axis labels
318318
with tm.assertRaisesRegexp(ValueError, "Shape of passed values is "
319-
"\(3, 2\), indices imply \(3, 1\)"):
319+
r"\(3, 2\), indices imply \(3, 1\)"):
320320
DataFrame(np.random.rand(2, 3), columns=['A', 'B', 'C'], index=[1])
321321

322322
with tm.assertRaisesRegexp(ValueError, "Shape of passed values is "
323-
"\(3, 2\), indices imply \(2, 2\)"):
323+
r"\(3, 2\), indices imply \(2, 2\)"):
324324
DataFrame(np.random.rand(2, 3), columns=['A', 'B'], index=[1, 2])
325325

326326
with tm.assertRaisesRegexp(ValueError, 'If using all scalar values, '

pandas/tests/frame/test_query_eval.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,8 +1124,8 @@ def test_invalid_type_for_operator_raises(self):
11241124
ops = '+', '-', '*', '/'
11251125
for op in ops:
11261126
with tm.assertRaisesRegexp(TypeError,
1127-
"unsupported operand type\(s\) for "
1128-
".+: '.+' and '.+'"):
1127+
r"unsupported operand type\(s\) for "
1128+
r".+: '.+' and '.+'"):
11291129
df.eval('a {0} b'.format(op), engine=self.engine,
11301130
parser=self.parser)
11311131

pandas/tests/frame/test_replace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def test_regex_replace_numeric_to_object_conversion(self):
550550
self.assertEqual(res.a.dtype, np.object_)
551551

552552
def test_replace_regex_metachar(self):
553-
metachars = '[]', '()', '\d', '\w', '\s'
553+
metachars = '[]', '()', r'\d', r'\w', r'\s'
554554

555555
for metachar in metachars:
556556
df = DataFrame({'a': [metachar, 'else']})
@@ -889,7 +889,7 @@ def test_replace_doesnt_replace_without_regex(self):
889889
2 2 0 0 0
890890
3 3 0 bt 0"""
891891
df = pd.read_csv(StringIO(raw), sep=r'\s+')
892-
res = df.replace({'\D': 1})
892+
res = df.replace({r'\D': 1})
893893
assert_frame_equal(df, res)
894894

895895
def test_replace_bool_with_string(self):

pandas/tests/indexes/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def test_take_invalid_kwargs(self):
431431
idx = self.create_index()
432432
indices = [1, 2]
433433

434-
msg = "take\(\) got an unexpected keyword argument 'foo'"
434+
msg = r"take\(\) got an unexpected keyword argument 'foo'"
435435
tm.assertRaisesRegexp(TypeError, msg, idx.take,
436436
indices, foo=2)
437437

pandas/tests/indexes/test_category.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ def test_take_invalid_kwargs(self):
890890
idx = pd.CategoricalIndex([1, 2, 3], name='foo')
891891
indices = [1, 0, -1]
892892

893-
msg = "take\(\) got an unexpected keyword argument 'foo'"
893+
msg = r"take\(\) got an unexpected keyword argument 'foo'"
894894
tm.assertRaisesRegexp(TypeError, msg, idx.take,
895895
indices, foo=2)
896896

pandas/tests/indexes/test_multi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,7 @@ def take_invalid_kwargs(self):
18701870
idx = pd.MultiIndex.from_product(vals, names=['str', 'dt'])
18711871
indices = [1, 2]
18721872

1873-
msg = "take\(\) got an unexpected keyword argument 'foo'"
1873+
msg = r"take\(\) got an unexpected keyword argument 'foo'"
18741874
tm.assertRaisesRegexp(TypeError, msg, idx.take,
18751875
indices, foo=2)
18761876

0 commit comments

Comments
 (0)