Skip to content

Commit 520fafe

Browse files
Fix Imports and Added Test
1 parent 91d4d00 commit 520fafe

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

pandas/core/computation/ops.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from pandas.core.dtypes.common import (
2121
is_list_like,
22+
is_numeric_dtype,
2223
is_scalar,
2324
)
2425

@@ -508,12 +509,6 @@ def _disallow_scalar_only_bool_ops(self) -> None:
508509
raise NotImplementedError("cannot evaluate scalar only bool ops")
509510

510511

511-
def isnumeric(dtype) -> bool:
512-
return getattr(dtype, "_is_numeric", False) or issubclass(
513-
np.dtype(dtype).type, np.number
514-
)
515-
516-
517512
class Div(BinOp):
518513
"""
519514
Div operator to special case casting.
@@ -527,7 +522,9 @@ class Div(BinOp):
527522
def __init__(self, lhs, rhs) -> None:
528523
super().__init__("/", lhs, rhs)
529524

530-
if not isnumeric(lhs.return_type) or not isnumeric(rhs.return_type):
525+
if not is_numeric_dtype(lhs.return_type) or not is_numeric_dtype(
526+
rhs.return_type
527+
):
531528
raise TypeError(
532529
f"unsupported operand type(s) for {self.op}: "
533530
f"'{lhs.return_type}' and '{rhs.return_type}'"

pandas/tests/extension/test_datetime.py

-7
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ def cmp(a, b):
8888
return cmp
8989

9090

91-
@pytest.fixture
92-
def isnumeric(dtype):
93-
return getattr(dtype, "is_numeric", False) or issubclass(
94-
np.dtype(dtype).type, np.number
95-
)
96-
97-
9891
# ----------------------------------------------------------------------------
9992
class TestDatetimeArray(base.ExtensionTests):
10093
def _get_expected_exception(self, op_name, obj, other):

pandas/tests/frame/test_query_eval.py

+7
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ def test_eval_simple(self, engine, parser):
202202
expected = df["a"]
203203
tm.assert_series_equal(expected, res)
204204

205+
def test_extension_array_eval():
206+
# GH#58748
207+
df = DataFrame({"a": pd.array([1, 2, 3]), "b": pd.array([4, 5, 6])})
208+
result = df.eval("a / b")
209+
expected = Series([0.25, 0.40, 0.50])
210+
tm.assert_series_equal(result, expected)
211+
205212

206213
class TestDataFrameQueryWithMultiIndex:
207214
def test_query_with_named_multiindex(self, parser, engine):

0 commit comments

Comments
 (0)