Python pandas.Timestamp.today() Examples

The following are 18 code examples of pandas.Timestamp.today(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pandas.Timestamp , or try the search function .
Example #1
Source File: test_timestamp.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_today(self):
        ts_from_string = Timestamp('today')
        ts_from_method = Timestamp.today()
        ts_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)
        assert abs(ts_from_method - ts_from_string) < delta
        assert abs(ts_datetime - ts_from_method) < delta
        assert abs(ts_from_method_tz - ts_from_string_tz) < delta
        assert (abs(ts_from_string_tz.tz_localize(None) -
                    ts_from_method_tz.tz_localize(None)) < delta) 
Example #2
Source File: test_timestamp.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def test_class_ops_dateutil(self):
        def compare(x, y):
            assert (int(np.round(Timestamp(x).value / 1e9)) ==
                    int(np.round(Timestamp(y).value / 1e9)))

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now('UTC'), datetime.now(tzutc()))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(Timestamp.utcfromtimestamp(current_time),
                datetime.utcfromtimestamp(current_time))
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(Timestamp.combine(date_component, time_component),
                datetime.combine(date_component, time_component)) 
Example #3
Source File: test_timestamp.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def test_class_ops_pytz(self):
        def compare(x, y):
            assert (int(Timestamp(x).value / 1e9) ==
                    int(Timestamp(y).value / 1e9))

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now('UTC'), datetime.now(timezone('UTC')))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(Timestamp.utcfromtimestamp(current_time),
                datetime.utcfromtimestamp(current_time))
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(Timestamp.combine(date_component, time_component),
                datetime.combine(date_component, time_component)) 
Example #4
Source File: test_timestamp.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def test_today(self):
        ts_from_string = Timestamp('today')
        ts_from_method = Timestamp.today()
        ts_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)
        assert abs(ts_from_method - ts_from_string) < delta
        assert abs(ts_datetime - ts_from_method) < delta
        assert abs(ts_from_method_tz - ts_from_string_tz) < delta
        assert (abs(ts_from_string_tz.tz_localize(None) -
                    ts_from_method_tz.tz_localize(None)) < delta) 
Example #5
Source File: test_multilevel.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def test_datetimeindex(self):
        idx1 = pd.DatetimeIndex(
            ['2013-04-01 9:00', '2013-04-02 9:00', '2013-04-03 9:00'
             ] * 2, tz='Asia/Tokyo')
        idx2 = pd.date_range('2010/01/01', periods=6, freq='M',
                             tz='US/Eastern')
        idx = MultiIndex.from_arrays([idx1, idx2])

        expected1 = pd.DatetimeIndex(['2013-04-01 9:00', '2013-04-02 9:00',
                                      '2013-04-03 9:00'], tz='Asia/Tokyo')

        tm.assert_index_equal(idx.levels[0], expected1)
        tm.assert_index_equal(idx.levels[1], idx2)

        # from datetime combos
        # GH 7888
        date1 = datetime.date.today()
        date2 = datetime.datetime.today()
        date3 = Timestamp.today()

        for d1, d2 in itertools.product(
                [date1, date2, date3], [date1, date2, date3]):
            index = MultiIndex.from_product([[d1], [d2]])
            assert isinstance(index.levels[0], pd.DatetimeIndex)
            assert isinstance(index.levels[1], pd.DatetimeIndex) 
Example #6
Source File: test_multilevel.py    From coffeegrindsize with MIT License 6 votes vote down vote up
def test_datetimeindex(self):
        idx1 = pd.DatetimeIndex(
            ['2013-04-01 9:00', '2013-04-02 9:00', '2013-04-03 9:00'
             ] * 2, tz='Asia/Tokyo')
        idx2 = pd.date_range('2010/01/01', periods=6, freq='M',
                             tz='US/Eastern')
        idx = MultiIndex.from_arrays([idx1, idx2])

        expected1 = pd.DatetimeIndex(['2013-04-01 9:00', '2013-04-02 9:00',
                                      '2013-04-03 9:00'], tz='Asia/Tokyo')

        tm.assert_index_equal(idx.levels[0], expected1)
        tm.assert_index_equal(idx.levels[1], idx2)

        # from datetime combos
        # GH 7888
        date1 = datetime.date.today()
        date2 = datetime.datetime.today()
        date3 = Timestamp.today()

        for d1, d2 in itertools.product(
                [date1, date2, date3], [date1, date2, date3]):
            index = MultiIndex.from_product([[d1], [d2]])
            assert isinstance(index.levels[0], pd.DatetimeIndex)
            assert isinstance(index.levels[1], pd.DatetimeIndex) 
