Skip to content

Commit a57986b

Browse files
committed
raise error when function not supported by older version of numpy
1 parent 80da35e commit a57986b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pandas/core/computation/ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ def __unicode__(self):
542542
class FuncNode(object):
543543

544544
def __init__(self, name):
545-
if name not in _mathops:
545+
if name not in _mathops or not hasattr(np, name) :
546546
raise ValueError(
547547
"\"{0}\" is not a supported function".format(name))
548548
self.name = name

pandas/tests/computation/test_eval.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1627,10 +1627,21 @@ def test_unary_functions(self):
16271627
a = df.a
16281628
for fn in self.unary_fns:
16291629
expr = "{0}(a)".format(fn)
1630-
got = self.eval(expr)
16311630
with np.errstate(all='ignore'):
1632-
expect = getattr(np, fn)(a)
1633-
tm.assert_series_equal(got, expect, check_names=False)
1631+
if hasattr(np, fn):
1632+
got = self.eval(expr)
1633+
expect = getattr(np, fn)(a)
1634+
tm.assert_series_equal(got, expect, check_names=False)
1635+
1636+
def test_all_unary_functions_not_supported_in_numpy_112(self):
1637+
df = DataFrame({'a': np.random.randn(10)})
1638+
for fn in self.unary_fns:
1639+
expr = "{0}(a)".format(fn)
1640+
with np.errstate(all='ignore'):
1641+
if not hasattr(np, fn):
1642+
msg = f"\"{fn}\" is not a supported function"
1643+
with pytest.raises(ValueError, match=msg):
1644+
self.eval(expr)
16341645

16351646
def test_binary_functions(self):
16361647
df = DataFrame({'a': np.random.randn(10),

0 commit comments

Comments
 (0)