|
27 | 27 | from pandas.core.indexing import _check_bool_indexer, _maybe_convert_indices |
28 | 28 | from pandas.core import generic, base |
29 | 29 | from pandas.core.internals import SingleBlockManager |
30 | | -from pandas.core.categorical import Categorical |
| 30 | +from pandas.core.categorical import Categorical, CategoricalAccessor |
| 31 | +from pandas.core.strings import StringMethods |
| 32 | +from pandas.tseries.common import (maybe_to_datetimelike, |
| 33 | + CombinedDatetimelikeProperties) |
31 | 34 | from pandas.tseries.index import DatetimeIndex |
32 | 35 | from pandas.tseries.tdi import TimedeltaIndex |
33 | 36 | from pandas.tseries.period import PeriodIndex, Period |
@@ -2452,11 +2455,6 @@ def asof(self, where): |
2452 | 2455 | new_values = com.take_1d(values, locs) |
2453 | 2456 | return self._constructor(new_values, index=where).__finalize__(self) |
2454 | 2457 |
|
2455 | | - @cache_readonly |
2456 | | - def str(self): |
2457 | | - from pandas.core.strings import StringMethods |
2458 | | - return StringMethods(self) |
2459 | | - |
2460 | 2458 | def to_timestamp(self, freq=None, how='start', copy=True): |
2461 | 2459 | """ |
2462 | 2460 | Cast to datetimeindex of timestamps, at *beginning* of period |
@@ -2502,27 +2500,35 @@ def to_period(self, freq=None, copy=True): |
2502 | 2500 | return self._constructor(new_values, |
2503 | 2501 | index=new_index).__finalize__(self) |
2504 | 2502 |
|
| 2503 | + #------------------------------------------------------------------------------ |
| 2504 | + # string methods |
| 2505 | + |
| 2506 | + def _make_str_accessor(self): |
| 2507 | + return StringMethods(self) |
| 2508 | + |
| 2509 | + str = base.AccessorProperty(StringMethods, _make_str_accessor) |
| 2510 | + |
2505 | 2511 | #------------------------------------------------------------------------------ |
2506 | 2512 | # Datetimelike delegation methods |
2507 | 2513 |
|
2508 | | - @cache_readonly |
2509 | | - def dt(self): |
2510 | | - from pandas.tseries.common import maybe_to_datetimelike |
| 2514 | + def _make_dt_accessor(self): |
2511 | 2515 | try: |
2512 | 2516 | return maybe_to_datetimelike(self) |
2513 | 2517 | except (Exception): |
2514 | 2518 | raise TypeError("Can only use .dt accessor with datetimelike values") |
2515 | 2519 |
|
| 2520 | + dt = base.AccessorProperty(CombinedDatetimelikeProperties, _make_dt_accessor) |
| 2521 | + |
2516 | 2522 | #------------------------------------------------------------------------------ |
2517 | 2523 | # Categorical methods |
2518 | 2524 |
|
2519 | | - @cache_readonly |
2520 | | - def cat(self): |
2521 | | - from pandas.core.categorical import CategoricalAccessor |
| 2525 | + def _make_cat_accessor(self): |
2522 | 2526 | if not com.is_categorical_dtype(self.dtype): |
2523 | 2527 | raise TypeError("Can only use .cat accessor with a 'category' dtype") |
2524 | 2528 | return CategoricalAccessor(self.values, self.index) |
2525 | 2529 |
|
| 2530 | + cat = base.AccessorProperty(CategoricalAccessor, _make_cat_accessor) |
| 2531 | + |
2526 | 2532 | Series._setup_axes(['index'], info_axis=0, stat_axis=0, |
2527 | 2533 | aliases={'rows': 0}) |
2528 | 2534 | Series._add_numeric_operations() |
|
0 commit comments