本文整理汇总了Python中pandas.tseries.offsets.Nano方法的典型用法代码示例。如果您正苦于以下问题:Python offsets.Nano方法的具体用法?Python offsets.Nano怎么用?Python offsets.Nano使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.tseries.offsets
的用法示例。
在下文中一共展示了offsets.Nano方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_Nanosecond
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def test_Nanosecond():
timestamp = Timestamp(datetime(2010, 1, 1))
assert_offset_equal(Nano(),
timestamp,
timestamp + np.timedelta64(1, 'ns'))
assert_offset_equal(Nano(-1),
timestamp + np.timedelta64(1, 'ns'),
timestamp)
assert_offset_equal(2 * Nano(),
timestamp,
timestamp + np.timedelta64(2, 'ns'))
assert_offset_equal(-1 * Nano(),
timestamp + np.timedelta64(1, 'ns'),
timestamp)
assert Nano(3) + Nano(2) == Nano(5)
assert Nano(3) - Nano(2) == Nano()
# GH9284
assert Nano(1) + Nano(10) == Nano(11)
assert Nano(5) + Micro(1) == Nano(1005)
assert Micro(5) + Nano(1) == Nano(5001)
示例2: test_tick_division
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def test_tick_division(cls):
off = cls(10)
assert off / cls(5) == 2
assert off / 2 == cls(5)
assert off / 2.0 == cls(5)
assert off / off.delta == 1
assert off / off.delta.to_timedelta64() == 1
assert off / Nano(1) == off.delta / Nano(1).delta
if cls is not Nano:
# A case where we end up with a smaller class
result = off / 1000
assert isinstance(result, offsets.Tick)
assert not isinstance(result, cls)
assert result.delta == off.delta / 1000
if cls._inc < Timedelta(seconds=1):
# Case where we end up with a bigger class
result = off / .001
assert isinstance(result, offsets.Tick)
assert not isinstance(result, cls)
assert result.delta == off.delta / .001
示例3: test_tz
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def test_tz(self):
tstr = '2014-02-01 09:00'
ts = Timestamp(tstr)
local = ts.tz_localize('Asia/Tokyo')
assert local.hour == 9
assert local == Timestamp(tstr, tz='Asia/Tokyo')
conv = local.tz_convert('US/Eastern')
assert conv == Timestamp('2014-01-31 19:00', tz='US/Eastern')
assert conv.hour == 19
# preserves nanosecond
ts = Timestamp(tstr) + offsets.Nano(5)
local = ts.tz_localize('Asia/Tokyo')
assert local.hour == 9
assert local.nanosecond == 5
conv = local.tz_convert('US/Eastern')
assert conv.nanosecond == 5
assert conv.hour == 19
示例4: _adjust_bin_edges
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def _adjust_bin_edges(self, binner, ax_values):
# Some hacks for > daily data, see #1471, #1458, #1483
if self.freq != 'D' and is_superperiod(self.freq, 'D'):
if self.closed == 'right':
# GH 21459, GH 9119: Adjust the bins relative to the wall time
bin_edges = binner.tz_localize(None)
bin_edges = bin_edges + timedelta(1) - Nano(1)
bin_edges = bin_edges.tz_localize(binner.tz).asi8
else:
bin_edges = binner.asi8
# intraday values on last day
if bin_edges[-2] > ax_values.max():
bin_edges = bin_edges[:-1]
binner = binner[:-1]
else:
bin_edges = binner.asi8
return binner, bin_edges
示例5: test_is_superperiod_subperiod
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def test_is_superperiod_subperiod():
# input validation
assert not (is_superperiod(offsets.YearEnd(), None))
assert not (is_subperiod(offsets.MonthEnd(), None))
assert not (is_superperiod(None, offsets.YearEnd()))
assert not (is_subperiod(None, offsets.MonthEnd()))
assert not (is_superperiod(None, None))
assert not (is_subperiod(None, None))
assert (is_superperiod(offsets.YearEnd(), offsets.MonthEnd()))
assert (is_subperiod(offsets.MonthEnd(), offsets.YearEnd()))
assert (is_superperiod(offsets.Hour(), offsets.Minute()))
assert (is_subperiod(offsets.Minute(), offsets.Hour()))
assert (is_superperiod(offsets.Second(), offsets.Milli()))
assert (is_subperiod(offsets.Milli(), offsets.Second()))
assert (is_superperiod(offsets.Milli(), offsets.Micro()))
assert (is_subperiod(offsets.Micro(), offsets.Milli()))
assert (is_superperiod(offsets.Micro(), offsets.Nano()))
assert (is_subperiod(offsets.Nano(), offsets.Micro()))
示例6: test_is_superperiod_subperiod
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def test_is_superperiod_subperiod():
# input validation
assert not (frequencies.is_superperiod(offsets.YearEnd(), None))
assert not (frequencies.is_subperiod(offsets.MonthEnd(), None))
assert not (frequencies.is_superperiod(None, offsets.YearEnd()))
assert not (frequencies.is_subperiod(None, offsets.MonthEnd()))
assert not (frequencies.is_superperiod(None, None))
assert not (frequencies.is_subperiod(None, None))
assert (frequencies.is_superperiod(offsets.YearEnd(), offsets.MonthEnd()))
assert (frequencies.is_subperiod(offsets.MonthEnd(), offsets.YearEnd()))
assert (frequencies.is_superperiod(offsets.Hour(), offsets.Minute()))
assert (frequencies.is_subperiod(offsets.Minute(), offsets.Hour()))
assert (frequencies.is_superperiod(offsets.Second(), offsets.Milli()))
assert (frequencies.is_subperiod(offsets.Milli(), offsets.Second()))
assert (frequencies.is_superperiod(offsets.Milli(), offsets.Micro()))
assert (frequencies.is_subperiod(offsets.Micro(), offsets.Milli()))
assert (frequencies.is_superperiod(offsets.Micro(), offsets.Nano()))
assert (frequencies.is_subperiod(offsets.Nano(), offsets.Micro()))
示例7: test_tz
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def test_tz(self):
t = '2014-02-01 09:00'
ts = Timestamp(t)
local = ts.tz_localize('Asia/Tokyo')
assert local.hour == 9
assert local == Timestamp(t, tz='Asia/Tokyo')
conv = local.tz_convert('US/Eastern')
assert conv == Timestamp('2014-01-31 19:00', tz='US/Eastern')
assert conv.hour == 19
# preserves nanosecond
ts = Timestamp(t) + offsets.Nano(5)
local = ts.tz_localize('Asia/Tokyo')
assert local.hour == 9
assert local.nanosecond == 5
conv = local.tz_convert('US/Eastern')
assert conv.nanosecond == 5
assert conv.hour == 19
示例8: test_qcut_nat
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def test_qcut_nat(ser):
# see gh-19768
intervals = IntervalIndex.from_tuples([
(ser[0] - Nano(), ser[2] - Day()),
np.nan, (ser[2] - Day(), ser[2])])
expected = Series(Categorical(intervals, ordered=True))
result = qcut(ser, 2)
tm.assert_series_equal(result, expected)
示例9: test_delta_to_tick
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def test_delta_to_tick():
delta = timedelta(3)
tick = offsets._delta_to_tick(delta)
assert (tick == offsets.Day(3))
td = Timedelta(nanoseconds=5)
tick = offsets._delta_to_tick(td)
assert tick == Nano(5)
示例10: test_NanosecondGeneric
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def test_NanosecondGeneric():
timestamp = Timestamp(datetime(2010, 1, 1))
assert timestamp.nanosecond == 0
result = timestamp + Nano(10)
assert result.nanosecond == 10
reverse_result = Nano(10) + timestamp
assert reverse_result.nanosecond == 10
示例11: test_nanosecond_timestamp
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def test_nanosecond_timestamp(self):
# GH 7610
expected = 1293840000000000005
t = Timestamp('2011-01-01') + offsets.Nano(5)
assert repr(t) == "Timestamp('2011-01-01 00:00:00.000000005')"
assert t.value == expected
assert t.nanosecond == 5
t = Timestamp(t)
assert repr(t) == "Timestamp('2011-01-01 00:00:00.000000005')"
assert t.value == expected
assert t.nanosecond == 5
t = Timestamp(np_datetime64_compat('2011-01-01 00:00:00.000000005Z'))
assert repr(t) == "Timestamp('2011-01-01 00:00:00.000000005')"
assert t.value == expected
assert t.nanosecond == 5
expected = 1293840000000000010
t = t + offsets.Nano(5)
assert repr(t) == "Timestamp('2011-01-01 00:00:00.000000010')"
assert t.value == expected
assert t.nanosecond == 10
t = Timestamp(t)
assert repr(t) == "Timestamp('2011-01-01 00:00:00.000000010')"
assert t.value == expected
assert t.nanosecond == 10
t = Timestamp(np_datetime64_compat('2011-01-01 00:00:00.000000010Z'))
assert repr(t) == "Timestamp('2011-01-01 00:00:00.000000010')"
assert t.value == expected
assert t.nanosecond == 10
示例12: test_qcut_nat
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def test_qcut_nat(self, s):
# GH 19768
intervals = IntervalIndex.from_tuples(
[(s[0] - Nano(), s[2] - Day()), np.nan, (s[2] - Day(), s[2])])
expected = Series(Categorical(intervals, ordered=True))
result = qcut(s, 2)
tm.assert_series_equal(result, expected)
示例13: test_tick_zero
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import Nano [as 别名]
def test_tick_zero(cls1, cls2):
assert cls1(0) == cls2(0)
assert cls1(0) + cls2(0) == cls1(0)
if cls1 is not Nano:
assert cls1(2) + cls2(0) == cls1(2)
if cls1 is Nano:
assert cls1(2) + Nano(0) == cls1(2)