29
29
import pandas .core .computation .expr as expr
30
30
import pandas .util .testing as tm
31
31
from pandas .util .testing import (assert_frame_equal , randbool ,
32
- assertRaisesRegexp , assert_numpy_array_equal ,
33
- assert_produces_warning , assert_series_equal ,
34
- slow )
32
+ assert_numpy_array_equal , assert_series_equal ,
33
+ assert_produces_warning , slow )
35
34
from pandas .compat import PY3 , reduce
36
35
37
36
_series_frame_incompatible = _bool_ops_syms
@@ -1677,17 +1676,17 @@ def test_result_types2(self):
1677
1676
1678
1677
def test_undefined_func (self ):
1679
1678
df = DataFrame ({'a' : np .random .randn (10 )})
1680
- with tm .assertRaisesRegexp ( ValueError ,
1681
- "\" mysin\" is not a supported function" ):
1679
+ with tm .assert_raises_regex (
1680
+ ValueError , "\" mysin\" is not a supported function" ):
1682
1681
df .eval ("mysin(a)" ,
1683
1682
engine = self .engine ,
1684
1683
parser = self .parser )
1685
1684
1686
1685
def test_keyword_arg (self ):
1687
1686
df = DataFrame ({'a' : np .random .randn (10 )})
1688
- with tm .assertRaisesRegexp (TypeError ,
1689
- "Function \" sin\" does not support "
1690
- "keyword arguments" ):
1687
+ with tm .assert_raises_regex (TypeError ,
1688
+ "Function \" sin\" does not support "
1689
+ "keyword arguments" ):
1691
1690
df .eval ("sin(x=a)" ,
1692
1691
engine = self .engine ,
1693
1692
parser = self .parser )
@@ -1748,16 +1747,16 @@ def test_no_new_globals(self, engine, parser):
1748
1747
1749
1748
def test_invalid_engine ():
1750
1749
tm .skip_if_no_ne ()
1751
- assertRaisesRegexp (KeyError , 'Invalid engine \' asdf\' passed' ,
1752
- pd .eval , 'x + y' , local_dict = {'x' : 1 , 'y' : 2 },
1753
- engine = 'asdf' )
1750
+ tm . assert_raises_regex (KeyError , 'Invalid engine \' asdf\' passed' ,
1751
+ pd .eval , 'x + y' , local_dict = {'x' : 1 , 'y' : 2 },
1752
+ engine = 'asdf' )
1754
1753
1755
1754
1756
1755
def test_invalid_parser ():
1757
1756
tm .skip_if_no_ne ()
1758
- assertRaisesRegexp (KeyError , 'Invalid parser \' asdf\' passed' ,
1759
- pd .eval , 'x + y' , local_dict = {'x' : 1 , 'y' : 2 },
1760
- parser = 'asdf' )
1757
+ tm . assert_raises_regex (KeyError , 'Invalid parser \' asdf\' passed' ,
1758
+ pd .eval , 'x + y' , local_dict = {'x' : 1 , 'y' : 2 },
1759
+ parser = 'asdf' )
1761
1760
1762
1761
1763
1762
_parsers = {'python' : PythonExprVisitor , 'pytables' : pytables .ExprVisitor ,
@@ -1795,18 +1794,20 @@ def test_invalid_local_variable_reference(engine, parser):
1795
1794
1796
1795
for _expr in exprs :
1797
1796
if parser != 'pandas' :
1798
- with tm .assertRaisesRegexp (SyntaxError , "The '@' prefix is only" ):
1797
+ with tm .assert_raises_regex (SyntaxError ,
1798
+ "The '@' prefix is only" ):
1799
1799
pd .eval (_expr , engine = engine , parser = parser )
1800
1800
else :
1801
- with tm .assertRaisesRegexp (SyntaxError , "The '@' prefix is not" ):
1801
+ with tm .assert_raises_regex (SyntaxError ,
1802
+ "The '@' prefix is not" ):
1802
1803
pd .eval (_expr , engine = engine , parser = parser )
1803
1804
1804
1805
1805
1806
def test_numexpr_builtin_raises (engine , parser ):
1806
1807
sin , dotted_line = 1 , 2
1807
1808
if engine == 'numexpr' :
1808
- with tm .assertRaisesRegexp (NumExprClobberingError ,
1809
- 'Variables in expression .+' ):
1809
+ with tm .assert_raises_regex (NumExprClobberingError ,
1810
+ 'Variables in expression .+' ):
1810
1811
pd .eval ('sin + dotted_line' , engine = engine , parser = parser )
1811
1812
else :
1812
1813
res = pd .eval ('sin + dotted_line' , engine = engine , parser = parser )
@@ -1815,20 +1816,21 @@ def test_numexpr_builtin_raises(engine, parser):
1815
1816
1816
1817
def test_bad_resolver_raises (engine , parser ):
1817
1818
cannot_resolve = 42 , 3.0
1818
- with tm .assertRaisesRegexp (TypeError , 'Resolver of type .+' ):
1819
+ with tm .assert_raises_regex (TypeError , 'Resolver of type .+' ):
1819
1820
pd .eval ('1 + 2' , resolvers = cannot_resolve , engine = engine ,
1820
1821
parser = parser )
1821
1822
1822
1823
1823
1824
def test_empty_string_raises (engine , parser ):
1824
1825
# GH 13139
1825
- with tm .assertRaisesRegexp (ValueError , 'expr cannot be an empty string' ):
1826
+ with tm .assert_raises_regex (ValueError ,
1827
+ 'expr cannot be an empty string' ):
1826
1828
pd .eval ('' , engine = engine , parser = parser )
1827
1829
1828
1830
1829
1831
def test_more_than_one_expression_raises (engine , parser ):
1830
- with tm .assertRaisesRegexp (SyntaxError ,
1831
- 'only a single expression is allowed' ):
1832
+ with tm .assert_raises_regex (SyntaxError ,
1833
+ 'only a single expression is allowed' ):
1832
1834
pd .eval ('1 + 1; 2 + 2' , engine = engine , parser = parser )
1833
1835
1834
1836
0 commit comments