|
2 | 2 | import operator
|
3 | 3 | from functools import wraps
|
4 | 4 |
|
| 5 | +import numpy as np |
5 | 6 | import pandas as pd
|
6 | 7 | from pandas.core.accessor import CachedAccessor
|
7 | 8 | from pandas.core.indexes.accessors import (
|
@@ -70,31 +71,6 @@ def _wrap_result(self, *args, **kwargs):
|
70 | 71 | return self._parent_frame.loc[bool_idx]
|
71 | 72 |
|
72 | 73 |
|
73 |
| -class SelectDatetimeProperties(DatetimeProperties): |
74 |
| - def __init__(self, parent, *args, **kwargs): |
75 |
| - # datetime properties holds an attribute _parent |
76 |
| - # we need to add the parent_frame (or series) to the subclass instances |
77 |
| - self._parent_frame = parent |
78 |
| - super().__init__(*args, **kwargs) |
79 |
| - |
80 |
| - def __getattribute__(self, attr): |
81 |
| - if ( |
82 |
| - not attr.startswith("_") |
83 |
| - and inspect.isroutine( # noqa |
84 |
| - getattr(DatetimeProperties, attr, None) |
85 |
| - ) |
86 |
| - and attr not in _date_boolean_methods |
87 |
| - ): # noqa |
88 |
| - raise NotImplementedError( |
89 |
| - "Boolean selection with this method " "does not make sense." |
90 |
| - ) |
91 |
| - elif attr in _date_boolean_methods: |
92 |
| - idx = super().__getattribute__(attr) |
93 |
| - return self._parent_frame.loc[idx] |
94 |
| - else: |
95 |
| - return super().__getattribute__(attr) |
96 |
| - |
97 |
| - |
98 | 74 | class SelectPeriodProperties(PeriodProperties):
|
99 | 75 | def __init__(self, parent, *args, **kwargs):
|
100 | 76 | self._parent_frame = parent
|
@@ -252,3 +228,37 @@ def __getitem__(self, key):
|
252 | 228 | @property
|
253 | 229 | def index(self):
|
254 | 230 | return SelectableIndex(self._frame)
|
| 231 | + |
| 232 | + |
| 233 | +class SelectDatetimeProperties(DatetimeProperties): |
| 234 | + def __init__(self, parent, *args, **kwargs): |
| 235 | + # datetime properties holds an attribute _parent |
| 236 | + # we need to add the parent_frame (or series) to the subclass instances |
| 237 | + self._parent_frame = parent |
| 238 | + super().__init__(*args, **kwargs) |
| 239 | + |
| 240 | + def __getattribute__(self, attr): |
| 241 | + if ( |
| 242 | + not attr.startswith("_") |
| 243 | + and inspect.isroutine( # noqa |
| 244 | + getattr(DatetimeProperties, attr, None) |
| 245 | + ) |
| 246 | + and attr not in _date_boolean_methods |
| 247 | + ): # noqa |
| 248 | + raise NotImplementedError( |
| 249 | + "Boolean selection with this method " "does not make sense." |
| 250 | + ) |
| 251 | + elif attr in _date_boolean_methods: |
| 252 | + idx = super().__getattribute__(attr) |
| 253 | + return self._parent_frame.loc[idx] |
| 254 | + else: |
| 255 | + got_attr = super().__getattribute__(attr) |
| 256 | + # this allows things like dt.day, dt.month to be selectable |
| 257 | + # for the parent frame. assumes they're all properties. |
| 258 | + if ( |
| 259 | + isinstance(got_attr, pd.Series) |
| 260 | + and not attr.startswith('_') |
| 261 | + and isinstance(getattr(self.__class__, attr), property) |
| 262 | + ): |
| 263 | + return SelectableColumn(self._parent_frame, got_attr) |
| 264 | + return got_attr |
0 commit comments