Skip to content

Commit

Permalink
Fix Imports and Added Test
Browse files Browse the repository at this point in the history
  • Loading branch information
SiddheshBangar committed May 22, 2024
1 parent 91d4d00 commit 520fafe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
11 changes: 4 additions & 7 deletions pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from pandas.core.dtypes.common import (
is_list_like,
is_numeric_dtype,
is_scalar,
)

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


def isnumeric(dtype) -> bool:
return getattr(dtype, "_is_numeric", False) or issubclass(
np.dtype(dtype).type, np.number
)


class Div(BinOp):
"""
Div operator to special case casting.
Expand All @@ -527,7 +522,9 @@ class Div(BinOp):
def __init__(self, lhs, rhs) -> None:
super().__init__("/", lhs, rhs)

if not isnumeric(lhs.return_type) or not isnumeric(rhs.return_type):
if not is_numeric_dtype(lhs.return_type) or not is_numeric_dtype(
rhs.return_type
):
raise TypeError(
f"unsupported operand type(s) for {self.op}: "
f"'{lhs.return_type}' and '{rhs.return_type}'"
Expand Down
7 changes: 0 additions & 7 deletions pandas/tests/extension/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ def cmp(a, b):
return cmp


@pytest.fixture
def isnumeric(dtype):
return getattr(dtype, "is_numeric", False) or issubclass(
np.dtype(dtype).type, np.number
)


# ----------------------------------------------------------------------------
class TestDatetimeArray(base.ExtensionTests):
def _get_expected_exception(self, op_name, obj, other):
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/test_query_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ def test_eval_simple(self, engine, parser):
expected = df["a"]
tm.assert_series_equal(expected, res)

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


class TestDataFrameQueryWithMultiIndex:
def test_query_with_named_multiindex(self, parser, engine):
Expand Down

0 comments on commit 520fafe

Please sign in to comment.