|
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 |
@@ -207,6 +183,7 @@ class SelectableColumn: |
207 | 183 | notna = selector_wrapper(pd.Series, "notna") |
208 | 184 | notnull = selector_wrapper(pd.Series, "notnull") |
209 | 185 | isin = selector_wrapper(pd.Series, "isin") |
| 186 | + between = selector_wrapper(pd.Series, "between") |
210 | 187 |
|
211 | 188 | def __init__(self, parent, series=None): |
212 | 189 | # if accessed as the series accessor, parent is the series |
@@ -252,3 +229,37 @@ def __getitem__(self, key): |
252 | 229 | @property |
253 | 230 | def index(self): |
254 | 231 | return SelectableIndex(self._frame) |
| 232 | + |
| 233 | + |
| 234 | +class SelectDatetimeProperties(DatetimeProperties): |
| 235 | + def __init__(self, parent, *args, **kwargs): |
| 236 | + # datetime properties holds an attribute _parent |
| 237 | + # we need to add the parent_frame (or series) to the subclass instances |
| 238 | + self._parent_frame = parent |
| 239 | + super().__init__(*args, **kwargs) |
| 240 | + |
| 241 | + def __getattribute__(self, attr): |
| 242 | + if ( |
| 243 | + not attr.startswith("_") |
| 244 | + and inspect.isroutine( # noqa |
| 245 | + getattr(DatetimeProperties, attr, None) |
| 246 | + ) |
| 247 | + and attr not in _date_boolean_methods |
| 248 | + ): # noqa |
| 249 | + raise NotImplementedError( |
| 250 | + "Boolean selection with this method " "does not make sense." |
| 251 | + ) |
| 252 | + elif attr in _date_boolean_methods: |
| 253 | + idx = super().__getattribute__(attr) |
| 254 | + return self._parent_frame.loc[idx] |
| 255 | + else: |
| 256 | + got_attr = super().__getattribute__(attr) |
| 257 | + # this allows things like dt.day, dt.month to be selectable |
| 258 | + # for the parent frame. assumes they're all properties. |
| 259 | + if ( |
| 260 | + isinstance(got_attr, pd.Series) |
| 261 | + and not attr.startswith('_') |
| 262 | + and isinstance(getattr(self.__class__, attr), property) |
| 263 | + ): |
| 264 | + return SelectableColumn(self._parent_frame, got_attr) |
| 265 | + return got_attr |
0 commit comments