Skip to content

Skipif no lzma ne #18820

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

Merged
merged 2 commits into from
Dec 19, 2017
Merged
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
17 changes: 7 additions & 10 deletions pandas/tests/computation/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def _is_py3_complex_incompat(result, expected):
_good_arith_ops = com.difference(_arith_ops_syms, _special_case_arith_ops_syms)


@td.skip_if_no_ne
class TestEvalNumexprPandas(object):

@classmethod
def setup_class(cls):
tm.skip_if_no_ne()
import numexpr as ne
cls.ne = ne
cls.engine = 'numexpr'
Expand Down Expand Up @@ -374,7 +374,6 @@ def check_single_invert_op(self, lhs, cmp1, rhs):
tm.assert_almost_equal(expected, result)

for engine in self.current_engines:
tm.skip_if_no_ne(engine)
tm.assert_almost_equal(result, pd.eval('~elb', engine=engine,
parser=self.parser))

Expand All @@ -400,7 +399,6 @@ def check_compound_invert_op(self, lhs, cmp1, rhs):

# make sure the other engines work the same as this one
for engine in self.current_engines:
tm.skip_if_no_ne(engine)
ev = pd.eval(ex, engine=self.engine, parser=self.parser)
tm.assert_almost_equal(ev, result)

Expand Down Expand Up @@ -731,12 +729,12 @@ def test_disallow_python_keywords(self):
df.query('lambda == 0')


@td.skip_if_no_ne
class TestEvalNumexprPython(TestEvalNumexprPandas):

@classmethod
def setup_class(cls):
super(TestEvalNumexprPython, cls).setup_class()
tm.skip_if_no_ne()
import numexpr as ne
cls.ne = ne
cls.engine = 'numexpr'
Expand Down Expand Up @@ -1078,11 +1076,11 @@ def test_performance_warning_for_poor_alignment(self, engine, parser):
# ------------------------------------
# Slightly more complex ops

@td.skip_if_no_ne
class TestOperationsNumExprPandas(object):

@classmethod
def setup_class(cls):
tm.skip_if_no_ne()
cls.engine = 'numexpr'
cls.parser = 'pandas'
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
Expand Down Expand Up @@ -1528,14 +1526,14 @@ def test_simple_in_ops(self):
parser=self.parser)


@td.skip_if_no_ne
class TestOperationsNumExprPython(TestOperationsNumExprPandas):

@classmethod
def setup_class(cls):
super(TestOperationsNumExprPython, cls).setup_class()
cls.engine = 'numexpr'
cls.parser = 'python'
tm.skip_if_no_ne(cls.engine)
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
cls.arith_ops = filter(lambda x: x not in ('in', 'not in'),
cls.arith_ops)
Expand Down Expand Up @@ -1623,11 +1621,11 @@ def setup_class(cls):
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms


@td.skip_if_no_ne
class TestMathPythonPython(object):

@classmethod
def setup_class(cls):
tm.skip_if_no_ne()
cls.engine = 'python'
cls.parser = 'pandas'
cls.unary_fns = _unary_math_ops
Expand Down Expand Up @@ -1782,15 +1780,15 @@ def test_no_new_globals(self, engine, parser):
assert gbls == gbls2


@td.skip_if_no_ne
def test_invalid_engine():
tm.skip_if_no_ne()
tm.assert_raises_regex(KeyError, 'Invalid engine \'asdf\' passed',
pd.eval, 'x + y', local_dict={'x': 1, 'y': 2},
engine='asdf')


@td.skip_if_no_ne
def test_invalid_parser():
tm.skip_if_no_ne()
tm.assert_raises_regex(KeyError, 'Invalid parser \'asdf\' passed',
pd.eval, 'x + y', local_dict={'x': 1, 'y': 2},
parser='asdf')
Expand All @@ -1803,7 +1801,6 @@ def test_invalid_parser():
@pytest.mark.parametrize('engine', _parsers)
@pytest.mark.parametrize('parser', _parsers)
def test_disallowed_nodes(engine, parser):
tm.skip_if_no_ne(engine)
VisitorClass = _parsers[parser]
uns_ops = VisitorClass.unsupported_nodes
inst = VisitorClass('x + 1', engine, parser)
Expand Down
76 changes: 11 additions & 65 deletions pandas/tests/frame/test_query_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
makeCustomDataframe as mkdf)

import pandas.util.testing as tm
import pandas.util._test_decorators as td
from pandas.core.computation.check import _NUMEXPR_INSTALLED

from pandas.tests.frame.common import TestData


PARSERS = 'python', 'pandas'
ENGINES = 'python', 'numexpr'
ENGINES = 'python', pytest.param('numexpr', marks=td.skip_if_no_ne)


@pytest.fixture(params=PARSERS, ids=lambda x: x)
Expand All @@ -41,13 +42,6 @@ def skip_if_no_pandas_parser(parser):
pytest.skip("cannot evaluate with parser {0!r}".format(parser))


def skip_if_no_ne(engine='numexpr'):
if engine == 'numexpr':
if not _NUMEXPR_INSTALLED:
pytest.skip("cannot query engine numexpr when numexpr not "
"installed")


