File: accessors.py

package info (click to toggle)
python-geopandas 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,752 kB
  • sloc: python: 26,021; makefile: 147; sh: 25
file content (26 lines) | stat: -rw-r--r-- 750 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""Accessors for accessing GeoPandas functionality via pandas extension dtypes."""

import pandas.api.extensions

from geopandas import GeoSeries
from geopandas.array import GeometryDtype


@pandas.api.extensions.register_series_accessor("geo")
class GeoSeriesAccessor:
    """Series.geo accessor to expose GeoSeries methods on pandas Series.

    Parameters
    ----------
    series : pandas.Series
        A Series with geometry dtype.
    """

    def __init__(self, series):
        if not isinstance(series.dtype, GeometryDtype):
            raise AttributeError("Can only use .geo accessor with GeometryDtype values")

        self._geoseries = GeoSeries(series)

    def __getattr__(self, name):
        return getattr(self._geoseries, name)