Example #7
Source File: test_multilevel.py    From elasticintel with GNU General Public License v3.0 6 votes vote down vote up
def test_datetimeindex(self):
        idx1 = pd.DatetimeIndex(
            ['2013-04-01 9:00', '2013-04-02 9:00', '2013-04-03 9:00'
             ] * 2, tz='Asia/Tokyo')
        idx2 = pd.date_range('2010/01/01', periods=6, freq='M',
                             tz='US/Eastern')
        idx = MultiIndex.from_arrays([idx1, idx2])

        expected1 = pd.DatetimeIndex(['2013-04-01 9:00', '2013-04-02 9:00',
                                      '2013-04-03 9:00'], tz='Asia/Tokyo')

        tm.assert_index_equal(idx.levels[0], expected1)
        tm.assert_index_equal(idx.levels[1], idx2)

        # from datetime combos
        # GH 7888
        date1 = datetime.date.today()
        date2 = datetime.datetime.today()
        date3 = Timestamp.today()

        for d1, d2 in itertools.product(
                [date1, date2, date3], [date1, date2, date3]):
            index = pd.MultiIndex.from_product([[d1], [d2]])
            assert isinstance(index.levels[0], pd.DatetimeIndex)
            assert isinstance(index.levels[1], pd.DatetimeIndex) 
Example #8
Source File: test_timestamp.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_class_ops_dateutil(self):
        def compare(x, y):
            assert (int(np.round(Timestamp(x).value / 1e9)) ==
                    int(np.round(Timestamp(y).value / 1e9)))

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now('UTC'), datetime.now(tzutc()))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(Timestamp.utcfromtimestamp(current_time),
                datetime.utcfromtimestamp(current_time))
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(Timestamp.combine(date_component, time_component),
                datetime.combine(date_component, time_component)) 
Example #9
Source File: test_timestamp.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_class_ops_pytz(self):
        def compare(x, y):
            assert (int(Timestamp(x).value / 1e9) ==
                    int(Timestamp(y).value / 1e9))

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now('UTC'), datetime.now(timezone('UTC')))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(Timestamp.utcfromtimestamp(current_time),
                datetime.utcfromtimestamp(current_time))
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(Timestamp.combine(date_component, time_component),
                datetime.combine(date_component, time_component)) 
Example #10
Source File: test_multilevel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_datetimeindex(self):
        idx1 = pd.DatetimeIndex(
            ['2013-04-01 9:00', '2013-04-02 9:00', '2013-04-03 9:00'
             ] * 2, tz='Asia/Tokyo')
        idx2 = pd.date_range('2010/01/01', periods=6, freq='M',
                             tz='US/Eastern')
        idx = MultiIndex.from_arrays([idx1, idx2])

        expected1 = pd.DatetimeIndex(['2013-04-01 9:00', '2013-04-02 9:00',
                                      '2013-04-03 9:00'], tz='Asia/Tokyo')

        tm.assert_index_equal(idx.levels[0], expected1)
        tm.assert_index_equal(idx.levels[1], idx2)

        # from datetime combos
        # GH 7888
        date1 = datetime.date.today()
        date2 = datetime.datetime.today()
        date3 = Timestamp.today()

        for d1, d2 in itertools.product(
                [date1, date2, date3], [date1, date2, date3]):
            index = MultiIndex.from_product([[d1], [d2]])
            assert isinstance(index.levels[0], pd.DatetimeIndex)
            assert isinstance(index.levels[1], pd.DatetimeIndex) 
Example #11
Source File: test_multilevel.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_datetimeindex(self):
        idx1 = pd.DatetimeIndex(
            ['2013-04-01 9:00', '2013-04-02 9:00', '2013-04-03 9:00'
             ] * 2, tz='Asia/Tokyo')
        idx2 = pd.date_range('2010/01/01', periods=6, freq='M',
                             tz='US/Eastern')
        idx = MultiIndex.from_arrays([idx1, idx2])

        expected1 = pd.DatetimeIndex(['2013-04-01 9:00', '2013-04-02 9:00',
                                      '2013-04-03 9:00'], tz='Asia/Tokyo')

        tm.assert_index_equal(idx.levels[0], expected1)
        tm.assert_index_equal(idx.levels[1], idx2)

        # from datetime combos
        # GH 7888
        date1 = datetime.date.today()
        date2 = datetime.datetime.today()
        date3 = Timestamp.today()

        for d1, d2 in itertools.product(
                [date1, date2, date3], [date1, date2, date3]):
            index = MultiIndex.from_product([[d1], [d2]])
            assert isinstance(index.levels[0], pd.DatetimeIndex)
            assert isinstance(index.levels[1], pd.DatetimeIndex) 