class TestCompat(object):

def setup_method(self, method):
Expand Down Expand Up @@ -175,7 +169,6 @@ def test_eval_resolvers_as_list(self):
class TestDataFrameQueryWithMultiIndex(object):

def test_query_with_named_multiindex(self, parser, engine):
tm.skip_if_no_ne(engine)
skip_if_no_pandas_parser(parser)
a = np.random.choice(['red', 'green'], size=10)
b = np.random.choice(['eggs', 'ham'], size=10)
Expand Down Expand Up @@ -225,7 +218,6 @@ def test_query_with_named_multiindex(self, parser, engine):
assert_frame_equal(res2, exp)

def test_query_with_unnamed_multiindex(self, parser, engine):
tm.skip_if_no_ne(engine)
skip_if_no_pandas_parser(parser)
a = np.random.choice(['red', 'green'], size=10)
b = np.random.choice(['eggs', 'ham'], size=10)
Expand Down Expand Up @@ -316,7 +308,6 @@ def test_query_with_unnamed_multiindex(self, parser, engine):
assert_frame_equal(res2, exp)

def test_query_with_partially_named_multiindex(self, parser, engine):
tm.skip_if_no_ne(engine)
skip_if_no_pandas_parser(parser)
a = np.random.choice(['red', 'green'], size=10)
b = np.arange(10)
Expand Down Expand Up @@ -370,27 +361,25 @@ def to_series(mi, level):
raise AssertionError("object must be a Series or Index")

def test_raise_on_panel_with_multiindex(self, parser, engine):
tm.skip_if_no_ne()
Copy link
Member Author

@WillAyd WillAyd Dec 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor bug before where this wasn't passing engine as an argument to the skip_if function, so this test was always being skipped on systems lacking numexpr, even for non-numexpr engines

p = tm.makePanel(7)
p.items = tm.makeCustomIndex(len(p.items), nlevels=2)
with pytest.raises(NotImplementedError):
pd.eval('p + 1', parser=parser, engine=engine)

def test_raise_on_panel4d_with_multiindex(self, parser, engine):
tm.skip_if_no_ne()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same bug as above

p4d = tm.makePanel4D(7)
p4d.items = tm.makeCustomIndex(len(p4d.items), nlevels=2)
with pytest.raises(NotImplementedError):
pd.eval('p4d + 1', parser=parser, engine=engine)


@td.skip_if_no_ne
class TestDataFrameQueryNumExprPandas(object):

@classmethod
def setup_class(cls):
cls.engine = 'numexpr'
cls.parser = 'pandas'
tm.skip_if_no_ne(cls.engine)

@classmethod
def teardown_class(cls):
Expand Down Expand Up @@ -714,14 +703,14 @@ def test_inf(self):
assert_frame_equal(result, expected)


@td.skip_if_no_ne
class TestDataFrameQueryNumExprPython(TestDataFrameQueryNumExprPandas):

@classmethod
def setup_class(cls):
super(TestDataFrameQueryNumExprPython, cls).setup_class()
cls.engine = 'numexpr'
cls.parser = 'python'
tm.skip_if_no_ne(cls.engine)
cls.frame = TestData().frame

def test_date_query_no_attribute_access(self):
Expand Down Expand Up @@ -859,7 +848,6 @@ def test_query_builtin(self):
class TestDataFrameQueryStrings(object):

def test_str_query_method(self, parser, engine):
tm.skip_if_no_ne(engine)
df = DataFrame(randn(10, 1), columns=['b'])
df['strings'] = Series(list('aabbccddee'))
expect = df[df.strings == 'a']
Expand Down Expand Up @@ -896,7 +884,6 @@ def test_str_query_method(self, parser, engine):
assert_frame_equal(res, df[~df.strings.isin(['a'])])

def test_str_list_query_method(self, parser, engine):
tm.skip_if_no_ne(engine)
df = DataFrame(randn(10, 1), columns=['b'])
df['strings'] = Series(list('aabbccddee'))
expect = df[df.strings.isin(['a', 'b'])]
Expand Down Expand Up @@ -935,7 +922,6 @@ def test_str_list_query_method(self, parser, engine):
assert_frame_equal(res, expect)

