当前位置: 首页>>代码示例>>Python>>正文


Python tslib.normalize_date方法代码示例

本文整理汇总了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 
开发者ID:mars-project,项目名称:mars,代码行数:20,代码来源:date_range.py

示例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)) 
开发者ID:mars-project,项目名称:mars,代码行数:13,代码来源:date_range.py

示例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)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:12,代码来源:test_tools.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:5,代码来源:test_offsets.py

示例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 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:55,代码来源:offsets.py


注:本文中的pandas._libs.tslib.normalize_date方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。