Example #12
Source File: test_timestamp.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_class_ops_dateutil(self):
        def compare(x, y):
            assert (int(np.round(Timestamp(x).value / 1e9)) ==
                    int(np.round(Timestamp(y).value / 1e9)))

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now('UTC'), datetime.now(tzutc()))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(Timestamp.utcfromtimestamp(current_time),
                datetime.utcfromtimestamp(current_time))
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(Timestamp.combine(date_component, time_component),
                datetime.combine(date_component, time_component)) 
Example #13
Source File: test_timestamp.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_class_ops_pytz(self):
        def compare(x, y):
            assert (int(Timestamp(x).value / 1e9) ==
                    int(Timestamp(y).value / 1e9))

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now('UTC'), datetime.now(timezone('UTC')))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(Timestamp.utcfromtimestamp(current_time),
                datetime.utcfromtimestamp(current_time))
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(Timestamp.combine(date_component, time_component),
                datetime.combine(date_component, time_component)) 
Example #14
Source File: test_timestamp.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_today(self):
        ts_from_string = Timestamp('today')
        ts_from_method = Timestamp.today()
        ts_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)
        assert abs(ts_from_method - ts_from_string) < delta
        assert abs(ts_datetime - ts_from_method) < delta
        assert abs(ts_from_method_tz - ts_from_string_tz) < delta
        assert (abs(ts_from_string_tz.tz_localize(None) -
                    ts_from_method_tz.tz_localize(None)) < delta) 
Example #15
Source File: test_multilevel.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_datetimeindex(self):
        idx1 = pd.DatetimeIndex(
            ['2013-04-01 9:00', '2013-04-02 9:00', '2013-04-03 9:00'
             ] * 2, tz='Asia/Tokyo')
        idx2 = pd.date_range('2010/01/01', periods=6, freq='M',
                             tz='US/Eastern')
        idx = MultiIndex.from_arrays([idx1, idx2])

        expected1 = pd.DatetimeIndex(['2013-04-01 9:00', '2013-04-02 9:00',
                                      '2013-04-03 9:00'], tz='Asia/Tokyo')

        tm.assert_index_equal(idx.levels[0], expected1)
        tm.assert_index_equal(idx.levels[1], idx2)

        # from datetime combos
        # GH 7888
        date1 = datetime.date.today()
        date2 = datetime.datetime.today()
        date3 = Timestamp.today()

        for d1, d2 in itertools.product(
                [date1, date2, date3], [date1, date2, date3]):
            index = MultiIndex.from_product([[d1], [d2]])
            assert isinstance(index.levels[0], pd.DatetimeIndex)
            assert isinstance(index.levels[1], pd.DatetimeIndex) 
Example #16
Source File: test_timestamp.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_class_ops_dateutil(self):
        def compare(x, y):
            assert (int(np.round(Timestamp(x).value / 1e9)) ==
                    int(np.round(Timestamp(y).value / 1e9)))

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now('UTC'), datetime.now(tzutc()))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(Timestamp.utcfromtimestamp(current_time),
                datetime.utcfromtimestamp(current_time))
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(Timestamp.combine(date_component, time_component),
                datetime.combine(date_component, time_component)) 
Example #17
Source File: test_timestamp.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_class_ops_pytz(self):
        def compare(x, y):
            assert (int(Timestamp(x).value / 1e9) ==
                    int(Timestamp(y).value / 1e9))

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now('UTC'), datetime.now(timezone('UTC')))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(Timestamp.utcfromtimestamp(current_time),
                datetime.utcfromtimestamp(current_time))
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(Timestamp.combine(date_component, time_component),
                datetime.combine(date_component, time_component)) 
Example #18
Source File: test_timestamp.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_today(self):
        ts_from_string = Timestamp('today')
        ts_from_method = Timestamp.today()
        ts_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)
        assert abs(ts_from_method - ts_from_string) < delta
        assert abs(ts_datetime - ts_from_method) < delta
        assert abs(ts_from_method_tz - ts_from_string_tz) < delta
        assert (abs(ts_from_string_tz.tz_localize(None) -
                    ts_from_method_tz.tz_localize(None)) < delta)