Skip to content

Commit 5d3a861

Browse files
Address review comments
1 parent 7df795a commit 5d3a861

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

pandas/core/indexes/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,7 @@ def _union(self, other, sort):
24922492
# find indexes of things in "other" that are not in "self"
24932493
if self.is_unique:
24942494
indexer = self.get_indexer(other)
2495-
indexer, = (indexer == -1).nonzero()
2495+
indexer = (indexer == -1).nonzero()[0]
24962496
else:
24972497
indexer = algos.unique1d(self.get_indexer_non_unique(other)[1])
24982498

pandas/tests/indexes/test_category.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -600,24 +600,24 @@ def test_reindex_dtype(self):
600600

601601
def test_reindex_duplicate_source(self):
602602
# See GH23963
603-
c = CategoricalIndex(["a", "b", "c", "a"], categories=["a", "b", "c", "d"])
603+
cat = CategoricalIndex(["a", "b", "c", "a"], categories=["a", "b", "c", "d"])
604604
with pytest.raises(ValueError, match="duplicate axis"):
605-
c._can_reindex(["a", "c"])
605+
cat._can_reindex(["a", "c"])
606606

607607
with pytest.raises(ValueError, match="duplicate axis"):
608-
c._can_reindex(
608+
cat._can_reindex(
609609
CategoricalIndex(["a", "c"], categories=["a", "b", "c", "d"])
610610
)
611611

612612
def test_reindex_duplicate_target(self):
613613
# See GH25459
614-
c = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c", "d"])
615-
res, indexer = c.reindex(["a", "c", "c"])
614+
cat = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c", "d"])
615+
res, indexer = cat.reindex(["a", "c", "c"])
616616
exp = Index(["a", "c", "c"], dtype="object")
617617
tm.assert_index_equal(res, exp, exact=True)
618618
tm.assert_numpy_array_equal(indexer, np.array([0, 2, 2], dtype=np.intp))
619619

620-
res, indexer = c.reindex(
620+
res, indexer = cat.reindex(
621621
CategoricalIndex(["a", "c", "c"], categories=["a", "b", "c", "d"])
622622
)
623623
exp = CategoricalIndex(["a", "c", "c"], categories=["a", "b", "c", "d"])

pandas/tests/series/test_operators.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,27 +273,54 @@ def test_logical_ops_with_index(self, op):
273273
result = op(ser, idx2)
274274
assert_series_equal(result, expected)
275275

276+
def test_reversed_xor_with_index_returns_index(self):
277+
# GH#22092, GH#19792
278+
ser = Series([True, True, False, False])
279+
idx1 = Index([True, False, True, False])
280+
idx2 = Index([1, 0, 1, 0])
281+
282+
expected = Index.symmetric_difference(idx1, ser)
283+
result = idx1 ^ ser
284+
assert_index_equal(result, expected)
285+
286+
expected = Index.symmetric_difference(idx2, ser)
287+
result = idx2 ^ ser
288+
assert_index_equal(result, expected)
289+
276290
@pytest.mark.parametrize(
277-
"op, index_op",
291+
"op",
278292
[
279-
(ops.rand_, Index.intersection),
280-
(ops.ror_, Index.union),
281-
(ops.rxor, Index.symmetric_difference),
293+
pytest.param(
294+
ops.rand_,
295+
marks=pytest.mark.xfail(
296+
reason="GH#22092 Index __and__ returns Index intersection",
297+
raises=AssertionError,
298+
strict=True,
299+
),
300+
),
301+
pytest.param(
302+
ops.ror_,
303+
marks=pytest.mark.xfail(
304+
reason="GH#22092 Index __or__ returns Index union",
305+
raises=AssertionError,
306+
strict=True,
307+
),
308+
),
282309
],
283310
)
284-
def test_reversed_logical_ops_with_index(self, op, index_op):
311+
def test_reversed_logical_op_with_index_returns_series(self, op):
285312
# GH#22092, GH#19792
286313
ser = Series([True, True, False, False])
287314
idx1 = Index([True, False, True, False])
288315
idx2 = Index([1, 0, 1, 0])
289316

290-
expected = index_op(idx1, ser)
317+
expected = pd.Series(op(idx1.values, ser.values))
291318
result = op(ser, idx1)
292-
assert_index_equal(result, expected)
319+
assert_series_equal(result, expected)
293320

294-
expected = index_op(idx2, ser)
321+
expected = pd.Series(op(idx2.values, ser.values))
295322
result = op(ser, idx2)
296-
assert_index_equal(result, expected)
323+
assert_series_equal(result, expected)
297324

298325
@pytest.mark.parametrize(
299326
"op, expected",

0 commit comments

Comments
 (0)