Custom property-like object. A descriptor for accessors. Parameters ---------- name : str Namespace that will be accessed under, e.g. ``df.foo``. accessor : cls Class with the extension methods. Notes ----- For accessor, The class's __init__ me
| 200 | |
| 201 | |
| 202 | class Accessor: |
| 203 | """ |
| 204 | Custom property-like object. |
| 205 | |
| 206 | A descriptor for accessors. |
| 207 | |
| 208 | Parameters |
| 209 | ---------- |
| 210 | name : str |
| 211 | Namespace that will be accessed under, e.g. ``df.foo``. |
| 212 | accessor : cls |
| 213 | Class with the extension methods. |
| 214 | |
| 215 | Notes |
| 216 | ----- |
| 217 | For accessor, The class's __init__ method assumes that one of |
| 218 | ``Series``, ``DataFrame`` or ``Index`` as the |
| 219 | single argument ``data``. |
| 220 | """ |
| 221 | |
| 222 | def __init__(self, name: str, accessor) -> None: |
| 223 | self._name = name |
| 224 | self._accessor = accessor |
| 225 | |
| 226 | def __get__(self, obj, cls): |
| 227 | if obj is None: |
| 228 | # we're accessing the attribute of the class, i.e., Dataset.geo |
| 229 | return self._accessor |
| 230 | return self._accessor(obj) |
| 231 | |
| 232 | |
| 233 | # Alias kept for downstream libraries |