def test_query_with_string_columns(self, parser, engine):
tm.skip_if_no_ne(engine)
df = DataFrame({'a': list('aaaabbbbcccc'),
'b': list('aabbccddeeff'),
'c': np.random.randint(5, size=12),
Expand All @@ -956,7 +942,6 @@ def test_query_with_string_columns(self, parser, engine):
df.query('a in b and c < d', parser=parser, engine=engine)

def test_object_array_eq_ne(self, parser, engine):
tm.skip_if_no_ne(engine)
df = DataFrame({'a': list('aaaabbbbcccc'),
'b': list('aabbccddeeff'),
'c': np.random.randint(5, size=12),
Expand All @@ -970,7 +955,6 @@ def test_object_array_eq_ne(self, parser, engine):
assert_frame_equal(res, exp)

def test_query_with_nested_strings(self, parser, engine):
tm.skip_if_no_ne(engine)
skip_if_no_pandas_parser(parser)
raw = """id event timestamp
1 "page 1 load" 1/1/2014 0:00:01
Expand All @@ -995,15 +979,13 @@ def test_query_with_nested_strings(self, parser, engine):

def test_query_with_nested_special_character(self, parser, engine):
skip_if_no_pandas_parser(parser)
tm.skip_if_no_ne(engine)
df = DataFrame({'a': ['a', 'b', 'test & test'],
'b': [1, 2, 3]})
res = df.query('a == "test & test"', parser=parser, engine=engine)
expec = df[df.a == 'test & test']
assert_frame_equal(res, expec)

def test_query_lex_compare_strings(self, parser, engine):
tm.skip_if_no_ne(engine=engine)
import operator as opr

a = Series(np.random.choice(list('abcde'), 20))
Expand All @@ -1018,7 +1000,6 @@ def test_query_lex_compare_strings(self, parser, engine):
assert_frame_equal(res, expected)

def test_query_single_element_booleans(self, parser, engine):
tm.skip_if_no_ne(engine)
columns = 'bid', 'bidsize', 'ask', 'asksize'
data = np.random.randint(2, size=(1, len(columns))).astype(bool)
df = DataFrame(data, columns=columns)
Expand All @@ -1027,7 +1008,6 @@ def test_query_single_element_booleans(self, parser, engine):
assert_frame_equal(res, expected)

def test_query_string_scalar_variable(self, parser, engine):
tm.skip_if_no_ne(engine)
skip_if_no_pandas_parser(parser)
df = pd.DataFrame({'Symbol': ['BUD US', 'BUD US', 'IBM US', 'IBM US'],
'Price': [109.70, 109.72, 183.30, 183.35]})
Expand All @@ -1037,63 +1017,29 @@ def test_query_string_scalar_variable(self, parser, engine):
assert_frame_equal(e, r)


class TestDataFrameEvalNumExprPandas(object):

@classmethod
def setup_class(cls):
cls.engine = 'numexpr'
cls.parser = 'pandas'
tm.skip_if_no_ne()
class TestDataFrameEvalWithFrame(object):

def setup_method(self, method):
self.frame = DataFrame(randn(10, 3), columns=list('abc'))

def teardown_method(self, method):
del self.frame

def test_simple_expr(self):
res = self.frame.eval('a + b', engine=self.engine, parser=self.parser)
def test_simple_expr(self, parser, engine):
res = self.frame.eval('a + b', engine=engine, parser=parser)
expect = self.frame.a + self.frame.b
assert_series_equal(res, expect)

def test_bool_arith_expr(self):
res = self.frame.eval('a[a < 1] + b', engine=self.engine,
parser=self.parser)
def test_bool_arith_expr(self, parser, engine):
res = self.frame.eval('a[a < 1] + b', engine=engine, parser=parser)
expect = self.frame.a[self.frame.a < 1] + self.frame.b
assert_series_equal(res, expect)

def test_invalid_type_for_operator_raises(self):
def test_invalid_type_for_operator_raises(self, parser, engine):
df = DataFrame({'a': [1, 2], 'b': ['c', 'd']})
ops = '+', '-', '*', '/'
for op in ops:
with tm.assert_raises_regex(TypeError,
"unsupported operand type\(s\) "
"for .+: '.+' and '.+'"):
df.eval('a {0} b'.format(op), engine=self.engine,
parser=self.parser)


class TestDataFrameEvalNumExprPython(TestDataFrameEvalNumExprPandas):

@classmethod
def setup_class(cls):
super(TestDataFrameEvalNumExprPython, cls).setup_class()
cls.engine = 'numexpr'
cls.parser = 'python'
tm.skip_if_no_ne(cls.engine)


class TestDataFrameEvalPythonPandas(TestDataFrameEvalNumExprPandas):

@classmethod
def setup_class(cls):
super(TestDataFrameEvalPythonPandas, cls).setup_class()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to the super setup_class method inadvertently skipped this class of tests on systems that did not have numexpr even though that isn't required for these. Fixed with commit

cls.engine = 'python'
cls.parser = 'pandas'


class TestDataFrameEvalPythonPython(TestDataFrameEvalNumExprPython):

@classmethod
def setup_class(cls):
cls.engine = cls.parser = 'python'
df.eval('a {0} b'.format(op), engine=engine, parser=parser)
3 changes: 2 additions & 1 deletion pandas/tests/frame/test_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ensure_clean,
makeCustomDataframe as mkdf)
import pandas.util.testing as tm
import pandas.util._test_decorators as td

from pandas.tests.frame.common import TestData

Expand Down Expand Up @@ -965,10 +966,10 @@ def test_to_csv_compression_bz2(self):
for col in df.columns:
assert col in text

@td.skip_if_no_lzma
def test_to_csv_compression_xz(self):
# GH11852
# use the compression kw in to_csv
tm._skip_if_no_lzma()
df = DataFrame([[0.123456, 0.234567, 0.567567],
[12.32112, 123123.2, 321321.2]],
index=['A', 'B'], columns=['X', 'Y', 'Z'])
Expand Down
Loading