當前位置: 首頁>>代碼示例>>Python>>正文


Python pandas.NaT方法代碼示例

本文整理匯總了Python中pandas.NaT方法的典型用法代碼示例。如果您正苦於以下問題:Python pandas.NaT方法的具體用法?Python pandas.NaT怎麽用?Python pandas.NaT使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas的用法示例。


在下文中一共展示了pandas.NaT方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_min_max

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_min_max(self):
        arr = TimedeltaArray._from_sequence([
            '3H', '3H', 'NaT', '2H', '5H', '4H',
        ])

        result = arr.min()
        expected = pd.Timedelta('2H')
        assert result == expected

        result = arr.max()
        expected = pd.Timedelta('5H')
        assert result == expected

        result = arr.min(skipna=False)
        assert result is pd.NaT

        result = arr.max(skipna=False)
        assert result is pd.NaT 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:20,代碼來源:test_timedeltas.py

示例2: test_min_max

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_min_max(self):
        arr = period_array([
            '2000-01-03',
            '2000-01-03',
            'NaT',
            '2000-01-02',
            '2000-01-05',
            '2000-01-04',
        ], freq='D')

        result = arr.min()
        expected = pd.Period('2000-01-02', freq='D')
        assert result == expected

        result = arr.max()
        expected = pd.Period('2000-01-05', freq='D')
        assert result == expected

        result = arr.min(skipna=False)
        assert result is pd.NaT

        result = arr.max(skipna=False)
        assert result is pd.NaT 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:test_period.py

示例3: test_fillna_preserves_tz

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_fillna_preserves_tz(self, method):
        dti = pd.date_range('2000-01-01', periods=5, freq='D', tz='US/Central')
        arr = DatetimeArray(dti, copy=True)
        arr[2] = pd.NaT

        fill_val = dti[1] if method == 'pad' else dti[3]
        expected = DatetimeArray._from_sequence(
            [dti[0], dti[1], fill_val, dti[3], dti[4]],
            freq=None, tz='US/Central'
        )

        result = arr.fillna(method=method)
        tm.assert_extension_array_equal(result, expected)

        # assert that arr and dti were not modified in-place
        assert arr[2] is pd.NaT
        assert dti[2] == pd.Timestamp('2000-01-03', tz='US/Central') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_datetimes.py

示例4: test_min_max

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_min_max(self, tz):
        arr = DatetimeArray._from_sequence([
            '2000-01-03',
            '2000-01-03',
            'NaT',
            '2000-01-02',
            '2000-01-05',
            '2000-01-04',
        ], tz=tz)

        result = arr.min()
        expected = pd.Timestamp('2000-01-02', tz=tz)
        assert result == expected

        result = arr.max()
        expected = pd.Timestamp('2000-01-05', tz=tz)
        assert result == expected

        result = arr.min(skipna=False)
        assert result is pd.NaT

        result = arr.max(skipna=False)
        assert result is pd.NaT 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:test_datetimes.py

示例5: test_searchsorted

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_searchsorted(self):
        data = np.arange(10, dtype='i8') * 24 * 3600 * 10**9
        arr = self.array_cls(data, freq='D')

        # scalar
        result = arr.searchsorted(arr[1])
        assert result == 1

        result = arr.searchsorted(arr[2], side="right")
        assert result == 3

        # own-type
        result = arr.searchsorted(arr[1:3])
        expected = np.array([1, 2], dtype=np.intp)
        tm.assert_numpy_array_equal(result, expected)

        result = arr.searchsorted(arr[1:3], side="right")
        expected = np.array([2, 3], dtype=np.intp)
        tm.assert_numpy_array_equal(result, expected)

        # Following numpy convention, NaT goes at the beginning
        #  (unlike NaN which goes at the end)
        result = arr.searchsorted(pd.NaT)
        assert result == 0 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:test_datetimelike.py

