From 74c0b0138cfd74f70e82b72c3573b6e57c2d58fb Mon Sep 17 00:00:00 2001 From: Brock Date: Sun, 22 Nov 2020 15:30:09 -0800 Subject: [PATCH] TST/REF: collect Index.equals tests --- .../indexes/categorical/test_category.py | 71 ------- .../tests/indexes/categorical/test_equals.py | 77 ++++++++ pandas/tests/indexes/datetimelike.py | 22 +-- .../tests/indexes/datetimes/test_datetime.py | 6 - pandas/tests/indexes/datetimes/test_ops.py | 47 ----- pandas/tests/indexes/interval/test_base.py | 28 --- pandas/tests/indexes/interval/test_equals.py | 33 ++++ pandas/tests/indexes/period/test_ops.py | 32 ---- pandas/tests/indexes/test_datetimelike.py | 174 ++++++++++++++++++ pandas/tests/indexes/timedeltas/test_ops.py | 33 ---- .../indexes/timedeltas/test_timedelta.py | 6 - 11 files changed, 285 insertions(+), 244 deletions(-) create mode 100644 pandas/tests/indexes/categorical/test_equals.py create mode 100644 pandas/tests/indexes/interval/test_equals.py create mode 100644 pandas/tests/indexes/test_datetimelike.py diff --git a/pandas/tests/indexes/categorical/test_category.py b/pandas/tests/indexes/categorical/test_category.py index 1a05dbe2bb230..b2b3f76824b9e 100644 --- a/pandas/tests/indexes/categorical/test_category.py +++ b/pandas/tests/indexes/categorical/test_category.py @@ -381,77 +381,6 @@ def test_ensure_copied_data(self, index): result = CategoricalIndex(index.values, copy=False) assert _base(index.values) is _base(result.values) - def test_equals_categorical(self): - ci1 = CategoricalIndex(["a", "b"], categories=["a", "b"], ordered=True) - ci2 = CategoricalIndex(["a", "b"], categories=["a", "b", "c"], ordered=True) - - assert ci1.equals(ci1) - assert not ci1.equals(ci2) - assert ci1.equals(ci1.astype(object)) - assert ci1.astype(object).equals(ci1) - - assert (ci1 == ci1).all() - assert not (ci1 != ci1).all() - assert not (ci1 > ci1).all() - assert not (ci1 < ci1).all() - assert (ci1 <= ci1).all() - assert (ci1 >= ci1).all() - - assert not (ci1 == 1).all() - assert (ci1 == Index(["a", "b"])).all() - assert (ci1 == ci1.values).all() - - # invalid comparisons - with pytest.raises(ValueError, match="Lengths must match"): - ci1 == Index(["a", "b", "c"]) - - msg = "Categoricals can only be compared if 'categories' are the same" - with pytest.raises(TypeError, match=msg): - ci1 == ci2 - with pytest.raises(TypeError, match=msg): - ci1 == Categorical(ci1.values, ordered=False) - with pytest.raises(TypeError, match=msg): - ci1 == Categorical(ci1.values, categories=list("abc")) - - # tests - # make sure that we are testing for category inclusion properly - ci = CategoricalIndex(list("aabca"), categories=["c", "a", "b"]) - assert not ci.equals(list("aabca")) - # Same categories, but different order - # Unordered - assert ci.equals(CategoricalIndex(list("aabca"))) - # Ordered - assert not ci.equals(CategoricalIndex(list("aabca"), ordered=True)) - assert ci.equals(ci.copy()) - - ci = CategoricalIndex(list("aabca") + [np.nan], categories=["c", "a", "b"]) - assert not ci.equals(list("aabca")) - assert not ci.equals(CategoricalIndex(list("aabca"))) - assert ci.equals(ci.copy()) - - ci = CategoricalIndex(list("aabca") + [np.nan], categories=["c", "a", "b"]) - assert not ci.equals(list("aabca") + [np.nan]) - assert ci.equals(CategoricalIndex(list("aabca") + [np.nan])) - assert not ci.equals(CategoricalIndex(list("aabca") + [np.nan], ordered=True)) - assert ci.equals(ci.copy()) - - def test_equals_categorical_unordered(self): - # https://github.com/pandas-dev/pandas/issues/16603 - a = CategoricalIndex(["A"], categories=["A", "B"]) - b = CategoricalIndex(["A"], categories=["B", "A"]) - c = CategoricalIndex(["C"], categories=["B", "A"]) - assert a.equals(b) - assert not a.equals(c) - assert not b.equals(c) - - def test_equals_non_category(self): - # GH#37667 Case where other contains a value not among ci's - # categories ("D") and also contains np.nan - ci = CategoricalIndex(["A", "B", np.nan, np.nan]) - other = Index(["A", "B", "D", np.nan]) - - assert not ci.equals(other) - def test_frame_repr(self): df = pd.DataFrame({"A": [1, 2, 3]}, index=CategoricalIndex(["a", "b", "c"])) result = repr(df) diff --git a/pandas/tests/indexes/categorical/test_equals.py b/pandas/tests/indexes/categorical/test_equals.py new file mode 100644 index 0000000000000..3f9a58c6a06cd --- /dev/null +++ b/pandas/tests/indexes/categorical/test_equals.py @@ -0,0 +1,77 @@ +import numpy as np +import pytest + +from pandas import Categorical, CategoricalIndex, Index + + +class TestEquals: + def test_equals_categorical(self): + ci1 = CategoricalIndex(["a", "b"], categories=["a", "b"], ordered=True) + ci2 = CategoricalIndex(["a", "b"], categories=["a", "b", "c"], ordered=True) + + assert ci1.equals(ci1) + assert not ci1.equals(ci2) + assert ci1.equals(ci1.astype(object)) + assert ci1.astype(object).equals(ci1) + + assert (ci1 == ci1).all() + assert not (ci1 != ci1).all() + assert not (ci1 > ci1).all() + assert not (ci1 < ci1).all() + assert (ci1 <= ci1).all() + assert (ci1 >= ci1).all() + + assert not (ci1 == 1).all() + assert (ci1 == Index(["a", "b"])).all() + assert (ci1 == ci1.values).all() + + # invalid comparisons + with pytest.raises(ValueError, match="Lengths must match"): + ci1 == Index(["a", "b", "c"]) + + msg = "Categoricals can only be compared if 'categories' are the same" + with pytest.raises(TypeError, match=msg): + ci1 == ci2 + with pytest.raises(TypeError, match=msg): + ci1 == Categorical(ci1.values, ordered=False) + with pytest.raises(TypeError, match=msg): + ci1 == Categorical(ci1.values, categories=list("abc")) + + # tests + # make sure that we are testing for category inclusion properly + ci = CategoricalIndex(list("aabca"), categories=["c", "a", "b"]) + assert not ci.equals(list("aabca")) + # Same categories, but different order + # Unordered + assert ci.equals(CategoricalIndex(list("aabca"))) + # Ordered + assert not ci.equals(CategoricalIndex(list("aabca"), ordered=True)) + assert ci.equals(ci.copy()) + + ci = CategoricalIndex(list("aabca") + [np.nan], categories=["c", "a", "b"]) + assert not ci.equals(list("aabca")) + assert not ci.equals(CategoricalIndex(list("aabca"))) + assert ci.equals(ci.copy()) + + ci = CategoricalIndex(list("aabca") + [np.nan], categories=["c", "a", "b"]) + assert not ci.equals(list("aabca") + [np.nan]) + assert ci.equals(CategoricalIndex(list("aabca") + [np.nan])) + assert not ci.equals(CategoricalIndex(list("aabca") + [np.nan], ordered=True)) + assert ci.equals(ci.copy()) + + def test_equals_categorical_unordered(self): + # https://github.com/pandas-dev/pandas/issues/16603 + a = CategoricalIndex(["A"], categories=["A", "B"]) + b = CategoricalIndex(["A"], categories=["B", "A"]) + c = CategoricalIndex(["C"], categories=["B", "A"]) + assert a.equals(b) + assert not a.equals(c) + assert not b.equals(c) + + def test_equals_non_category(self): + # GH#37667 Case where other contains a value not among ci's + # categories ("D") and also contains np.nan + ci = CategoricalIndex(["A", "B", np.nan, np.nan]) + other = Index(["A", "B", "D", np.nan]) + + assert not ci.equals(other) diff --git a/pandas/tests/indexes/datetimelike.py b/pandas/tests/indexes/datetimelike.py index 6f078237e3a97..7ce8640d09777 100644 --- a/pandas/tests/indexes/datetimelike.py +++ b/pandas/tests/indexes/datetimelike.py @@ -1,4 +1,5 @@ """ generic datetimelike tests """ + import numpy as np import pytest @@ -109,27 +110,6 @@ def test_getitem_preserves_freq(self): result = index[:] assert result.freq == index.freq - def test_not_equals_numeric(self): - index = self.create_index() - - assert not index.equals(pd.Index(index.asi8)) - assert not index.equals(pd.Index(index.asi8.astype("u8"))) - assert not index.equals(pd.Index(index.asi8).astype("f8")) - - def test_equals(self): - index = self.create_index() - - assert index.equals(index.astype(object)) - assert index.equals(pd.CategoricalIndex(index)) - assert index.equals(pd.CategoricalIndex(index.astype(object))) - - def test_not_equals_strings(self): - index = self.create_index() - - other = pd.Index([str(x) for x in index], dtype=object) - assert not index.equals(other) - assert not index.equals(pd.CategoricalIndex(other)) - def test_where_cast_str(self): index = self.create_index() diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index b801f750718ac..b35aa28ffc40b 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -177,12 +177,6 @@ def test_misc_coverage(self): result = rng.groupby(rng.day) assert isinstance(list(result.values())[0][0], Timestamp) - idx = DatetimeIndex(["2000-01-03", "2000-01-01", "2000-01-02"]) - assert not idx.equals(list(idx)) - - non_datetime = Index(list("abc")) - assert not idx.equals(list(non_datetime)) - def test_string_index_series_name_converted(self): # #1644 df = DataFrame(np.random.randn(10, 4), index=date_range("1/1/2000", periods=10)) diff --git a/pandas/tests/indexes/datetimes/test_ops.py b/pandas/tests/indexes/datetimes/test_ops.py index 0359ee17f87c5..cbbe3aca9ccbe 100644 --- a/pandas/tests/indexes/datetimes/test_ops.py +++ b/pandas/tests/indexes/datetimes/test_ops.py @@ -325,47 +325,6 @@ def test_nat(self, tz_naive_fixture): assert idx.hasnans is True tm.assert_numpy_array_equal(idx._nan_idxs, np.array([1], dtype=np.intp)) - def test_equals(self): - # GH 13107 - idx = DatetimeIndex(["2011-01-01", "2011-01-02", "NaT"]) - assert idx.equals(idx) - assert idx.equals(idx.copy()) - assert idx.equals(idx.astype(object)) - assert idx.astype(object).equals(idx) - assert idx.astype(object).equals(idx.astype(object)) - assert not idx.equals(list(idx)) - assert not idx.equals(Series(idx)) - - idx2 = DatetimeIndex(["2011-01-01", "2011-01-02", "NaT"], tz="US/Pacific") - assert not idx.equals(idx2) - assert not idx.equals(idx2.copy()) - assert not idx.equals(idx2.astype(object)) - assert not idx.astype(object).equals(idx2) - assert not idx.equals(list(idx2)) - assert not idx.equals(Series(idx2)) - - # same internal, different tz - idx3 = DatetimeIndex(idx.asi8, tz="US/Pacific") - tm.assert_numpy_array_equal(idx.asi8, idx3.asi8) - assert not idx.equals(idx3) - assert not idx.equals(idx3.copy()) - assert not idx.equals(idx3.astype(object)) - assert not idx.astype(object).equals(idx3) - assert not idx.equals(list(idx3)) - assert not idx.equals(Series(idx3)) - - # check that we do not raise when comparing with OutOfBounds objects - oob = Index([datetime(2500, 1, 1)] * 3, dtype=object) - assert not idx.equals(oob) - assert not idx2.equals(oob) - assert not idx3.equals(oob) - - # check that we do not raise when comparing with OutOfBounds dt64 - oob2 = oob.map(np.datetime64) - assert not idx.equals(oob2) - assert not idx2.equals(oob2) - assert not idx3.equals(oob2) - @pytest.mark.parametrize("values", [["20180101", "20180103", "20180105"], []]) @pytest.mark.parametrize("freq", ["2D", Day(2), "2B", BDay(2), "48H", Hour(48)]) @pytest.mark.parametrize("tz", [None, "US/Eastern"]) @@ -429,9 +388,6 @@ def test_copy(self): repr(cp) tm.assert_index_equal(cp, self.rng) - def test_equals(self): - assert not self.rng.equals(list(self.rng)) - def test_identical(self): t1 = self.rng.copy() t2 = self.rng.copy() @@ -465,6 +421,3 @@ def test_copy(self): cp = self.rng.copy() repr(cp) tm.assert_index_equal(cp, self.rng) - - def test_equals(self): - assert not self.rng.equals(list(self.rng)) diff --git a/pandas/tests/indexes/interval/test_base.py b/pandas/tests/indexes/interval/test_base.py index 343c3d2e145f6..cc782a6e3bb81 100644 --- a/pandas/tests/indexes/interval/test_base.py +++ b/pandas/tests/indexes/interval/test_base.py @@ -21,34 +21,6 @@ def index(self): def create_index(self, closed="right"): return IntervalIndex.from_breaks(range(11), closed=closed) - def test_equals(self, closed): - expected = IntervalIndex.from_breaks(np.arange(5), closed=closed) - assert expected.equals(expected) - assert expected.equals(expected.copy()) - - assert not expected.equals(expected.astype(object)) - assert not expected.equals(np.array(expected)) - assert not expected.equals(list(expected)) - - assert not expected.equals([1, 2]) - assert not expected.equals(np.array([1, 2])) - assert not expected.equals(date_range("20130101", periods=2)) - - expected_name1 = IntervalIndex.from_breaks( - np.arange(5), closed=closed, name="foo" - ) - expected_name2 = IntervalIndex.from_breaks( - np.arange(5), closed=closed, name="bar" - ) - assert expected.equals(expected_name1) - assert expected_name1.equals(expected_name2) - - for other_closed in {"left", "right", "both", "neither"} - {closed}: - expected_other_closed = IntervalIndex.from_breaks( - np.arange(5), closed=other_closed - ) - assert not expected.equals(expected_other_closed) - def test_repr_max_seq_item_setting(self): # override base test: not a valid repr as we use interval notation pass diff --git a/pandas/tests/indexes/interval/test_equals.py b/pandas/tests/indexes/interval/test_equals.py new file mode 100644 index 0000000000000..e53a836366432 --- /dev/null +++ b/pandas/tests/indexes/interval/test_equals.py @@ -0,0 +1,33 @@ +import numpy as np + +from pandas import IntervalIndex, date_range + + +class TestEquals: + def test_equals(self, closed): + expected = IntervalIndex.from_breaks(np.arange(5), closed=closed) + assert expected.equals(expected) + assert expected.equals(expected.copy()) + + assert not expected.equals(expected.astype(object)) + assert not expected.equals(np.array(expected)) + assert not expected.equals(list(expected)) + + assert not expected.equals([1, 2]) + assert not expected.equals(np.array([1, 2])) + assert not expected.equals(date_range("20130101", periods=2)) + + expected_name1 = IntervalIndex.from_breaks( + np.arange(5), closed=closed, name="foo" + ) + expected_name2 = IntervalIndex.from_breaks( + np.arange(5), closed=closed, name="bar" + ) + assert expected.equals(expected_name1) + assert expected_name1.equals(expected_name2) + + for other_closed in {"left", "right", "both", "neither"} - {closed}: + expected_other_closed = IntervalIndex.from_breaks( + np.arange(5), closed=other_closed + ) + assert not expected.equals(expected_other_closed) diff --git a/pandas/tests/indexes/period/test_ops.py b/pandas/tests/indexes/period/test_ops.py index 8e7cb7d86edf5..645019f1ac063 100644 --- a/pandas/tests/indexes/period/test_ops.py +++ b/pandas/tests/indexes/period/test_ops.py @@ -287,38 +287,6 @@ def test_nat(self): assert idx.hasnans is True tm.assert_numpy_array_equal(idx._nan_idxs, np.array([1], dtype=np.intp)) - @pytest.mark.parametrize("freq", ["D", "M"]) - def test_equals(self, freq): - # GH#13107 - idx = PeriodIndex(["2011-01-01", "2011-01-02", "NaT"], freq=freq) - assert idx.equals(idx) - assert idx.equals(idx.copy()) - assert idx.equals(idx.astype(object)) - assert idx.astype(object).equals(idx) - assert idx.astype(object).equals(idx.astype(object)) - assert not idx.equals(list(idx)) - assert not idx.equals(Series(idx)) - - idx2 = PeriodIndex(["2011-01-01", "2011-01-02", "NaT"], freq="H") - assert not idx.equals(idx2) - assert not idx.equals(idx2.copy()) - assert not idx.equals(idx2.astype(object)) - assert not idx.astype(object).equals(idx2) - assert not idx.equals(list(idx2)) - assert not idx.equals(Series(idx2)) - - # same internal, different tz - idx3 = PeriodIndex._simple_new( - idx._values._simple_new(idx._values.asi8, freq="H") - ) - tm.assert_numpy_array_equal(idx.asi8, idx3.asi8) - assert not idx.equals(idx3) - assert not idx.equals(idx3.copy()) - assert not idx.equals(idx3.astype(object)) - assert not idx.astype(object).equals(idx3) - assert not idx.equals(list(idx3)) - assert not idx.equals(Series(idx3)) - def test_freq_setter_deprecated(self): # GH 20678 idx = pd.period_range("2018Q1", periods=4, freq="Q") diff --git a/pandas/tests/indexes/test_datetimelike.py b/pandas/tests/indexes/test_datetimelike.py new file mode 100644 index 0000000000000..55a90f982a971 --- /dev/null +++ b/pandas/tests/indexes/test_datetimelike.py @@ -0,0 +1,174 @@ +""" +Tests shared for DatetimeIndex/TimedeltaIndex/PeriodIndex +""" +from datetime import datetime, timedelta + +import numpy as np +import pytest + +import pandas as pd +from pandas import ( + CategoricalIndex, + DatetimeIndex, + Index, + PeriodIndex, + TimedeltaIndex, + date_range, + period_range, +) +import pandas._testing as tm + + +class EqualsTests: + def test_not_equals_numeric(self, index): + + assert not index.equals(Index(index.asi8)) + assert not index.equals(Index(index.asi8.astype("u8"))) + assert not index.equals(Index(index.asi8).astype("f8")) + + def test_equals(self, index): + assert index.equals(index) + assert index.equals(index.astype(object)) + assert index.equals(CategoricalIndex(index)) + assert index.equals(CategoricalIndex(index.astype(object))) + + def test_not_equals_non_arraylike(self, index): + assert not index.equals(list(index)) + + def test_not_equals_strings(self, index): + + other = Index([str(x) for x in index], dtype=object) + assert not index.equals(other) + assert not index.equals(CategoricalIndex(other)) + + def test_not_equals_misc_strs(self, index): + other = Index(list("abc")) + assert not index.equals(other) + + +class TestPeriodIndexEquals(EqualsTests): + @pytest.fixture + def index(self): + return period_range("2013-01-01", periods=5, freq="D") + + # TODO: de-duplicate with other test_equals2 methods + @pytest.mark.parametrize("freq", ["D", "M"]) + def test_equals2(self, freq): + # GH#13107 + idx = PeriodIndex(["2011-01-01", "2011-01-02", "NaT"], freq=freq) + assert idx.equals(idx) + assert idx.equals(idx.copy()) + assert idx.equals(idx.astype(object)) + assert idx.astype(object).equals(idx) + assert idx.astype(object).equals(idx.astype(object)) + assert not idx.equals(list(idx)) + assert not idx.equals(pd.Series(idx)) + + idx2 = PeriodIndex(["2011-01-01", "2011-01-02", "NaT"], freq="H") + assert not idx.equals(idx2) + assert not idx.equals(idx2.copy()) + assert not idx.equals(idx2.astype(object)) + assert not idx.astype(object).equals(idx2) + assert not idx.equals(list(idx2)) + assert not idx.equals(pd.Series(idx2)) + + # same internal, different tz + idx3 = PeriodIndex._simple_new( + idx._values._simple_new(idx._values.asi8, freq="H") + ) + tm.assert_numpy_array_equal(idx.asi8, idx3.asi8) + assert not idx.equals(idx3) + assert not idx.equals(idx3.copy()) + assert not idx.equals(idx3.astype(object)) + assert not idx.astype(object).equals(idx3) + assert not idx.equals(list(idx3)) + assert not idx.equals(pd.Series(idx3)) + + +class TestDatetimeIndexEquals(EqualsTests): + @pytest.fixture + def index(self): + return date_range("2013-01-01", periods=5) + + def test_equals2(self): + # GH#13107 + idx = DatetimeIndex(["2011-01-01", "2011-01-02", "NaT"]) + assert idx.equals(idx) + assert idx.equals(idx.copy()) + assert idx.equals(idx.astype(object)) + assert idx.astype(object).equals(idx) + assert idx.astype(object).equals(idx.astype(object)) + assert not idx.equals(list(idx)) + assert not idx.equals(pd.Series(idx)) + + idx2 = DatetimeIndex(["2011-01-01", "2011-01-02", "NaT"], tz="US/Pacific") + assert not idx.equals(idx2) + assert not idx.equals(idx2.copy()) + assert not idx.equals(idx2.astype(object)) + assert not idx.astype(object).equals(idx2) + assert not idx.equals(list(idx2)) + assert not idx.equals(pd.Series(idx2)) + + # same internal, different tz + idx3 = DatetimeIndex(idx.asi8, tz="US/Pacific") + tm.assert_numpy_array_equal(idx.asi8, idx3.asi8) + assert not idx.equals(idx3) + assert not idx.equals(idx3.copy()) + assert not idx.equals(idx3.astype(object)) + assert not idx.astype(object).equals(idx3) + assert not idx.equals(list(idx3)) + assert not idx.equals(pd.Series(idx3)) + + # check that we do not raise when comparing with OutOfBounds objects + oob = Index([datetime(2500, 1, 1)] * 3, dtype=object) + assert not idx.equals(oob) + assert not idx2.equals(oob) + assert not idx3.equals(oob) + + # check that we do not raise when comparing with OutOfBounds dt64 + oob2 = oob.map(np.datetime64) + assert not idx.equals(oob2) + assert not idx2.equals(oob2) + assert not idx3.equals(oob2) + + @pytest.mark.parametrize("freq", ["B", "C"]) + def test_not_equals_bday(self, freq): + rng = date_range("2009-01-01", "2010-01-01", freq=freq) + assert not rng.equals(list(rng)) + + +class TestTimedeltaIndexEquals(EqualsTests): + @pytest.fixture + def index(self): + return tm.makeTimedeltaIndex(10) + + def test_equals2(self): + # GH#13107 + idx = TimedeltaIndex(["1 days", "2 days", "NaT"]) + assert idx.equals(idx) + assert idx.equals(idx.copy()) + assert idx.equals(idx.astype(object)) + assert idx.astype(object).equals(idx) + assert idx.astype(object).equals(idx.astype(object)) + assert not idx.equals(list(idx)) + assert not idx.equals(pd.Series(idx)) + + idx2 = TimedeltaIndex(["2 days", "1 days", "NaT"]) + assert not idx.equals(idx2) + assert not idx.equals(idx2.copy()) + assert not idx.equals(idx2.astype(object)) + assert not idx.astype(object).equals(idx2) + assert not idx.astype(object).equals(idx2.astype(object)) + assert not idx.equals(list(idx2)) + assert not idx.equals(pd.Series(idx2)) + + # Check that we dont raise OverflowError on comparisons outside the + # implementation range + oob = Index([timedelta(days=10 ** 6)] * 3, dtype=object) + assert not idx.equals(oob) + assert not idx2.equals(oob) + + # FIXME: oob.apply(np.timedelta64) incorrectly overflows + oob2 = Index([np.timedelta64(x) for x in oob], dtype=object) + assert not idx.equals(oob2) + assert not idx2.equals(oob2) diff --git a/pandas/tests/indexes/timedeltas/test_ops.py b/pandas/tests/indexes/timedeltas/test_ops.py index 15b94eafe2f27..52097dbe610ef 100644 --- a/pandas/tests/indexes/timedeltas/test_ops.py +++ b/pandas/tests/indexes/timedeltas/test_ops.py @@ -1,5 +1,3 @@ -from datetime import timedelta - import numpy as np import pytest @@ -228,37 +226,6 @@ def test_nat(self): assert idx.hasnans is True tm.assert_numpy_array_equal(idx._nan_idxs, np.array([1], dtype=np.intp)) - def test_equals(self): - # GH 13107 - idx = TimedeltaIndex(["1 days", "2 days", "NaT"]) - assert idx.equals(idx) - assert idx.equals(idx.copy()) - assert idx.equals(idx.astype(object)) - assert idx.astype(object).equals(idx) - assert idx.astype(object).equals(idx.astype(object)) - assert not idx.equals(list(idx)) - assert not idx.equals(Series(idx)) - - idx2 = TimedeltaIndex(["2 days", "1 days", "NaT"]) - assert not idx.equals(idx2) - assert not idx.equals(idx2.copy()) - assert not idx.equals(idx2.astype(object)) - assert not idx.astype(object).equals(idx2) - assert not idx.astype(object).equals(idx2.astype(object)) - assert not idx.equals(list(idx2)) - assert not idx.equals(Series(idx2)) - - # Check that we dont raise OverflowError on comparisons outside the - # implementation range - oob = pd.Index([timedelta(days=10 ** 6)] * 3, dtype=object) - assert not idx.equals(oob) - assert not idx2.equals(oob) - - # FIXME: oob.apply(np.timedelta64) incorrectly overflows - oob2 = pd.Index([np.timedelta64(x) for x in oob], dtype=object) - assert not idx.equals(oob2) - assert not idx2.equals(oob2) - @pytest.mark.parametrize("values", [["0 days", "2 days", "4 days"], []]) @pytest.mark.parametrize("freq", ["2D", Day(2), "48H", Hour(48)]) def test_freq_setter(self, values, freq): diff --git a/pandas/tests/indexes/timedeltas/test_timedelta.py b/pandas/tests/indexes/timedeltas/test_timedelta.py index 4a1749ff734c1..774370ed866da 100644 --- a/pandas/tests/indexes/timedeltas/test_timedelta.py +++ b/pandas/tests/indexes/timedeltas/test_timedelta.py @@ -118,12 +118,6 @@ def test_misc_coverage(self): result = rng.groupby(rng.days) assert isinstance(list(result.values())[0][0], Timedelta) - idx = TimedeltaIndex(["3d", "1d", "2d"]) - assert not idx.equals(list(idx)) - - non_td = Index(list("abc")) - assert not idx.equals(list(non_td)) - def test_map(self): # test_map_dictlike generally tests