当前位置: 首页>>代码示例>>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;未经允许,请勿转载。