本文整理汇总了Python中pandas._libs.tslib.normalize_date方法的典型用法代码示例。如果您正苦于以下问题:Python tslib.normalize_date方法的具体用法?Python tslib.normalize_date怎么用?Python tslib.normalize_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas._libs.tslib
的用法示例。
在下文中一共展示了tslib.normalize_date方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _maybe_normalize_endpoints
# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import normalize_date [as 别名]
def _maybe_normalize_endpoints(start, end, normalize): # pragma: no cover
_normalized = True
if start is not None:
if normalize:
start = normalize_date(start)
_normalized = True
else:
_normalized = _normalized and start.time() == _midnight
if end is not None:
if normalize:
end = normalize_date(end)
_normalized = True
else:
_normalized = _normalized and end.time() == _midnight
return start, end, _normalized
示例2: normalize_date
# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import normalize_date [as 别名]
def normalize_date(dt): # from pandas/_libs/tslibs/conversion.pyx
if isinstance(dt, datetime):
if isinstance(dt, pd.Timestamp):
return dt.replace(hour=0, minute=0, second=0, microsecond=0,
nanosecond=0)
else:
return dt.replace(hour=0, minute=0, second=0, microsecond=0)
elif isinstance(dt, date):
return datetime(dt.year, dt.month, dt.day)
else:
raise TypeError('Unrecognized type: %r' % type(dt))
示例3: test_normalize_date
# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import normalize_date [as 别名]
def test_normalize_date():
value = date(2012, 9, 7)
result = tslib.normalize_date(value)
assert (result == datetime(2012, 9, 7))
value = datetime(2012, 9, 7, 12)
result = tslib.normalize_date(value)
assert (result == datetime(2012, 9, 7))
示例4: test_normalize_date
# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import normalize_date [as 别名]
def test_normalize_date():
actual = normalize_date(datetime(2007, 10, 1, 1, 12, 5, 10))
assert actual == datetime(2007, 10, 1)
示例5: apply_wraps
# 需要导入模块: from pandas._libs import tslib [as 别名]
# 或者: from pandas._libs.tslib import normalize_date [as 别名]
def apply_wraps(func):
@functools.wraps(func)
def wrapper(self, other):
if other is tslib.NaT:
return tslib.NaT
elif isinstance(other, (timedelta, Tick, DateOffset)):
# timedelta path
return func(self, other)
elif isinstance(other, (np.datetime64, datetime, date)):
other = as_timestamp(other)
tz = getattr(other, 'tzinfo', None)
nano = getattr(other, 'nanosecond', 0)
try:
if self._adjust_dst and isinstance(other, Timestamp):
other = other.tz_localize(None)
result = func(self, other)
if self._adjust_dst:
result = tslib._localize_pydatetime(result, tz)
result = Timestamp(result)
if self.normalize:
result = result.normalize()
# nanosecond may be deleted depending on offset process
if not self.normalize and nano != 0:
if not isinstance(self, Nano) and result.nanosecond != nano:
if result.tz is not None:
# convert to UTC
value = tslib.tz_convert_single(
result.value, 'UTC', result.tz)
else:
value = result.value
result = Timestamp(value + nano)
if tz is not None and result.tzinfo is None:
result = tslib._localize_pydatetime(result, tz)
except OutOfBoundsDatetime:
result = func(self, as_datetime(other))
if self.normalize:
# normalize_date returns normal datetime
result = tslib.normalize_date(result)
if tz is not None and result.tzinfo is None:
result = tslib._localize_pydatetime(result, tz)
return result
return wrapper