示例#1
0
    def test_misc_coverage(self):
        rng = date_range('1/1/2000', periods=5)
        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))
示例#2
0
    def test_misc_coverage(self):
        rng = date_range("1/1/2000", periods=5)
        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))
示例#3
0
    def test_misc_coverage(self):
        rng = date_range('1/1/2000', periods=5)
        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_nat(self):
        # GH 5546
        dates = [NaT]
        idx = DatetimeIndex(dates)
        idx = idx.tz_localize("US/Pacific")
        self.assertTrue(idx.equals(DatetimeIndex(dates, tz="US/Pacific")))
        idx = idx.tz_convert("US/Eastern")
        self.assertTrue(idx.equals(DatetimeIndex(dates, tz="US/Eastern")))
        idx = idx.tz_convert("UTC")
        self.assertTrue(idx.equals(DatetimeIndex(dates, tz="UTC")))

        dates = ["2010-12-01 00:00", "2010-12-02 00:00", NaT]
        idx = DatetimeIndex(dates)
        idx = idx.tz_localize("US/Pacific")
        self.assertTrue(idx.equals(DatetimeIndex(dates, tz="US/Pacific")))
        idx = idx.tz_convert("US/Eastern")
        expected = ["2010-12-01 03:00", "2010-12-02 03:00", NaT]
        self.assertTrue(idx.equals(DatetimeIndex(expected, tz="US/Eastern")))

        idx = idx + offsets.Hour(5)
        expected = ["2010-12-01 08:00", "2010-12-02 08:00", NaT]
        self.assertTrue(idx.equals(DatetimeIndex(expected, tz="US/Eastern")))
        idx = idx.tz_convert("US/Pacific")
        expected = ["2010-12-01 05:00", "2010-12-02 05:00", NaT]
        self.assertTrue(idx.equals(DatetimeIndex(expected, tz="US/Pacific")))

        idx = idx + np.timedelta64(3, "h")
        expected = ["2010-12-01 08:00", "2010-12-02 08:00", NaT]
        self.assertTrue(idx.equals(DatetimeIndex(expected, tz="US/Pacific")))

        idx = idx.tz_convert("US/Eastern")
        expected = ["2010-12-01 11:00", "2010-12-02 11:00", NaT]
        self.assertTrue(idx.equals(DatetimeIndex(expected, tz="US/Eastern")))
示例#5
0
    def test_nat(self):
        # GH 5546
        dates = [NaT]
        idx = DatetimeIndex(dates)
        idx = idx.tz_localize('US/Pacific')
        self.assertTrue(idx.equals(DatetimeIndex(dates, tz='US/Pacific')))
        idx = idx.tz_convert('US/Eastern')
        self.assertTrue(idx.equals(DatetimeIndex(dates, tz='US/Eastern')))
        idx = idx.tz_convert('UTC')
        self.assertTrue(idx.equals(DatetimeIndex(dates, tz='UTC')))

        dates = ['2010-12-01 00:00', '2010-12-02 00:00', NaT]
        idx = DatetimeIndex(dates)
        idx = idx.tz_localize('US/Pacific')
        self.assertTrue(idx.equals(DatetimeIndex(dates, tz='US/Pacific')))
        idx = idx.tz_convert('US/Eastern')
        expected = ['2010-12-01 03:00', '2010-12-02 03:00', NaT]
        self.assertTrue(idx.equals(DatetimeIndex(expected, tz='US/Eastern')))

        idx = idx + offsets.Hour(5)
        expected = ['2010-12-01 08:00', '2010-12-02 08:00', NaT]
        self.assertTrue(idx.equals(DatetimeIndex(expected, tz='US/Eastern')))
        idx = idx.tz_convert('US/Pacific')
        expected = ['2010-12-01 05:00', '2010-12-02 05:00', NaT]
        self.assertTrue(idx.equals(DatetimeIndex(expected, tz='US/Pacific')))

        idx = idx + np.timedelta64(3, 'h')
        expected = ['2010-12-01 08:00', '2010-12-02 08:00', NaT]
        self.assertTrue(idx.equals(DatetimeIndex(expected, tz='US/Pacific')))

        idx = idx.tz_convert('US/Eastern')
        expected = ['2010-12-01 11:00', '2010-12-02 11:00', NaT]
        self.assertTrue(idx.equals(DatetimeIndex(expected, tz='US/Eastern')))
