コード例 #1
0
ファイル: test_tslib.py プロジェクト: Timdwyer/pandas
    def test_nat_arithmetic(self):
        # GH 6873
        nat = tslib.NaT
        t = Timestamp('2014-01-01')
        dt = datetime.datetime(2014, 1, 1)
        delta = datetime.timedelta(3600)
        td = Timedelta('5s')
        i = 2
        f = 1.5

        for (left, right) in [(nat, i), (nat, f), (nat, np.nan)]:
            self.assertTrue((left / right) is nat)
            self.assertTrue((left * right) is nat)
            self.assertTrue((right * left) is nat)
            with tm.assertRaises(TypeError):
                right / left

        # Timestamp / datetime
        for (left, right) in [(nat, nat), (nat, t), (nat, dt)]:
            # NaT __add__ or __sub__ Timestamp-like (or inverse) returns NaT
            self.assertTrue((right + left) is nat)
            self.assertTrue((left + right) is nat)
            self.assertTrue((left - right) is nat)
            self.assertTrue((right - left) is nat)

        # timedelta-like
        # offsets are tested in test_offsets.py
        for (left, right) in [(nat, delta), (nat, td)]:
            # NaT + timedelta-like returns NaT
            self.assertTrue((right + left) is nat)
            self.assertTrue((left + right) is nat)
            self.assertTrue((right - left) is nat)
            self.assertTrue((left - right) is nat)
コード例 #2
0
ファイル: test_tslib.py プロジェクト: ubdsgroup/wikienergy
    def test_now(self):
        # #9000
        ts_from_string = Timestamp('now')
        ts_from_method = Timestamp.now()
        ts_datetime = datetime.datetime.now()

        ts_from_string_tz = Timestamp('now', tz='US/Eastern')
        ts_from_method_tz = Timestamp.now(tz='US/Eastern')

        # Check that the delta between the times is less than 1s (arbitrarily small)
        delta = Timedelta(seconds=1)
        self.assertTrue((ts_from_method - ts_from_string) < delta)
        self.assertTrue((ts_from_method_tz - ts_from_string_tz) < delta)
        self.assertTrue(
            (ts_from_string_tz.tz_localize(None) - ts_from_string) < delta)
コード例 #3
0
ファイル: test_tslib.py プロジェクト: mikeaddison93/pandas
    def test_today(self):

        ts_from_string = Timestamp('today')
        ts_from_method = Timestamp.today()
        ts_datetime = datetime.datetime.today()

        ts_from_string_tz = Timestamp('today', tz='US/Eastern')
        ts_from_method_tz = Timestamp.today(tz='US/Eastern')

        # Check that the delta between the times is less than 1s (arbitrarily small)
        delta = Timedelta(seconds=1)
        self.assertTrue(abs(ts_from_method - ts_from_string) < delta)
        self.assertTrue(abs(ts_datetime - ts_from_method) < delta)
        self.assertTrue(abs(ts_from_method_tz - ts_from_string_tz) < delta)
        self.assertTrue(
            abs(
                ts_from_string_tz.tz_localize(None) -
                ts_from_method_tz.tz_localize(None)) < delta)