|
1 |
| -from datetime import datetime, timedelta |
2 |
| - |
3 | 1 | import numpy as np
|
4 | 2 | import pytest
|
5 | 3 |
|
@@ -464,176 +462,6 @@ def test_join_self(self, join_type):
|
464 | 462 | joined = index.join(index, how=join_type)
|
465 | 463 | assert index is joined
|
466 | 464 |
|
467 |
| - @pytest.mark.parametrize("sort", [None, False]) |
468 |
| - def test_intersection(self, sort): |
469 |
| - # intersect with Int64Index |
470 |
| - index = self.create_index() |
471 |
| - other = Index(np.arange(1, 6)) |
472 |
| - result = index.intersection(other, sort=sort) |
473 |
| - expected = Index(np.sort(np.intersect1d(index.values, other.values))) |
474 |
| - tm.assert_index_equal(result, expected) |
475 |
| - |
476 |
| - result = other.intersection(index, sort=sort) |
477 |
| - expected = Index( |
478 |
| - np.sort(np.asarray(np.intersect1d(index.values, other.values))) |
479 |
| - ) |
480 |
| - tm.assert_index_equal(result, expected) |
481 |
| - |
482 |
| - # intersect with increasing RangeIndex |
483 |
| - other = RangeIndex(1, 6) |
484 |
| - result = index.intersection(other, sort=sort) |
485 |
| - expected = Index(np.sort(np.intersect1d(index.values, other.values))) |
486 |
| - tm.assert_index_equal(result, expected) |
487 |
| - |
488 |
| - # intersect with decreasing RangeIndex |
489 |
| - other = RangeIndex(5, 0, -1) |
490 |
| - result = index.intersection(other, sort=sort) |
491 |
| - expected = Index(np.sort(np.intersect1d(index.values, other.values))) |
492 |
| - tm.assert_index_equal(result, expected) |
493 |
| - |
494 |
| - # reversed (GH 17296) |
495 |
| - result = other.intersection(index, sort=sort) |
496 |
| - tm.assert_index_equal(result, expected) |
497 |
| - |
498 |
| - # GH 17296: intersect two decreasing RangeIndexes |
499 |
| - first = RangeIndex(10, -2, -2) |
500 |
| - other = RangeIndex(5, -4, -1) |
501 |
| - expected = first.astype(int).intersection(other.astype(int), sort=sort) |
502 |
| - result = first.intersection(other, sort=sort).astype(int) |
503 |
| - tm.assert_index_equal(result, expected) |
504 |
| - |
505 |
| - # reversed |
506 |
| - result = other.intersection(first, sort=sort).astype(int) |
507 |
| - tm.assert_index_equal(result, expected) |
508 |
| - |
509 |
| - index = RangeIndex(5) |
510 |
| - |
511 |
| - # intersect of non-overlapping indices |
512 |
| - other = RangeIndex(5, 10, 1) |
513 |
| - result = index.intersection(other, sort=sort) |
514 |
| - expected = RangeIndex(0, 0, 1) |
515 |
| - tm.assert_index_equal(result, expected) |
516 |
| - |
517 |
| - other = RangeIndex(-1, -5, -1) |
518 |
| - result = index.intersection(other, sort=sort) |
519 |
| - expected = RangeIndex(0, 0, 1) |
520 |
| - tm.assert_index_equal(result, expected) |
521 |
| - |
522 |
| - # intersection of empty indices |
523 |
| - other = RangeIndex(0, 0, 1) |
524 |
| - result = index.intersection(other, sort=sort) |
525 |
| - expected = RangeIndex(0, 0, 1) |
526 |
| - tm.assert_index_equal(result, expected) |
527 |
| - |
528 |
| - result = other.intersection(index, sort=sort) |
529 |
| - tm.assert_index_equal(result, expected) |
530 |
| - |
531 |
| - # intersection of non-overlapping values based on start value and gcd |
532 |
| - index = RangeIndex(1, 10, 2) |
533 |
| - other = RangeIndex(0, 10, 4) |
534 |
| - result = index.intersection(other, sort=sort) |
535 |
| - expected = RangeIndex(0, 0, 1) |
536 |
| - tm.assert_index_equal(result, expected) |
537 |
| - |
538 |
| - @pytest.mark.parametrize("sort", [False, None]) |
539 |
| - def test_union_noncomparable(self, sort): |
540 |
| - # corner case, non-Int64Index |
541 |
| - index = self.create_index() |
542 |
| - other = Index([datetime.now() + timedelta(i) for i in range(4)], dtype=object) |
543 |
| - result = index.union(other, sort=sort) |
544 |
| - expected = Index(np.concatenate((index, other))) |
545 |
| - tm.assert_index_equal(result, expected) |
546 |
| - |
547 |
| - result = other.union(index, sort=sort) |
548 |
| - expected = Index(np.concatenate((other, index))) |
549 |
| - tm.assert_index_equal(result, expected) |
550 |
| - |
551 |
| - @pytest.fixture( |
552 |
| - params=[ |
553 |
| - (RI(0, 10, 1), RI(0, 10, 1), RI(0, 10, 1), RI(0, 10, 1)), |
554 |
| - (RI(0, 10, 1), RI(5, 20, 1), RI(0, 20, 1), I64(range(20))), |
555 |
| - (RI(0, 10, 1), RI(10, 20, 1), RI(0, 20, 1), I64(range(20))), |
556 |
| - (RI(0, -10, -1), RI(0, -10, -1), RI(0, -10, -1), RI(0, -10, -1)), |
557 |
| - (RI(0, -10, -1), RI(-10, -20, -1), RI(-19, 1, 1), I64(range(0, -20, -1))), |
558 |
| - ( |
559 |
| - RI(0, 10, 2), |
560 |
| - RI(1, 10, 2), |
561 |
| - RI(0, 10, 1), |
562 |
| - I64(list(range(0, 10, 2)) + list(range(1, 10, 2))), |
563 |
| - ), |
564 |
| - ( |
565 |
| - RI(0, 11, 2), |
566 |
| - RI(1, 12, 2), |
567 |
| - RI(0, 12, 1), |
568 |
| - I64(list(range(0, 11, 2)) + list(range(1, 12, 2))), |
569 |
| - ), |
570 |
| - ( |
571 |
| - RI(0, 21, 4), |
572 |
| - RI(-2, 24, 4), |
573 |
| - RI(-2, 24, 2), |
574 |
| - I64(list(range(0, 21, 4)) + list(range(-2, 24, 4))), |
575 |
| - ), |
576 |
| - ( |
577 |
| - RI(0, -20, -2), |
578 |
| - RI(-1, -21, -2), |
579 |
| - RI(-19, 1, 1), |
580 |
| - I64(list(range(0, -20, -2)) + list(range(-1, -21, -2))), |
581 |
| - ), |
582 |
| - (RI(0, 100, 5), RI(0, 100, 20), RI(0, 100, 5), I64(range(0, 100, 5))), |
583 |
| - ( |
584 |
| - RI(0, -100, -5), |
585 |
| - RI(5, -100, -20), |
586 |
| - RI(-95, 10, 5), |
587 |
| - I64(list(range(0, -100, -5)) + [5]), |
588 |
| - ), |
589 |
| - ( |
590 |
| - RI(0, -11, -1), |
591 |
| - RI(1, -12, -4), |
592 |
| - RI(-11, 2, 1), |
593 |
| - I64(list(range(0, -11, -1)) + [1, -11]), |
594 |
| - ), |
595 |
| - (RI(0), RI(0), RI(0), RI(0)), |
596 |
| - (RI(0, -10, -2), RI(0), RI(0, -10, -2), RI(0, -10, -2)), |
597 |
| - (RI(0, 100, 2), RI(100, 150, 200), RI(0, 102, 2), I64(range(0, 102, 2))), |
598 |
| - ( |
599 |
| - RI(0, -100, -2), |
600 |
| - RI(-100, 50, 102), |
601 |
| - RI(-100, 4, 2), |
602 |
| - I64(list(range(0, -100, -2)) + [-100, 2]), |
603 |
| - ), |
604 |
| - ( |
605 |
| - RI(0, -100, -1), |
606 |
| - RI(0, -50, -3), |
607 |
| - RI(-99, 1, 1), |
608 |
| - I64(list(range(0, -100, -1))), |
609 |
| - ), |
610 |
| - (RI(0, 1, 1), RI(5, 6, 10), RI(0, 6, 5), I64([0, 5])), |
611 |
| - (RI(0, 10, 5), RI(-5, -6, -20), RI(-5, 10, 5), I64([0, 5, -5])), |
612 |
| - (RI(0, 3, 1), RI(4, 5, 1), I64([0, 1, 2, 4]), I64([0, 1, 2, 4])), |
613 |
| - (RI(0, 10, 1), I64([]), RI(0, 10, 1), RI(0, 10, 1)), |
614 |
| - (RI(0), I64([1, 5, 6]), I64([1, 5, 6]), I64([1, 5, 6])), |
615 |
| - ] |
616 |
| - ) |
617 |
| - def unions(self, request): |
618 |
| - """Inputs and expected outputs for RangeIndex.union tests""" |
619 |
| - |
620 |
| - return request.param |
621 |
| - |
622 |
| - def test_union_sorted(self, unions): |
623 |
| - |
624 |
| - idx1, idx2, expected_sorted, expected_notsorted = unions |
625 |
| - |
626 |
| - res1 = idx1.union(idx2, sort=None) |
627 |
| - tm.assert_index_equal(res1, expected_sorted, exact=True) |
628 |
| - |
629 |
| - res1 = idx1.union(idx2, sort=False) |
630 |
| - tm.assert_index_equal(res1, expected_notsorted, exact=True) |
631 |
| - |
632 |
| - res2 = idx2.union(idx1, sort=None) |
633 |
| - res3 = idx1._int64index.union(idx2, sort=None) |
634 |
| - tm.assert_index_equal(res2, expected_sorted, exact=True) |
635 |
| - tm.assert_index_equal(res3, expected_sorted) |
636 |
| - |
637 | 465 | def test_nbytes(self):
|
638 | 466 |
|
639 | 467 | # memory savings vs int index
|
|
0 commit comments