示例#6
0
    def test_nat(self):
        # GH 5546
        dates = [NaT]
        idx = DatetimeIndex(dates)
        idx = idx.tz_localize('US/Pacific')
        self.assert_(idx.equals(DatetimeIndex(dates, tz='US/Pacific')))
        idx = idx.tz_convert('US/Eastern')
        self.assert_(idx.equals(DatetimeIndex(dates, tz='US/Eastern')))
        idx = idx.tz_convert('UTC')
        self.assert_(idx.equals(DatetimeIndex(dates, tz='UTC')))

        dates = ['2010-12-01 00:00', '2010-12-02 00:00', NaT]
        idx = DatetimeIndex(dates)
        idx = idx.tz_localize('US/Pacific')
        self.assert_(idx.equals(DatetimeIndex(dates, tz='US/Pacific')))
        idx = idx.tz_convert('US/Eastern')
        expected = ['2010-12-01 03:00', '2010-12-02 03:00', NaT]
        self.assert_(idx.equals(DatetimeIndex(expected, tz='US/Eastern')))

        idx = idx + offsets.Hour(5)
        expected = ['2010-12-01 08:00', '2010-12-02 08:00', NaT]
        self.assert_(idx.equals(DatetimeIndex(expected, tz='US/Eastern')))
        idx = idx.tz_convert('US/Pacific')
        expected = ['2010-12-01 05:00', '2010-12-02 05:00', NaT]
        self.assert_(idx.equals(DatetimeIndex(expected, tz='US/Pacific')))

        if not _np_version_under1p7:
            idx = idx + np.timedelta64(3, 'h')
            expected = ['2010-12-01 08:00', '2010-12-02 08:00', NaT]
            self.assert_(idx.equals(DatetimeIndex(expected, tz='US/Pacific')))

            idx = idx.tz_convert('US/Eastern')
            expected = ['2010-12-01 11:00', '2010-12-02 11:00', NaT]
            self.assert_(idx.equals(DatetimeIndex(expected, tz='US/Eastern')))
示例#7
0
    def test_index_conversion(self):
        index = self.frame.index
        obj_index = index.asobject

        conv = DatetimeIndex(obj_index)
        self.assert_(conv.equals(index))

        self.assertRaises(ValueError, DatetimeIndex, ["a", "b", "c", "d"])
    def test_index_conversion(self):
        index = self.frame.index
        obj_index = index.asobject

        conv = DatetimeIndex(obj_index)
        self.assertTrue(conv.equals(index))

        self.assertRaises(ValueError, DatetimeIndex, ['a', 'b', 'c', 'd'])
    def test_index_conversion(self):
        index = self.frame.index
        obj_index = index.asobject

        conv = DatetimeIndex(obj_index)
        self.assertTrue(conv.equals(index))

        self.assertRaises(ValueError, DatetimeIndex, ['a', 'b', 'c', 'd'])
示例#10
0
 def test_ceil_floor_edge(self, test_input, rounder, freq, expected):
     dt = DatetimeIndex(list(test_input))
     func = getattr(dt, rounder)
     result = func(freq)
     expected = DatetimeIndex(list(expected))
     assert expected.equals(result)
示例#11
0
    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)
示例#12
0
 def test_ceil_floor_edge(self, tz, test_input, rounder, freq, expected):
     dt = DatetimeIndex(list(test_input))
     func = getattr(dt, rounder)
     result = func(freq)
     expected = DatetimeIndex(list(expected))
     assert expected.equals(result)