|
40 | 40 | DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin, |
41 | 41 | wrap_field_accessor, wrap_array_method) |
42 | 42 | from pandas.tseries.offsets import ( |
43 | | - generate_range, CDay, prefix_mapping) |
| 43 | + CDay, prefix_mapping) |
44 | 44 |
|
45 | 45 | from pandas.core.tools.timedeltas import to_timedelta |
46 | 46 | from pandas.util._decorators import Appender, cache_readonly, Substitution |
@@ -326,13 +326,6 @@ def _generate_range(cls, start, end, periods, name=None, freq=None, |
326 | 326 | out.name = name |
327 | 327 | return out |
328 | 328 |
|
329 | | - @classmethod |
330 | | - def _use_cached_range(cls, freq, _normalized, start, end): |
331 | | - # Note: This always returns False |
332 | | - return (freq._should_cache() and |
333 | | - not (freq._normalize_cache and not _normalized) and |
334 | | - _naive_in_cache_range(start, end)) |
335 | | - |
336 | 329 | def _convert_for_op(self, value): |
337 | 330 | """ Convert value to be insertable to ndarray """ |
338 | 331 | if self._has_same_tz(value): |
@@ -410,71 +403,6 @@ def nbytes(self): |
410 | 403 | # for TZ-aware |
411 | 404 | return self._ndarray_values.nbytes |
412 | 405 |
|
413 | | - @classmethod |
414 | | - def _cached_range(cls, start=None, end=None, periods=None, freq=None, |
415 | | - name=None): |
416 | | - if start is None and end is None: |
417 | | - # I somewhat believe this should never be raised externally |
418 | | - raise TypeError('Must specify either start or end.') |
419 | | - if start is not None: |
420 | | - start = Timestamp(start) |
421 | | - if end is not None: |
422 | | - end = Timestamp(end) |
423 | | - if (start is None or end is None) and periods is None: |
424 | | - raise TypeError( |
425 | | - 'Must either specify period or provide both start and end.') |
426 | | - |
427 | | - if freq is None: |
428 | | - # This can't happen with external-facing code |
429 | | - raise TypeError('Must provide freq.') |
430 | | - |
431 | | - drc = _daterange_cache |
432 | | - if freq not in _daterange_cache: |
433 | | - xdr = generate_range(offset=freq, start=_CACHE_START, |
434 | | - end=_CACHE_END) |
435 | | - |
436 | | - arr = tools.to_datetime(list(xdr), box=False) |
437 | | - |
438 | | - cachedRange = DatetimeIndex._simple_new(arr) |
439 | | - cachedRange.freq = freq |
440 | | - cachedRange = cachedRange.tz_localize(None) |
441 | | - cachedRange.name = None |
442 | | - drc[freq] = cachedRange |
443 | | - else: |
444 | | - cachedRange = drc[freq] |
445 | | - |
446 | | - if start is None: |
447 | | - if not isinstance(end, Timestamp): |
448 | | - raise AssertionError('end must be an instance of Timestamp') |
449 | | - |
450 | | - end = freq.rollback(end) |
451 | | - |
452 | | - endLoc = cachedRange.get_loc(end) + 1 |
453 | | - startLoc = endLoc - periods |
454 | | - elif end is None: |
455 | | - if not isinstance(start, Timestamp): |
456 | | - raise AssertionError('start must be an instance of Timestamp') |
457 | | - |
458 | | - start = freq.rollforward(start) |
459 | | - |
460 | | - startLoc = cachedRange.get_loc(start) |
461 | | - endLoc = startLoc + periods |
462 | | - else: |
463 | | - if not freq.onOffset(start): |
464 | | - start = freq.rollforward(start) |
465 | | - |
466 | | - if not freq.onOffset(end): |
467 | | - end = freq.rollback(end) |
468 | | - |
469 | | - startLoc = cachedRange.get_loc(start) |
470 | | - endLoc = cachedRange.get_loc(end) + 1 |
471 | | - |
472 | | - indexSlice = cachedRange[startLoc:endLoc] |
473 | | - indexSlice.name = name |
474 | | - indexSlice.freq = freq |
475 | | - |
476 | | - return indexSlice |
477 | | - |
478 | 406 | def _mpl_repr(self): |
479 | 407 | # how to represent ourselves to matplotlib |
480 | 408 | return libts.ints_to_pydatetime(self.asi8, self.tz) |
@@ -832,22 +760,19 @@ def _fast_union(self, other): |
832 | 760 | else: |
833 | 761 | left, right = other, self |
834 | 762 |
|
835 | | - left_start, left_end = left[0], left[-1] |
| 763 | + left_end = left[-1] |
836 | 764 | right_end = right[-1] |
837 | 765 |
|
838 | | - if not self.freq._should_cache(): |
839 | | - # concatenate dates |
840 | | - if left_end < right_end: |
841 | | - loc = right.searchsorted(left_end, side='right') |
842 | | - right_chunk = right.values[loc:] |
843 | | - dates = _concat._concat_compat((left.values, right_chunk)) |
844 | | - return self._shallow_copy(dates) |
845 | | - else: |
846 | | - return left |
| 766 | + # TODO: consider re-implementing freq._should_cache for fastpath |
| 767 | + |
| 768 | + # concatenate dates |
| 769 | + if left_end < right_end: |
| 770 | + loc = right.searchsorted(left_end, side='right') |
| 771 | + right_chunk = right.values[loc:] |
| 772 | + dates = _concat._concat_compat((left.values, right_chunk)) |
| 773 | + return self._shallow_copy(dates) |
847 | 774 | else: |
848 | | - return type(self)(start=left_start, |
849 | | - end=max(left_end, right_end), |
850 | | - freq=left.freq) |
| 775 | + return left |
851 | 776 |
|
852 | 777 | def _wrap_union_result(self, other, result): |
853 | 778 | name = self.name if self.name == other.name else None |
@@ -1724,21 +1649,6 @@ def cdate_range(start=None, end=None, periods=None, freq='C', tz=None, |
1724 | 1649 | closed=closed, **kwargs) |
1725 | 1650 |
|
1726 | 1651 |
|
1727 | | -_CACHE_START = Timestamp(datetime(1950, 1, 1)) |
1728 | | -_CACHE_END = Timestamp(datetime(2030, 1, 1)) |
1729 | | - |
1730 | | -_daterange_cache = {} |
1731 | | - |
1732 | | - |
1733 | | -def _naive_in_cache_range(start, end): |
1734 | | - if start is None or end is None: |
1735 | | - return False |
1736 | | - else: |
1737 | | - if start.tzinfo is not None or end.tzinfo is not None: |
1738 | | - return False |
1739 | | - return start > _CACHE_START and end < _CACHE_END |
1740 | | - |
1741 | | - |
1742 | 1652 | def _time_to_micros(time): |
1743 | 1653 | seconds = time.hour * 60 * 60 + 60 * time.minute + time.second |
1744 | 1654 | return 1000000 * seconds + time.microsecond |
0 commit comments