示例6: test_float64_ns_rounded

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_float64_ns_rounded(self):
        # GH#23539 without specifying a unit, floats are regarded as nanos,
        #  and fractional portions are truncated
        tdi = TimedeltaIndex([2.3, 9.7])
        expected = TimedeltaIndex([2, 9])
        tm.assert_index_equal(tdi, expected)

        # integral floats are non-lossy
        tdi = TimedeltaIndex([2.0, 9.0])
        expected = TimedeltaIndex([2, 9])
        tm.assert_index_equal(tdi, expected)

        # NaNs get converted to NaT
        tdi = TimedeltaIndex([2.0, np.nan])
        expected = TimedeltaIndex([pd.Timedelta(nanoseconds=2), pd.NaT])
        tm.assert_index_equal(tdi, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_construction.py

示例7: test_to_timedelta_on_missing_values

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_to_timedelta_on_missing_values(self):
        # GH5438
        timedelta_NaT = np.timedelta64('NaT')

        actual = pd.to_timedelta(Series(['00:00:01', np.nan]))
        expected = Series([np.timedelta64(1000000000, 'ns'),
                           timedelta_NaT], dtype='<m8[ns]')
        assert_series_equal(actual, expected)

        actual = pd.to_timedelta(Series(['00:00:01', pd.NaT]))
        assert_series_equal(actual, expected)

        actual = pd.to_timedelta(np.nan)
        assert actual.value == timedelta_NaT.astype('int64')

        actual = pd.to_timedelta(pd.NaT)
        assert actual.value == timedelta_NaT.astype('int64') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_tools.py

示例8: test_nat

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_nat(self):
        assert pd.TimedeltaIndex._na_value is pd.NaT
        assert pd.TimedeltaIndex([])._na_value is pd.NaT

        idx = pd.TimedeltaIndex(['1 days', '2 days'])
        assert idx._can_hold_na

        tm.assert_numpy_array_equal(idx._isnan, np.array([False, False]))
        assert idx.hasnans is False
        tm.assert_numpy_array_equal(idx._nan_idxs,
                                    np.array([], dtype=np.intp))

        idx = pd.TimedeltaIndex(['1 days', 'NaT'])
        assert idx._can_hold_na

        tm.assert_numpy_array_equal(idx._isnan, np.array([False, True]))
        assert idx.hasnans is True
        tm.assert_numpy_array_equal(idx._nan_idxs,
                                    np.array([1], dtype=np.intp)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:test_ops.py

示例9: test_map_dictlike

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_map_dictlike(self, mapper):
        expected = self.index + self.index.freq

        # don't compare the freqs
        if isinstance(expected, pd.DatetimeIndex):
            expected.freq = None

        result = self.index.map(mapper(expected, self.index))
        tm.assert_index_equal(result, expected)

        expected = pd.Index([pd.NaT] + self.index[1:].tolist())
        result = self.index.map(mapper(expected, self.index))
        tm.assert_index_equal(result, expected)

        # empty map; these map to np.nan because we cannot know
        # to re-infer things
        expected = pd.Index([np.nan] * len(self.index))
        result = self.index.map(mapper([], []))
        tm.assert_index_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:datetimelike.py

示例10: test_index_groupby

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_index_groupby(self):
        int_idx = Index(range(6))
        float_idx = Index(np.arange(0, 0.6, 0.1))
        obj_idx = Index('A B C D E F'.split())
        dt_idx = pd.date_range('2013-01-01', freq='M', periods=6)

        for idx in [int_idx, float_idx, obj_idx, dt_idx]:
            to_groupby = np.array([1, 2, np.nan, np.nan, 2, 1])
            tm.assert_dict_equal(idx.groupby(to_groupby),
                                 {1.0: idx[[0, 5]], 2.0: idx[[1, 4]]})

            to_groupby = Index([datetime(2011, 11, 1),
                                datetime(2011, 12, 1),
                                pd.NaT,
                                pd.NaT,
                                datetime(2011, 12, 1),
                                datetime(2011, 11, 1)],
                               tz='UTC').values

            ex_keys = [Timestamp('2011-11-01'), Timestamp('2011-12-01')]
            expected = {ex_keys[0]: idx[[0, 5]],
                        ex_keys[1]: idx[[1, 4]]}
            tm.assert_dict_equal(idx.groupby(to_groupby), expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:test_numeric.py

示例11: test_where_other

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_where_other(self):
        # other is ndarray or Index
        i = pd.date_range('20130101', periods=3, tz='US/Eastern')

        for arr in [np.nan, pd.NaT]:
            result = i.where(notna(i), other=np.nan)
            expected = i
            tm.assert_index_equal(result, expected)

        i2 = i.copy()
        i2 = Index([pd.NaT, pd.NaT] + i[2:].tolist())
        result = i.where(notna(i2), i2)
        tm.assert_index_equal(result, i2)

        i2 = i.copy()
        i2 = Index([pd.NaT, pd.NaT] + i[2:].tolist())
        result = i.where(notna(i2), i2.values)
        tm.assert_index_equal(result, i2) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:20,代碼來源:test_indexing.py

示例12: test_categorical_preserves_tz

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_categorical_preserves_tz(self):
        # GH#18664 retain tz when going DTI-->Categorical-->DTI
        # TODO: parametrize over DatetimeIndex/DatetimeArray
        #  once CategoricalIndex(DTA) works

        dti = pd.DatetimeIndex(
            [pd.NaT, '2015-01-01', '1999-04-06 15:14:13', '2015-01-01'],
            tz='US/Eastern')

        ci = pd.CategoricalIndex(dti)
        carr = pd.Categorical(dti)
        cser = pd.Series(ci)

        for obj in [ci, carr, cser]:
            result = pd.DatetimeIndex(obj)
            tm.assert_index_equal(result, dti) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_construction.py

示例13: test_dti_tz_localize_nonexistent_raise_coerce

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_dti_tz_localize_nonexistent_raise_coerce(self):
        # GH#13057
        times = ['2015-03-08 01:00', '2015-03-08 02:00', '2015-03-08 03:00']
        index = DatetimeIndex(times)
        tz = 'US/Eastern'
        with pytest.raises(pytz.NonExistentTimeError):
            index.tz_localize(tz=tz)

        with pytest.raises(pytz.NonExistentTimeError):
            with tm.assert_produces_warning(FutureWarning):
                index.tz_localize(tz=tz, errors='raise')

        with tm.assert_produces_warning(FutureWarning,
                                        clear=FutureWarning,
                                        check_stacklevel=False):
            result = index.tz_localize(tz=tz, errors='coerce')
        test_times = ['2015-03-08 01:00-05:00', 'NaT',
                      '2015-03-08 03:00-04:00']
        dti = to_datetime(test_times, utc=True)
        expected = dti.tz_convert('US/Eastern')
        tm.assert_index_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:test_timezones.py

示例14: test_datetime_outofbounds_scalar

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_datetime_outofbounds_scalar(self, value, format, infer):
        # GH24763
        res = pd.to_datetime(value, errors='ignore', format=format,
                             infer_datetime_format=infer)
        assert res == value

        res = pd.to_datetime(value, errors='coerce', format=format,
                             infer_datetime_format=infer)
        assert res is pd.NaT

        if format is not None:
            with pytest.raises(ValueError):
                pd.to_datetime(value, errors='raise', format=format,
                               infer_datetime_format=infer)
        else:
            with pytest.raises(OutOfBoundsDatetime):
                pd.to_datetime(value, errors='raise', format=format,
                               infer_datetime_format=infer) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:20,代碼來源:test_tools.py

示例15: test_iso_8601_strings_with_different_offsets

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import NaT [as 別名]
def test_iso_8601_strings_with_different_offsets(self):
        # GH 17697, 11736
        ts_strings = ["2015-11-18 15:30:00+05:30",
                      "2015-11-18 16:30:00+06:30",
                      NaT]
        result = to_datetime(ts_strings)
        expected = np.array([datetime(2015, 11, 18, 15, 30,
                                      tzinfo=tzoffset(None, 19800)),
                             datetime(2015, 11, 18, 16, 30,
                                      tzinfo=tzoffset(None, 23400)),
                             NaT],
                            dtype=object)
        # GH 21864
        expected = Index(expected)
        tm.assert_index_equal(result, expected)

        result = to_datetime(ts_strings, utc=True)
        expected = DatetimeIndex([Timestamp(2015, 11, 18, 10),
                                  Timestamp(2015, 11, 18, 10),
                                  NaT], tz='UTC')
        tm.assert_index_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:test_tools.py


注:本文中的pandas.NaT方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。