GeoPandas Compatibility#
cuSpatial supports any geometry format supported by GeoPandas. Load geometry information from a GeoPandas.GeoSeries or GeoPandas.GeoDataFrame.
>>> gpdf = geopandas.read_file('arbitrary.txt')
cugpdf = cuspatial.from_geopandas(gpdf)
or
>>> cugpdf = cuspatial.GeoDataFrame(gpdf)
- class cuspatial.GeoDataFrame(data: Optional[geopandas.geodataframe.GeoDataFrame] = None)#
A GPU GeoDataFrame object.
Methods
groupby
(*args, **kwargs)Group DataFrame using a mapper or by a Series of columns.
to_geopandas
([nullable])Returns a new GeoPandas GeoDataFrame object from the coordinates in the cuspatial GeoDataFrame.
to_pandas
([nullable])Calls self.to_geopandas, converting GeoSeries columns into GeoPandas columns and cudf.Series columns into pandas.Series columns, and returning a pandas.DataFrame.
cummax
cummin
cumprod
cumsum
- cummax(axis=None, *args, **kwargs)#
Return cumulative max of the IndexedFrame.
- Parameters
- axis: {index (0), columns(1)}
Axis for the function to be applied on.
- skipna: bool, default True
Exclude NA/null values. If an entire row/column is NA, the result will be NA.
- Returns
- IndexedFrame
Examples
Series
>>> import cudf >>> ser = cudf.Series([1, 5, 2, 4, 3]) >>> ser.cumsum() 0 1 1 6 2 8 3 12 4 15
DataFrame
>>> import cudf >>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]}) >>> s.cumsum() a b 0 1 7 1 3 15 2 6 24 3 10 34
- cummin(axis=None, *args, **kwargs)#
Return cumulative min of the IndexedFrame.
- Parameters
- axis: {index (0), columns(1)}
Axis for the function to be applied on.
- skipna: bool, default True
Exclude NA/null values. If an entire row/column is NA, the result will be NA.
- Returns
- IndexedFrame
Examples
Series
>>> import cudf >>> ser = cudf.Series([1, 5, 2, 4, 3]) >>> ser.cumsum() 0 1 1 6 2 8 3 12 4 15
DataFrame
>>> import cudf >>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]}) >>> s.cumsum() a b 0 1 7 1 3 15 2 6 24 3 10 34
- cumprod(axis=None, *args, **kwargs)#
Return cumulative product of the IndexedFrame.
- Parameters
- axis: {index (0), columns(1)}
Axis for the function to be applied on.
- skipna: bool, default True
Exclude NA/null values. If an entire row/column is NA, the result will be NA.
- Returns
- IndexedFrame
Examples
Series
>>> import cudf >>> ser = cudf.Series([1, 5, 2, 4, 3]) >>> ser.cumsum() 0 1 1 6 2 8 3 12 4 15
DataFrame
>>> import cudf >>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]}) >>> s.cumsum() a b 0 1 7 1 3 15 2 6 24 3 10 34
- cumsum(axis=None, *args, **kwargs)#
Return cumulative sum of the IndexedFrame.
- Parameters
- axis: {index (0), columns(1)}
Axis for the function to be applied on.
- skipna: bool, default True
Exclude NA/null values. If an entire row/column is NA, the result will be NA.
- Returns
- IndexedFrame
Examples
Series
>>> import cudf >>> ser = cudf.Series([1, 5, 2, 4, 3]) >>> ser.cumsum() 0 1 1 6 2 8 3 12 4 15
DataFrame
>>> import cudf >>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]}) >>> s.cumsum() a b 0 1 7 1 3 15 2 6 24 3 10 34
- groupby(*args, **kwargs)#
Group DataFrame using a mapper or by a Series of columns.
A groupby operation involves some combination of splitting the object, applying a function, and combining the results. This can be used to group large amounts of data and compute operations on these groups.
- Parameters
- bymapping, function, label, or list of labels
Used to determine the groups for the groupby. If by is a function, it’s called on each value of the object’s index. If a dict or Series is passed, the Series or dict VALUES will be used to determine the groups (the Series’ values are first aligned; see .align() method). If a cupy array is passed, the values are used as-is determine the groups. A label or list of labels may be passed to group by the columns in self. Notice that a tuple is interpreted as a (single) key.
- levelint, level name, or sequence of such, default None
If the axis is a MultiIndex (hierarchical), group by a particular level or levels.
- as_indexbool, default True
For aggregated output, return object with group labels as the index. Only relevant for DataFrame input. as_index=False is effectively “SQL-style” grouped output.
- sortbool, default False
Sort result by group key. Differ from Pandas, cudf defaults to
False
for better performance. Note this does not influence the order of observations within each group. Groupby preserves the order of rows within each group.- dropnabool, optional
If True (default), do not include the “null” group.
- Returns
- DataFrameGroupBy
Returns a groupby object that contains information about the groups.
Examples
>>> import cudf >>> import pandas as pd >>> df = cudf.DataFrame({ ... 'Animal': ['Falcon', 'Falcon', 'Parrot', 'Parrot'], ... 'Max Speed': [380., 370., 24., 26.], ... }) >>> df Animal Max Speed 0 Falcon 380.0 1 Falcon 370.0 2 Parrot 24.0 3 Parrot 26.0 >>> df.groupby(['Animal']).mean() Max Speed Animal Falcon 375.0 Parrot 25.0
>>> arrays = [['Falcon', 'Falcon', 'Parrot', 'Parrot'], ... ['Captive', 'Wild', 'Captive', 'Wild']] >>> index = pd.MultiIndex.from_arrays(arrays, names=('Animal', 'Type')) >>> df = cudf.DataFrame({'Max Speed': [390., 350., 30., 20.]}, ... index=index) >>> df Max Speed Animal Type Falcon Captive 390.0 Wild 350.0 Parrot Captive 30.0 Wild 20.0 >>> df.groupby(level=0).mean() Max Speed Animal Falcon 370.0 Parrot 25.0 >>> df.groupby(level="Type").mean() Max Speed Type Wild 185.0 Captive 210.0
- to_geopandas(nullable=False)#
Returns a new GeoPandas GeoDataFrame object from the coordinates in the cuspatial GeoDataFrame.
- Parameters
- nullable: matches the cudf `to_pandas` signature, not yet supported.
- to_pandas(nullable=False)#
Calls self.to_geopandas, converting GeoSeries columns into GeoPandas columns and cudf.Series columns into pandas.Series columns, and returning a pandas.DataFrame.
- Parameters
- nullable: matches the cudf `to_pandas` signature, not yet supported.
- class cuspatial.GeoSeries(data: geopandas.geoseries.GeoSeries, index: Optional[Union[cudf.core.index.Index, pandas.core.indexes.base.Index]] = None, dtype=None, name=None, nan_as_null=True)#
cuspatial.GeoSeries enables GPU-backed storage and computation of shapely-like objects. Our goal is to give feature parity with GeoPandas. At this time, only from_geopandas and to_geopandas are directly supported. cuspatial GIS, indexing, and trajectory functions depend on the arrays stored in the GeoArrowBuffers object, accessible with the points, multipoints, lines, and polygons accessors.
>>> cuseries.points xy: 0 -1.0 1 0.0 dtype: float64
- Attributes
lines
Access the LineArray of the underlying GeoArrowBuffers.
multipoints
Access the MultiPointArray of the underlying GeoArrowBuffers.
points
Access the PointsArray of the underlying GeoArrowBuffers.
polygons
Access the PolygonArray of the underlying GeoArrowBuffers.
Methods
to_geopandas
([nullable])Returns a new GeoPandas GeoSeries object from the coordinates in the cuspatial GeoSeries.
Treats to_pandas and to_geopandas as the same call, which improves compatibility with pandas.
cummax
cummin
cumprod
cumsum
- cummax(axis=None, *args, **kwargs)#
Return cumulative max of the IndexedFrame.
- Parameters
- axis: {index (0), columns(1)}
Axis for the function to be applied on.
- skipna: bool, default True
Exclude NA/null values. If an entire row/column is NA, the result will be NA.
- Returns
- IndexedFrame
Examples
Series
>>> import cudf >>> ser = cudf.Series([1, 5, 2, 4, 3]) >>> ser.cumsum() 0 1 1 6 2 8 3 12 4 15
DataFrame
>>> import cudf >>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]}) >>> s.cumsum() a b 0 1 7 1 3 15 2 6 24 3 10 34
- cummin(axis=None, *args, **kwargs)#
Return cumulative min of the IndexedFrame.
- Parameters
- axis: {index (0), columns(1)}
Axis for the function to be applied on.
- skipna: bool, default True
Exclude NA/null values. If an entire row/column is NA, the result will be NA.
- Returns
- IndexedFrame
Examples
Series
>>> import cudf >>> ser = cudf.Series([1, 5, 2, 4, 3]) >>> ser.cumsum() 0 1 1 6 2 8 3 12 4 15
DataFrame
>>> import cudf >>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]}) >>> s.cumsum() a b 0 1 7 1 3 15 2 6 24 3 10 34
- cumprod(axis=None, *args, **kwargs)#
Return cumulative product of the IndexedFrame.
- Parameters
- axis: {index (0), columns(1)}
Axis for the function to be applied on.
- skipna: bool, default True
Exclude NA/null values. If an entire row/column is NA, the result will be NA.
- Returns
- IndexedFrame
Examples
Series
>>> import cudf >>> ser = cudf.Series([1, 5, 2, 4, 3]) >>> ser.cumsum() 0 1 1 6 2 8 3 12 4 15
DataFrame
>>> import cudf >>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]}) >>> s.cumsum() a b 0 1 7 1 3 15 2 6 24 3 10 34
- cumsum(axis=None, *args, **kwargs)#
Return cumulative sum of the IndexedFrame.
- Parameters
- axis: {index (0), columns(1)}
Axis for the function to be applied on.
- skipna: bool, default True
Exclude NA/null values. If an entire row/column is NA, the result will be NA.
- Returns
- IndexedFrame
Examples
Series
>>> import cudf >>> ser = cudf.Series([1, 5, 2, 4, 3]) >>> ser.cumsum() 0 1 1 6 2 8 3 12 4 15
DataFrame
>>> import cudf >>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]}) >>> s.cumsum() a b 0 1 7 1 3 15 2 6 24 3 10 34
- property lines#
Access the LineArray of the underlying GeoArrowBuffers.
- property multipoints#
Access the MultiPointArray of the underlying GeoArrowBuffers.
- property points#
Access the PointsArray of the underlying GeoArrowBuffers.
- property polygons#
Access the PolygonArray of the underlying GeoArrowBuffers.
- to_geopandas(nullable=False)#
Returns a new GeoPandas GeoSeries object from the coordinates in the cuspatial GeoSeries.
- to_pandas()#
Treats to_pandas and to_geopandas as the same call, which improves compatibility with pandas.