diff --git a/pandas/io/tests/json/test_pandas.py b/pandas/io/tests/json/test_pandas.py
index 117ac2324d0e0..ba02e9186f1df 100644
--- a/pandas/io/tests/json/test_pandas.py
+++ b/pandas/io/tests/json/test_pandas.py
@@ -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
diff --git a/pandas/io/tests/parser/c_parser_only.py b/pandas/io/tests/parser/c_parser_only.py
index 09d521e5a7e46..75b99654dbf89 100644
--- a/pandas/io/tests/parser/c_parser_only.py
+++ b/pandas/io/tests/parser/c_parser_only.py
@@ -71,11 +71,11 @@ 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'])
@@ -83,7 +83,7 @@ def test_dtype_and_names_error(self):
# 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'])
@@ -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):
diff --git a/pandas/io/tests/parser/common.py b/pandas/io/tests/parser/common.py
index f0fdc9398084f..397292ec6d036 100644
--- a/pandas/io/tests/parser/common.py
+++ b/pandas/io/tests/parser/common.py
@@ -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):
@@ -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)
@@ -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))
@@ -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
@@ -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],
@@ -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)
@@ -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)
diff --git a/pandas/io/tests/parser/header.py b/pandas/io/tests/parser/header.py
index 33a4d71fc03b6..dc6d2ad1daa47 100644
--- a/pandas/io/tests/parser/header.py
+++ b/pandas/io/tests/parser/header.py
@@ -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(',,')
diff --git a/pandas/io/tests/parser/python_parser_only.py b/pandas/io/tests/parser/python_parser_only.py
index 3214aa39358e8..bbc1c3bab7635 100644
--- a/pandas/io/tests/parser/python_parser_only.py
+++ b/pandas/io/tests/parser/python_parser_only.py
@@ -162,7 +162,7 @@ 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
@@ -170,7 +170,7 @@ def test_read_table_buglet_4x_multiindex(self):
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):
diff --git a/pandas/io/tests/parser/test_unsupported.py b/pandas/io/tests/parser/test_unsupported.py
index ef8f7967193ff..2fc238acd54e3 100644
--- a/pandas/io/tests/parser/test_unsupported.py
+++ b/pandas/io/tests/parser/test_unsupported.py
@@ -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})
@@ -59,7 +59,7 @@ 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)
@@ -67,7 +67,7 @@ def test_c_engine(self):
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)
@@ -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
diff --git a/pandas/io/tests/parser/usecols.py b/pandas/io/tests/parser/usecols.py
index 16a19c50be960..5051171ccb8f0 100644
--- a/pandas/io/tests/parser/usecols.py
+++ b/pandas/io/tests/parser/usecols.py
@@ -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])
diff --git a/pandas/io/tests/test_clipboard.py b/pandas/io/tests/test_clipboard.py
index 6c5ee6fcd22ba..af17945bbcf95 100644
--- a/pandas/io/tests/test_clipboard.py
+++ b/pandas/io/tests/test_clipboard.py
@@ -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):
diff --git a/pandas/io/tests/test_excel.py b/pandas/io/tests/test_excel.py
index a4132cd69141a..49a508dd22023 100644
--- a/pandas/io/tests/test_excel.py
+++ b/pandas/io/tests/test_excel.py
@@ -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
diff --git a/pandas/io/tests/test_html.py b/pandas/io/tests/test_html.py
index 7b4e775db9476..c202c60f5213d 100644
--- a/pandas/io/tests/test_html.py
+++ b/pandas/io/tests/test_html.py
@@ -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
diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py
index 213bc53e3aab4..72973105ff3bd 100644
--- a/pandas/io/tests/test_pytables.py
+++ b/pandas/io/tests/test_pytables.py
@@ -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'],
diff --git a/pandas/sparse/tests/test_array.py b/pandas/sparse/tests/test_array.py
index dd86e9e791e5e..2b284ac631d3f 100644
--- a/pandas/sparse/tests/test_array.py
+++ b/pandas/sparse/tests/test_array.py
@@ -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)
diff --git a/pandas/tests/formats/test_format.py b/pandas/tests/formats/test_format.py
index 3bbfd621d2342..e7c32a4baa4ea 100644
--- a/pandas/tests/formats/test_format.py
+++ b/pandas/tests/formats/test_format.py
@@ -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
@@ -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("
\s]", x)]
+ hdrs = [x for x in html.split(r"\n") if re.search(r" | \s]", x)]
self.assertTrue(len(hdrs) > 0)
for h in hdrs:
self.assertTrue("min-width" in h)
@@ -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'])
@@ -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)
@@ -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):
diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py
index 390d796ced006..e73d3c58aea85 100644
--- a/pandas/tests/frame/test_analytics.py
+++ b/pandas/tests/frame/test_analytics.py
@@ -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
diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py
index e55ba3e161ed9..489c85a7234b8 100644
--- a/pandas/tests/frame/test_constructors.py
+++ b/pandas/tests/frame/test_constructors.py
@@ -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'],
@@ -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, '
diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py
index 29662c5addb75..36ae5dac733a5 100644
--- a/pandas/tests/frame/test_query_eval.py
+++ b/pandas/tests/frame/test_query_eval.py
@@ -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)
diff --git a/pandas/tests/frame/test_replace.py b/pandas/tests/frame/test_replace.py
index bed0e0623ace0..3bc388da5bec8 100644
--- a/pandas/tests/frame/test_replace.py
+++ b/pandas/tests/frame/test_replace.py
@@ -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']})
@@ -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):
diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py
index 773f20532e4ff..1b373baf9b3c1 100644
--- a/pandas/tests/indexes/common.py
+++ b/pandas/tests/indexes/common.py
@@ -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)
diff --git a/pandas/tests/indexes/test_category.py b/pandas/tests/indexes/test_category.py
index c76f5ff22c534..819b88bf4c5d3 100644
--- a/pandas/tests/indexes/test_category.py
+++ b/pandas/tests/indexes/test_category.py
@@ -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)
diff --git a/pandas/tests/indexes/test_multi.py b/pandas/tests/indexes/test_multi.py
index fdc5a2eaec812..61a4ea53f06fb 100644
--- a/pandas/tests/indexes/test_multi.py
+++ b/pandas/tests/indexes/test_multi.py
@@ -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)
diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py
index a50d3d28e5a11..9ca1fd2a76817 100644
--- a/pandas/tests/indexing/test_indexing.py
+++ b/pandas/tests/indexing/test_indexing.py
@@ -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):
@@ -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):
@@ -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'])
diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py
index 24e3a0ff5f325..6de1a68464436 100644
--- a/pandas/tests/series/test_analytics.py
+++ b/pandas/tests/series/test_analytics.py
@@ -1618,7 +1618,7 @@ def test_reshape_bad_kwarg(self):
tm.assertRaisesRegexp(TypeError, msg, a.reshape, (2, 2), foo=2)
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
- msg = "reshape\(\) got an unexpected keyword argument 'foo'"
+ msg = r"reshape\(\) got an unexpected keyword argument 'foo'"
tm.assertRaisesRegexp(TypeError, msg, a.reshape, a.shape, foo=2)
def test_numpy_reshape(self):
diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py
index eaa316bfd8157..da8cf120b8ed4 100644
--- a/pandas/tests/test_base.py
+++ b/pandas/tests/test_base.py
@@ -900,7 +900,7 @@ def test_duplicated_drop_duplicates_index(self):
tm.assert_index_equal(result, idx[~expected])
with tm.assertRaisesRegexp(
- TypeError, "drop_duplicates\(\) got an unexpected "
+ TypeError, r"drop_duplicates\(\) got an unexpected "
"keyword argument"):
idx.drop_duplicates(inplace=True)
diff --git a/pandas/tests/test_generic.py b/pandas/tests/test_generic.py
index cdcd8b1bcba60..84df82db69f77 100644
--- a/pandas/tests/test_generic.py
+++ b/pandas/tests/test_generic.py
@@ -1740,8 +1740,8 @@ def test_numpy_squeeze(self):
np.squeeze, s, axis=0)
def test_transpose(self):
- msg = ("transpose\(\) got multiple values for "
- "keyword argument 'axes'")
+ msg = (r"transpose\(\) got multiple values for "
+ r"keyword argument 'axes'")
for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
tm.makeObjectSeries()]:
# calls implementation in pandas/core/base.py
@@ -1831,7 +1831,7 @@ def test_take_invalid_kwargs(self):
p4d = tm.makePanel4D()
for obj in (s, df, p, p4d):
- msg = "take\(\) got an unexpected keyword argument 'foo'"
+ msg = r"take\(\) got an unexpected keyword argument 'foo'"
tm.assertRaisesRegexp(TypeError, msg, obj.take,
indices, foo=2)
diff --git a/pandas/tests/test_internals.py b/pandas/tests/test_internals.py
index 6a97f195abba7..db1c8da4cae73 100644
--- a/pandas/tests/test_internals.py
+++ b/pandas/tests/test_internals.py
@@ -82,7 +82,7 @@ def create_block(typestr, placement, item_shape=None, num_offset=0):
values = (mat * 1e9).astype('M8[ns]')
elif typestr.startswith('M8[ns'):
# datetime with tz
- m = re.search('M8\[ns,\s*(\w+\/?\w*)\]', typestr)
+ m = re.search(r'M8\[ns,\s*(\w+\/?\w*)\]', typestr)
assert m is not None, "incompatible typestr -> {0}".format(typestr)
tz = m.groups()[0]
assert num_items == 1, "must have only 1 num items for a tz-aware"
diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py
index 516c406f8d54f..4e7ace4173227 100755
--- a/pandas/tests/test_multilevel.py
+++ b/pandas/tests/test_multilevel.py
@@ -554,7 +554,7 @@ def test_xs_level_multiple(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 = read_table(StringIO(text), sep='\s+', engine='python')
+ df = read_table(StringIO(text), sep=r'\s+', engine='python')
result = df.xs(('a', 4), level=['one', 'four'])
expected = df.xs('a').xs(4, level='four')
@@ -588,7 +588,7 @@ def test_xs_level0(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 = read_table(StringIO(text), sep='\s+', engine='python')
+ df = read_table(StringIO(text), sep=r'\s+', engine='python')
result = df.xs('a', level=0)
expected = df.xs('a')
diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py
index a197037789fd2..9cb2dd5a40ac4 100644
--- a/pandas/tests/test_panel.py
+++ b/pandas/tests/test_panel.py
@@ -496,8 +496,8 @@ def test_setitem(self):
# bad shape
p = Panel(np.random.randn(4, 3, 2))
with tm.assertRaisesRegexp(ValueError,
- "shape of value must be \(3, 2\), "
- "shape of given object was \(4, 2\)"):
+ r"shape of value must be \(3, 2\), "
+ r"shape of given object was \(4, 2\)"):
p[0] = np.random.randn(4, 2)
def test_setitem_ndarray(self):
@@ -1128,24 +1128,24 @@ def testit():
Panel(np.random.randn(3, 4, 5), lrange(4), lrange(5), lrange(5))
assertRaisesRegexp(ValueError,
- "Shape of passed values is \(3, 4, 5\), "
- "indices imply \(4, 5, 5\)",
+ r"Shape of passed values is \(3, 4, 5\), "
+ r"indices imply \(4, 5, 5\)",
testit)
def testit():
Panel(np.random.randn(3, 4, 5), lrange(5), lrange(4), lrange(5))
assertRaisesRegexp(ValueError,
- "Shape of passed values is \(3, 4, 5\), "
- "indices imply \(5, 4, 5\)",
+ r"Shape of passed values is \(3, 4, 5\), "
+ r"indices imply \(5, 4, 5\)",
testit)
def testit():
Panel(np.random.randn(3, 4, 5), lrange(5), lrange(5), lrange(4))
assertRaisesRegexp(ValueError,
- "Shape of passed values is \(3, 4, 5\), "
- "indices imply \(5, 5, 4\)",
+ r"Shape of passed values is \(3, 4, 5\), "
+ r"indices imply \(5, 5, 4\)",
testit)
def test_conform(self):
diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py
index 9a3505c3421e0..bbcd856250c51 100644
--- a/pandas/tests/test_strings.py
+++ b/pandas/tests/test_strings.py
@@ -426,7 +426,7 @@ def test_replace(self):
# flags + unicode
values = Series([b"abcd,\xc3\xa0".decode("utf-8")])
exp = Series([b"abcd, \xc3\xa0".decode("utf-8")])
- result = values.str.replace("(?<=\w),(?=\w)", ", ", flags=re.UNICODE)
+ result = values.str.replace(r"(?<=\w),(?=\w)", ", ", flags=re.UNICODE)
tm.assert_series_equal(result, exp)
# GH 13438
@@ -670,12 +670,12 @@ def check_index(index):
data = ['A1', 'B2', 'C']
index = index[:len(data)]
s = Series(data, index=index)
- result = s.str.extract('(\d)', expand=False)
+ result = s.str.extract(r'(\d)', expand=False)
exp = Series(['1', '2', NA], index=index)
tm.assert_series_equal(result, exp)
result = Series(data, index=index).str.extract(
- '(?P\D)(?P\d)?', expand=False)
+ r'(?P\D)(?P\d)?', expand=False)
e_list = [
['A', '1'],
['B', '2'],
@@ -828,12 +828,13 @@ def test_extract_optional_groups(self):
def check_index(index):
data = ['A1', 'B2', 'C']
index = index[:len(data)]
- result = Series(data, index=index).str.extract('(\d)', expand=True)
+ result = Series(data, index=index).str.extract(
+ r'(\d)', expand=True)
exp = DataFrame(['1', '2', NA], index=index)
tm.assert_frame_equal(result, exp)
result = Series(data, index=index).str.extract(
- '(?P\D)(?P\d)?', expand=True)
+ r'(?P\D)(?P\d)?', expand=True)
e_list = [
['A', '1'],
['B', '2'],
@@ -1023,7 +1024,7 @@ def test_extractall_no_matches(self):
def test_extractall_stringindex(self):
s = Series(["a1a2", "b1", "c1"], name='xxx')
- res = s.str.extractall("[ab](?P\d)")
+ res = s.str.extractall(r"[ab](?P\d)")
exp_idx = MultiIndex.from_tuples([(0, 0), (0, 1), (1, 0)],
names=[None, 'match'])
exp = DataFrame({'digit': ["1", "2", "1"]}, index=exp_idx)
@@ -1034,12 +1035,12 @@ def test_extractall_stringindex(self):
for idx in [Index(["a1a2", "b1", "c1"]),
Index(["a1a2", "b1", "c1"], name='xxx')]:
- res = idx.str.extractall("[ab](?P\d)")
+ res = idx.str.extractall(r"[ab](?P\d)")
tm.assert_frame_equal(res, exp)
s = Series(["a1a2", "b1", "c1"], name='s_name',
index=Index(["XX", "yy", "zz"], name='idx_name'))
- res = s.str.extractall("[ab](?P\d)")
+ res = s.str.extractall(r"[ab](?P\d)")
exp_idx = MultiIndex.from_tuples([("XX", 0), ("XX", 1), ("yy", 0)],
names=["idx_name", 'match'])
exp = DataFrame({'digit': ["1", "2", "1"]}, index=exp_idx)
diff --git a/pandas/tests/test_testing.py b/pandas/tests/test_testing.py
index c242213ee226f..7a217ed9dbd86 100644
--- a/pandas/tests/test_testing.py
+++ b/pandas/tests/test_testing.py
@@ -319,10 +319,10 @@ def test_numpy_array_equal_copy_flag(self):
a = np.array([1, 2, 3])
b = a.copy()
c = a.view()
- expected = 'array\(\[1, 2, 3\]\) is not array\(\[1, 2, 3\]\)'
+ expected = r'array\(\[1, 2, 3\]\) is not array\(\[1, 2, 3\]\)'
with assertRaisesRegexp(AssertionError, expected):
assert_numpy_array_equal(a, b, check_same='same')
- expected = 'array\(\[1, 2, 3\]\) is array\(\[1, 2, 3\]\)'
+ expected = r'array\(\[1, 2, 3\]\) is array\(\[1, 2, 3\]\)'
with assertRaisesRegexp(AssertionError, expected):
assert_numpy_array_equal(a, c, check_same='copy')
diff --git a/pandas/tests/test_util.py b/pandas/tests/test_util.py
index f5828dab21e37..ee33e24c7f6c4 100644
--- a/pandas/tests/test_util.py
+++ b/pandas/tests/test_util.py
@@ -97,8 +97,8 @@ def test_bad_arg_length_max_value_single(self):
min_fname_arg_count = 0
max_length = len(compat_args) + min_fname_arg_count
actual_length = len(args) + min_fname_arg_count
- msg = ("{fname}\(\) takes at most {max_length} "
- "argument \({actual_length} given\)"
+ msg = (r"{fname}\(\) takes at most {max_length} "
+ r"argument \({actual_length} given\)"
.format(fname=self.fname, max_length=max_length,
actual_length=actual_length))
@@ -114,8 +114,8 @@ def test_bad_arg_length_max_value_multiple(self):
min_fname_arg_count = 2
max_length = len(compat_args) + min_fname_arg_count
actual_length = len(args) + min_fname_arg_count
- msg = ("{fname}\(\) takes at most {max_length} "
- "arguments \({actual_length} given\)"
+ msg = (r"{fname}\(\) takes at most {max_length} "
+ r"arguments \({actual_length} given\)"
.format(fname=self.fname, max_length=max_length,
actual_length=actual_length))
@@ -127,7 +127,7 @@ def test_bad_arg_length_max_value_multiple(self):
def test_not_all_defaults(self):
bad_arg = 'foo'
msg = ("the '{arg}' parameter is not supported "
- "in the pandas implementation of {func}\(\)".
+ r"in the pandas implementation of {func}\(\)".
format(arg=bad_arg, func=self.fname))
compat_args = OrderedDict()
@@ -163,8 +163,8 @@ def test_bad_kwarg(self):
compat_args[goodarg] = 'foo'
compat_args[badarg + 'o'] = 'bar'
kwargs = {goodarg: 'foo', badarg: 'bar'}
- msg = ("{fname}\(\) got an unexpected "
- "keyword argument '{arg}'".format(
+ msg = (r"{fname}\(\) got an unexpected "
+ r"keyword argument '{arg}'".format(
fname=self.fname, arg=badarg))
with tm.assertRaisesRegexp(TypeError, msg):
@@ -172,8 +172,8 @@ def test_bad_kwarg(self):
def test_not_all_none(self):
bad_arg = 'foo'
- msg = ("the '{arg}' parameter is not supported "
- "in the pandas implementation of {func}\(\)".
+ msg = (r"the '{arg}' parameter is not supported "
+ r"in the pandas implementation of {func}\(\)".
format(arg=bad_arg, func=self.fname))
compat_args = OrderedDict()
@@ -212,8 +212,8 @@ def test_invalid_total_length_max_length_one(self):
min_fname_arg_count = 0
max_length = len(compat_args) + min_fname_arg_count
actual_length = len(kwargs) + len(args) + min_fname_arg_count
- msg = ("{fname}\(\) takes at most {max_length} "
- "argument \({actual_length} given\)"
+ msg = (r"{fname}\(\) takes at most {max_length} "
+ r"argument \({actual_length} given\)"
.format(fname=self.fname, max_length=max_length,
actual_length=actual_length))
@@ -230,8 +230,8 @@ def test_invalid_total_length_max_length_multiple(self):
min_fname_arg_count = 2
max_length = len(compat_args) + min_fname_arg_count
actual_length = len(kwargs) + len(args) + min_fname_arg_count
- msg = ("{fname}\(\) takes at most {max_length} "
- "arguments \({actual_length} given\)"
+ msg = (r"{fname}\(\) takes at most {max_length} "
+ r"arguments \({actual_length} given\)"
.format(fname=self.fname, max_length=max_length,
actual_length=actual_length))
@@ -248,8 +248,8 @@ def test_no_args_with_kwargs(self):
compat_args['foo'] = -5
compat_args[bad_arg] = 1
- msg = ("the '{arg}' parameter is not supported "
- "in the pandas implementation of {func}\(\)".
+ msg = (r"the '{arg}' parameter is not supported "
+ r"in the pandas implementation of {func}\(\)".
format(arg=bad_arg, func=self.fname))
args = ()
@@ -275,8 +275,8 @@ def test_duplicate_argument(self):
kwargs = {'foo': None, 'bar': None}
args = (None,) # duplicate value for 'foo'
- msg = ("{fname}\(\) got multiple values for keyword "
- "argument '{arg}'".format(fname=self.fname, arg='foo'))
+ msg = (r"{fname}\(\) got multiple values for keyword "
+ r"argument '{arg}'".format(fname=self.fname, arg='foo'))
with tm.assertRaisesRegexp(TypeError, msg):
validate_args_and_kwargs(self.fname, args, kwargs,
diff --git a/pandas/tseries/tests/test_base.py b/pandas/tseries/tests/test_base.py
index a6d58fa3e7ef3..bca50237081e1 100644
--- a/pandas/tseries/tests/test_base.py
+++ b/pandas/tseries/tests/test_base.py
@@ -807,7 +807,7 @@ def test_take_invalid_kwargs(self):
idx = pd.date_range('2011-01-01', '2011-01-31', freq='D', name='idx')
indices = [1, 6, 5, 9, 10, 13, 15, 3]
- 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)
@@ -1639,7 +1639,7 @@ def test_take_invalid_kwargs(self):
idx = pd.timedelta_range('1 day', '31 day', freq='D', name='idx')
indices = [1, 6, 5, 9, 10, 13, 15, 3]
- 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)
diff --git a/pandas/tseries/tests/test_period.py b/pandas/tseries/tests/test_period.py
index e314081eac373..9bdf420ca6084 100644
--- a/pandas/tseries/tests/test_period.py
+++ b/pandas/tseries/tests/test_period.py
@@ -3730,11 +3730,11 @@ def test_add_raises(self):
# GH 4731
dt1 = Period(freq='D', year=2008, month=1, day=1)
dt2 = Period(freq='D', year=2008, month=1, day=2)
- msg = "unsupported operand type\(s\)"
+ msg = r"unsupported operand type\(s\)"
with tm.assertRaisesRegexp(TypeError, msg):
dt1 + "str"
- msg = "unsupported operand type\(s\)"
+ msg = r"unsupported operand type\(s\)"
with tm.assertRaisesRegexp(TypeError, msg):
"str" + dt1
@@ -3748,7 +3748,7 @@ def test_sub(self):
self.assertEqual(dt1 - dt2, -14)
self.assertEqual(dt2 - dt1, 14)
- msg = "Input has different freq=M from Period\(freq=D\)"
+ msg = r"Input has different freq=M from Period\(freq=D\)"
with tm.assertRaisesRegexp(period.IncompatibleFrequency, msg):
dt1 - pd.Period('2011-02', freq='M')
@@ -4112,7 +4112,7 @@ def test_period_ops_offset(self):
exp = pd.Period('2011-03-30', freq='D')
self.assertEqual(result, exp)
- msg = "Input cannot be converted to Period\(freq=D\)"
+ msg = r"Input cannot be converted to Period\(freq=D\)"
with tm.assertRaisesRegexp(period.IncompatibleFrequency, msg):
p + offsets.Hour(2)
@@ -4161,7 +4161,7 @@ def test_pi_ops_errors(self):
'2011-04'], freq='M', name='idx')
s = pd.Series(idx)
- msg = "unsupported operand type\(s\)"
+ msg = r"unsupported operand type\(s\)"
for obj in [idx, s]:
for ng in ["str", 1.5]:
@@ -4265,8 +4265,8 @@ def test_pi_offset_errors(self):
# Series op is applied per Period instance, thus error is raised
# from Period
- msg_idx = "Input has different freq from PeriodIndex\(freq=D\)"
- msg_s = "Input cannot be converted to Period\(freq=D\)"
+ msg_idx = r"Input has different freq from PeriodIndex\(freq=D\)"
+ msg_s = r"Input cannot be converted to Period\(freq=D\)"
for obj, msg in [(idx, msg_idx), (s, msg_s)]:
with tm.assertRaisesRegexp(period.IncompatibleFrequency, msg):
obj + offsets.Hour(2)
diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py
index aa8a5d10cd9d3..67b203d011d1a 100644
--- a/pandas/tseries/tests/test_timeseries.py
+++ b/pandas/tseries/tests/test_timeseries.py
@@ -5160,11 +5160,13 @@ def test_partial_slice_doesnt_require_monotonicity(self):
timestamp = pd.Timestamp('2014-01-10')
assert_series_equal(nonmonotonic['2014-01-10':], expected)
- self.assertRaisesRegexp(KeyError, "Timestamp\('2014-01-10 00:00:00'\)",
+ self.assertRaisesRegexp(KeyError,
+ r"Timestamp\('2014-01-10 00:00:00'\)",
lambda: nonmonotonic[timestamp:])
assert_series_equal(nonmonotonic.ix['2014-01-10':], expected)
- self.assertRaisesRegexp(KeyError, "Timestamp\('2014-01-10 00:00:00'\)",
+ self.assertRaisesRegexp(KeyError,
+ r"Timestamp\('2014-01-10 00:00:00'\)",
lambda: nonmonotonic.ix[timestamp:])
@@ -5284,7 +5286,7 @@ def test_to_datetime_with_non_exact(self):
s = Series(['19MAY11', 'foobar19MAY11', '19MAY11:00:00:00',
'19MAY11 00:00:00Z'])
result = to_datetime(s, format='%d%b%y', exact=False)
- expected = to_datetime(s.str.extract('(\d+\w+\d+)', expand=False),
+ expected = to_datetime(s.str.extract(r'(\d+\w+\d+)', expand=False),
format='%d%b%y')
assert_series_equal(result, expected)
|