Skip to content

COMPAT: remove some deprecation warnings in 3.6 #14681

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/io/tests/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ def test_to_jsonl(self):
def test_latin_encoding(self):
if compat.PY2:
self.assertRaisesRegexp(
TypeError, '\[unicode\] is not implemented as a table column')
TypeError, r'\[unicode\] is not implemented as a table column')
return

# GH 13774
Expand Down
8 changes: 4 additions & 4 deletions pandas/io/tests/parser/c_parser_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ def test_dtype_and_names_error(self):
3.0 3
"""
# base cases
result = self.read_csv(StringIO(data), sep='\s+', header=None)
result = self.read_csv(StringIO(data), sep=r'\s+', header=None)
expected = DataFrame([[1.0, 1], [2.0, 2], [3.0, 3]])
tm.assert_frame_equal(result, expected)

result = self.read_csv(StringIO(data), sep='\s+',
result = self.read_csv(StringIO(data), sep=r'\s+',
header=None, names=['a', 'b'])
expected = DataFrame(
[[1.0, 1], [2.0, 2], [3.0, 3]], columns=['a', 'b'])
tm.assert_frame_equal(result, expected)

# fallback casting
result = self.read_csv(StringIO(
data), sep='\s+', header=None,
data), sep=r'\s+', header=None,
names=['a', 'b'], dtype={'a': np.int32})
expected = DataFrame([[1, 1], [2, 2], [3, 3]],
columns=['a', 'b'])
Expand All @@ -97,7 +97,7 @@ def test_dtype_and_names_error(self):
"""
# fallback casting, but not castable
with tm.assertRaisesRegexp(ValueError, 'cannot safely convert'):
self.read_csv(StringIO(data), sep='\s+', header=None,
self.read_csv(StringIO(data), sep=r'\s+', header=None,
names=['a', 'b'], dtype={'a': np.int32})

def test_passing_dtype(self):
Expand Down
16 changes: 8 additions & 8 deletions pandas/io/tests/parser/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ def test_integer_overflow_bug(self):
result = self.read_csv(StringIO(data), header=None, sep=' ')
self.assertTrue(result[0].dtype == np.float64)

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

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

Expand Down Expand Up @@ -1052,7 +1052,7 @@ def test_uneven_lines_with_usecols(self):

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

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

def test_single_char_leading_whitespace(self):
# see gh-9710
Expand Down Expand Up @@ -1157,7 +1157,7 @@ def test_empty_lines(self):
[-70., .4, 1.]])
df = self.read_csv(StringIO(data))
tm.assert_numpy_array_equal(df.values, expected)
df = self.read_csv(StringIO(data.replace(',', ' ')), sep='\s+')
df = self.read_csv(StringIO(data.replace(',', ' ')), sep=r'\s+')
tm.assert_numpy_array_equal(df.values, expected)
expected = np.array([[1., 2., 4.],
[np.nan, np.nan, np.nan],
Expand Down Expand Up @@ -1189,14 +1189,14 @@ def test_regex_separator(self):
b 1 2 3 4
c 1 2 3 4
"""
df = self.read_table(StringIO(data), sep='\s+')
df = self.read_table(StringIO(data), sep=r'\s+')
expected = self.read_csv(StringIO(re.sub('[ ]+', ',', data)),
index_col=0)
self.assertIsNone(expected.index.name)
tm.assert_frame_equal(df, expected)

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

result = self.read_csv(new_file, sep='\s+', header=None)
result = self.read_csv(new_file, sep=r'\s+', header=None)
new_file.close()
expected = DataFrame([[0, 0]])
tm.assert_frame_equal(result, expected)
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/tests/parser/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class HeaderTests(object):

def test_read_with_bad_header(self):
errmsg = "but only \d+ lines in file"
errmsg = r"but only \d+ lines in file"

with tm.assertRaisesRegexp(ValueError, errmsg):
s = StringIO(',,')
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/tests/parser/python_parser_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ def test_read_table_buglet_4x_multiindex(self):
a q 20 4 0.4473 1.4152 0.2834 1.00661 0.1744
x q 30 3 -0.6662 -0.5243 -0.3580 0.89145 2.5838"""

df = self.read_table(StringIO(text), sep='\s+')
df = self.read_table(StringIO(text), sep=r'\s+')
self.assertEqual(df.index.names, ('one', 'two', 'three', 'four'))

# see gh-6893
data = ' A B C\na b c\n1 3 7 0 3 6\n3 1 4 1 5 9'
expected = DataFrame.from_records(
[(1, 3, 7, 0, 3, 6), (3, 1, 4, 1, 5, 9)],
columns=list('abcABC'), index=list('abc'))
actual = self.read_table(StringIO(data), sep='\s+')
actual = self.read_table(StringIO(data), sep=r'\s+')
tm.assert_frame_equal(actual, expected)

def test_skipfooter_with_decimal(self):
Expand Down
10 changes: 5 additions & 5 deletions pandas/io/tests/parser/test_unsupported.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_c_engine(self):
read_table(StringIO(data), sep=None,
delim_whitespace=False, dtype={'a': float})
with tm.assertRaisesRegexp(ValueError, msg):
read_table(StringIO(data), sep='\s', dtype={'a': float})
read_table(StringIO(data), sep=r'\s', dtype={'a': float})
with tm.assertRaisesRegexp(ValueError, msg):
read_table(StringIO(data), skipfooter=1, dtype={'a': float})

Expand All @@ -59,15 +59,15 @@ def test_c_engine(self):
read_table(StringIO(data), engine='c',
sep=None, delim_whitespace=False)
with tm.assertRaisesRegexp(ValueError, msg):
read_table(StringIO(data), engine='c', sep='\s')
read_table(StringIO(data), engine='c', sep=r'\s')
with tm.assertRaisesRegexp(ValueError, msg):
read_table(StringIO(data), engine='c', skipfooter=1)

# specify C-unsupported options without python-unsupported options
with tm.assert_produces_warning(parsers.ParserWarning):
read_table(StringIO(data), sep=None, delim_whitespace=False)
with tm.assert_produces_warning(parsers.ParserWarning):
read_table(StringIO(data), sep='\s')
read_table(StringIO(data), sep=r'\s')
with tm.assert_produces_warning(parsers.ParserWarning):
read_table(StringIO(data), skipfooter=1)

Expand All @@ -79,9 +79,9 @@ def test_c_engine(self):
msg = 'Error tokenizing data'

with tm.assertRaisesRegexp(CParserError, msg):
read_table(StringIO(text), sep='\s+')
read_table(StringIO(text), sep=r'\s+')
with tm.assertRaisesRegexp(CParserError, msg):
read_table(StringIO(text), engine='c', sep='\s+')
read_table(StringIO(text), engine='c', sep=r'\s+')

msg = "Only length-1 thousands markers supported"
data = """A|B|C
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/tests/parser/usecols.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_usecols_regex_sep(self):
# see gh-2733
data = 'a b c\n4 apple bat 5.7\n8 orange cow 10'

df = self.read_csv(StringIO(data), sep='\s+', usecols=('a', 'b'))
df = self.read_csv(StringIO(data), sep=r'\s+', usecols=('a', 'b'))

expected = DataFrame({'a': ['apple', 'orange'],
'b': ['bat', 'cow']}, index=[4, 8])
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/tests/test_clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def check_round_trip_frame(self, data_type, excel=None, sep=None):
def test_round_trip_frame_sep(self):
for dt in self.data_types:
self.check_round_trip_frame(dt, sep=',')
self.check_round_trip_frame(dt, sep='\s+')
self.check_round_trip_frame(dt, sep=r'\s+')
self.check_round_trip_frame(dt, sep='|')

def test_round_trip_frame_string(self):
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/tests/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1805,8 +1805,8 @@ def wrapped(self, *args, **kwargs):
if openpyxl_compat.is_compat(major_ver=major_ver):
orig_method(self, *args, **kwargs)
else:
msg = ('Installed openpyxl is not supported at this '
'time\. Use.+')
msg = (r'Installed openpyxl is not supported at this '
r'time\. Use.+')
with tm.assertRaisesRegexp(ValueError, msg):
orig_method(self, *args, **kwargs)
return wrapped
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def test_regex_idempotency(self):

def test_negative_skiprows(self):
with tm.assertRaisesRegexp(ValueError,
'\(you passed a negative value\)'):
r'\(you passed a negative value\)'):
self.read_html(self.spam_data, 'Water', skiprows=-1)

@network
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ def test_latin_encoding(self):

if compat.PY2:
self.assertRaisesRegexp(
TypeError, '\[unicode\] is not implemented as a table column')
TypeError, r'\[unicode\] is not implemented as a table column')
return

values = [[b'E\xc9, 17', b'', b'a', b'b', b'c'],
Expand Down
2 changes: 1 addition & 1 deletion pandas/sparse/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def test_bad_take(self):
self.assertRaises(IndexError, lambda: self.arr.take(-11))

def test_take_invalid_kwargs(self):
msg = "take\(\) got an unexpected keyword argument 'foo'"
msg = r"take\(\) got an unexpected keyword argument 'foo'"
tm.assertRaisesRegexp(TypeError, msg, self.arr.take,
[2, 3], foo=2)

Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def has_vertically_truncated_repr(df):
r = repr(df)
only_dot_row = False
for row in r.splitlines():
if re.match('^[\.\ ]+$', row):
if re.match(r'^[\.\ ]+$', row):
only_dot_row = True
return only_dot_row

Expand Down Expand Up @@ -834,7 +834,7 @@ def check_with_width(df, col_space):
# check that col_space affects HTML generation
# and be very brittle about it.
html = df.to_html(col_space=col_space)
hdrs = [x for x in html.split("\n") if re.search("<th[>\s]", x)]
hdrs = [x for x in html.split(r"\n") if re.search(r"<th[>\s]", x)]
self.assertTrue(len(hdrs) > 0)
for h in hdrs:
self.assertTrue("min-width" in h)
Expand Down Expand Up @@ -1940,7 +1940,7 @@ def test_to_string(self):
float_format='%.5f'.__mod__)
lines = result.split('\n')
header = lines[0].strip().split()
joined = '\n'.join([re.sub('\s+', ' ', x).strip() for x in lines[1:]])
joined = '\n'.join([re.sub(r'\s+', ' ', x).strip() for x in lines[1:]])
recons = read_table(StringIO(joined), names=header,
header=None, sep=' ')
tm.assert_series_equal(recons['B'], biggie['B'])
Expand Down Expand Up @@ -3782,7 +3782,7 @@ def chck_ncols(self, s):
res = repr(s)
lines = res.split('\n')
lines = [line for line in repr(s).split('\n')
if not re.match('[^\.]*\.+', line)][:-1]
if not re.match(r'[^\.]*\.+', line)][:-1]
ncolsizes = len(set(len(line.strip()) for line in lines))
self.assertEqual(ncolsizes, 1)

Expand Down Expand Up @@ -3823,7 +3823,7 @@ def test_max_rows_eq_one(self):

def test_truncate_ndots(self):
def getndots(s):
return len(re.match('[^\.]*(\.*)', s).groups()[0])
return len(re.match(r'[^\.]*(\.*)', s).groups()[0])

s = Series([0, 2, 3, 6])
with option_context("display.max_rows", 2):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def test_sem(self):
def test_sort_invalid_kwargs(self):
df = DataFrame([1, 2, 3], columns=['a'])

msg = "sort\(\) got an unexpected keyword argument 'foo'"
msg = r"sort\(\) got an unexpected keyword argument 'foo'"
tm.assertRaisesRegexp(TypeError, msg, df.sort, foo=2)

# Neither of these should raise an error because they
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def test_constructor_error_msgs(self):
'B': ['a', 'b', 'c']})

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

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

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

with tm.assertRaisesRegexp(ValueError, 'If using all scalar values, '
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/test_query_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,8 +1124,8 @@ def test_invalid_type_for_operator_raises(self):
ops = '+', '-', '*', '/'
for op in ops:
with tm.assertRaisesRegexp(TypeError,
"unsupported operand type\(s\) for "
".+: '.+' and '.+'"):
r"unsupported operand type\(s\) for "
r".+: '.+' and '.+'"):
df.eval('a {0} b'.format(op), engine=self.engine,
parser=self.parser)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def test_regex_replace_numeric_to_object_conversion(self):
self.assertEqual(res.a.dtype, np.object_)

def test_replace_regex_metachar(self):
metachars = '[]', '()', '\d', '\w', '\s'
metachars = '[]', '()', r'\d', r'\w', r'\s'

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

def test_replace_bool_with_string(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def test_take_invalid_kwargs(self):
idx = self.create_index()
indices = [1, 2]

msg = "take\(\) got an unexpected keyword argument 'foo'"
msg = r"take\(\) got an unexpected keyword argument 'foo'"
tm.assertRaisesRegexp(TypeError, msg, idx.take,
indices, foo=2)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ def test_take_invalid_kwargs(self):
idx = pd.CategoricalIndex([1, 2, 3], name='foo')
indices = [1, 0, -1]

msg = "take\(\) got an unexpected keyword argument 'foo'"
msg = r"take\(\) got an unexpected keyword argument 'foo'"
tm.assertRaisesRegexp(TypeError, msg, idx.take,
indices, foo=2)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ def take_invalid_kwargs(self):
idx = pd.MultiIndex.from_product(vals, names=['str', 'dt'])
indices = [1, 2]

msg = "take\(\) got an unexpected keyword argument 'foo'"
msg = r"take\(\) got an unexpected keyword argument 'foo'"
tm.assertRaisesRegexp(TypeError, msg, idx.take,
indices, foo=2)

Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ def test_at_to_fail(self):
df.columns = ['x', 'x', 'z']

# Check that we get the correct value in the KeyError
self.assertRaisesRegexp(KeyError, "\['y'\] not in index",
self.assertRaisesRegexp(KeyError, r"\['y'\] not in index",
lambda: df[['x', 'y', 'z']])

def test_loc_getitem_label_slice(self):
Expand Down Expand Up @@ -2232,7 +2232,7 @@ def f():
with tm.assertRaisesRegexp(
KeyError,
'MultiIndex Slicing requires the index to be fully '
'lexsorted tuple len \(2\), lexsort depth \(0\)'):
r'lexsorted tuple len \(2\), lexsort depth \(0\)'):
df.loc[(slice(None), df.loc[:, ('a', 'bar')] > 5), :]

def test_multiindex_slicers_non_unique(self):
Expand Down Expand Up @@ -3646,7 +3646,7 @@ def test_mi_access(self):
5 f B 6 A2 6
"""

df = pd.read_csv(StringIO(data), sep='\s+', index_col=0)
df = pd.read_csv(StringIO(data), sep=r'\s+', index_col=0)
df2 = df.set_index(['main', 'sub']).T.sort_index(1)
index = Index(['h1', 'h3', 'h5'])
columns = MultiIndex.from_tuples([('A', 'A1')], names=['main', 'sub'])
Expand Down
Loading