8000 REF: IntervalArray comparisons by jbrockmendel · Pull Request #37124 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

REF: IntervalArray comparisons #37124

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 15 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
handle NA per suggestion
  • Loading branch information
jbrockmendel committed Oct 24, 2020
commit ff640ea8f8ca52059ed85aac1e71ad0955fd97c1
16 changes: 9 additions & 7 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
IntervalMixin,
intervals_to_interval_bounds,
)
from pandas._libs.missing import NA
from pandas._typing import ArrayLike, Dtype
from pandas.compat.numpy import function as nv
from pandas.util._decorators import Appender
Expand Down Expand Up @@ -577,14 +578,15 @@ def _cmp_method(self, other, op):

# object dtype -> iteratively check for intervals
result = np.zeros(len(self), dtype=bool)
try:
for i, obj in enumerate(other):
result[i] = op(self[i], obj)
except TypeError:
# pd.NA
result = np.zeros(len(self), dtype=object)
for i, obj in enumerate(other):
for i, obj in enumerate(other):
try:
result[i] = op(self[i], obj)
except TypeError:
if obj is NA:
# github.com/pandas-dev/pandas/pull/37124#discussion_r509095092
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment with an actual explanation instead of (only) the link?

result[i] = op is operator.ne
else:
raise
return result

@unpack_zerodim_and_defer("__eq__")
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/arithmetic/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ def test_compare_list_like_nan(self, op, array, nulls_fixture, request):
result = op(array, other)
expected = self.elementwise_comparison(op, array, other)

if nulls_fixture is pd.NA and array.dtype.subtype != "i8":
reason = "broken for non-integer IntervalArray; see GH 31882"
mark = pytest.mark.xfail(reason=reason)
request.node.add_marker(mark)

tm.assert_numpy_array_equal(result, expected)

@pytest.mark.parametrize(
Expand Down
0