Python pandas._libs.tslib.normalize_date() Examples
The following are 8
code examples of pandas._libs.tslib.normalize_date().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas._libs.tslib
, or try the search function
.
Example #1
Source File: date_range.py From mars with Apache License 2.0 | 6 votes |
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
Example #2
Source File: date_range.py From mars with Apache License 2.0 | 5 votes |
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))
Example #3
Source File: test_tools.py From vnpy_crypto with MIT License | 5 votes |
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))
Example #4
Source File: test_offsets.py From vnpy_crypto with MIT License | 5 votes |
def test_normalize_date(): actual = normalize_date(datetime(2007, 10, 1, 1, 12, 5, 10)) assert actual == datetime(2007, 10, 1)
Example #5
Source File: test_tools.py From twitter-stock-recommendation with MIT License | 5 votes |
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))
Example #6
Source File: test_offsets.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_normalize_date(): actual = normalize_date(datetime(2007, 10, 1, 1, 12, 5, 10)) assert actual == datetime(2007, 10, 1)
Example #7
Source File: offsets.py From vnpy_crypto with MIT License | 4 votes |
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
Example #8
Source File: offsets.py From twitter-stock-recommendation with MIT License | 4 votes |
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