vibespatial.api.geometry_array¶
Attributes¶
Classes¶
A custom data type, to be paired with an ExtensionArray. |
|
Class wrapping a numpy array of Shapely objects. |
Functions¶
|
Check if scalar value is NA-like (None, np.nan or pd.NA). |
|
Convert a list or array of shapely objects to a GeometryArray. |
|
Convert GeometryArray to numpy object array of shapely objects. |
|
Convert a list or array of WKB objects to a GeometryArray. |
|
Convert GeometryArray to a numpy object array of WKB objects. |
|
Convert a list or array of WKT objects to a GeometryArray. |
|
Convert GeometryArray to a numpy object array of WKT objects. |
|
Generate GeometryArray of shapely Point geometries from x, y(, z) coordinates. |
|
Module Contents¶
- vibespatial.api.geometry_array.CRS¶
- vibespatial.api.geometry_array.TransformerFromCRS¶
- vibespatial.api.geometry_array.POLYGON_GEOM_TYPES¶
- vibespatial.api.geometry_array.LINE_GEOM_TYPES¶
- vibespatial.api.geometry_array.POINT_GEOM_TYPES¶
- vibespatial.api.geometry_array.type_mapping¶
- vibespatial.api.geometry_array.geometry_type_ids¶
- vibespatial.api.geometry_array.geometry_type_values¶
- class vibespatial.api.geometry_array.GeometryDtype¶
A custom data type, to be paired with an ExtensionArray.
This enables support for third-party and custom dtypes within the pandas ecosystem. By implementing this interface and pairing it with a custom ExtensionArray, users can create rich data types that integrate cleanly with pandas operations, such as grouping, joining, or aggregation.
See Also¶
- extensions.register_extension_dtype: Register an ExtensionType
with pandas as class decorator.
extensions.ExtensionArray: Abstract base class for custom 1-D array types.
Notes¶
The interface includes the following abstract methods that must be implemented by subclasses:
type
name
construct_array_type
The following attributes and methods influence the behavior of the dtype in pandas operations
_is_numeric
_is_boolean
_get_common_dtype
The na_value class attribute can be used to set the default NA value for this type.
numpy.nanis used by default.ExtensionDtypes are required to be hashable. The base class provides a default implementation, which relies on the
_metadataclass attribute._metadatashould be a tuple containing the strings that define your data type. For example, withPeriodDtypethat’s thefreqattribute.If you have a parametrized dtype you should set the ``_metadata`` class property.
Ideally, the attributes in
_metadatawill match the parameters to yourExtensionDtype.__init__(if any). If any of the attributes in_metadatadon’t implement the standard__eq__or__hash__, the default implementations here will not work.Examples¶
For interaction with Apache Arrow (pyarrow), a
__from_arrow__method can be implemented: this method receives a pyarrow Array or ChunkedArray as only argument and is expected to return the appropriate pandas ExtensionArray for this dtype and the passed values:>>> import pyarrow >>> from pandas.api.extensions import ExtensionArray >>> class ExtensionDtype: ... def __from_arrow__( ... self, array: pyarrow.Array | pyarrow.ChunkedArray ... ) -> ExtensionArray: ...
This class does not inherit from ‘abc.ABCMeta’ for performance reasons. Methods and properties required by the interface raise
pandas.errors.AbstractMethodErrorand noregistermethod is provided for registering virtual subclasses.- type¶
The scalar type for the array, e.g.
intIt’s expected
ExtensionArray[item]returns an instance ofExtensionDtype.typefor scalaritem, assuming that value is valid (not NA). NA values do not need to be instances of type.
- name = 'geometry'¶
A string identifying the data type.
Will be used for display in, e.g.
Series.dtype
- na_value = None¶
Default NA value to use for this type.
This is used in e.g. ExtensionArray.take. This should be the user-facing “boxed” version of the NA value, not the physical NA value for storage. e.g. for JSONArray, this is an empty dictionary.
- classmethod construct_from_string(string)¶
Construct this type from a string.
This is useful mainly for data types that accept parameters. For example, a period dtype accepts a frequency parameter that can be set as
period[h](where H means hourly frequency).By default, in the abstract class, just the name of the type is expected. But subclasses can overwrite this method to accept parameters.
Parameters¶
- stringstr
The name of the type, for example
category.
Returns¶
- ExtensionDtype
Instance of the dtype.
Raises¶
- TypeError
If a class cannot be constructed from this ‘string’.
Examples¶
For extension dtypes with arguments the following may be an adequate implementation.
>>> import re >>> @classmethod ... def construct_from_string(cls, string): ... pattern = re.compile(r"^my_type\[(?P<arg_name>.+)\]$") ... match = pattern.match(string) ... if match: ... return cls(**match.groupdict()) ... else: ... raise TypeError( ... f"Cannot construct a '{cls.__name__}' from '{string}'" ... )
- vibespatial.api.geometry_array.isna(value: None | float | pandas.NA) bool¶
Check if scalar value is NA-like (None, np.nan or pd.NA).
Custom version that only works for scalars (returning True or False), as pd.isna also works for array-like input returning a boolean array.
- vibespatial.api.geometry_array.from_shapely(data, crs: pyproj.CRS | None = None) GeometryArray¶
Convert a list or array of shapely objects to a GeometryArray.
Validates the elements.
Parameters¶
- dataarray-like
list or array of shapely objects
- crsvalue, optional
Coordinate Reference System of the geometry objects. Can be anything accepted by
pyproj.CRS.from_user_input(), such as an authority string (eg “EPSG:4326”) or a WKT string.
- vibespatial.api.geometry_array.to_shapely(geoms: GeometryArray) numpy.ndarray¶
Convert GeometryArray to numpy object array of shapely objects.
- vibespatial.api.geometry_array.from_wkb(data, crs: Any | None = None, on_invalid: Literal['raise', 'warn', 'ignore'] = 'raise') GeometryArray¶
Convert a list or array of WKB objects to a GeometryArray.
Parameters¶
- dataarray-like
list or array of WKB objects
- crsvalue, optional
Coordinate Reference System of the geometry objects. Can be anything accepted by
pyproj.CRS.from_user_input(), such as an authority string (eg “EPSG:4326”) or a WKT string.- on_invalid: {“raise”, “warn”, “ignore”}, default “raise”
raise: an exception will be raised if a WKB input geometry is invalid.
warn: a warning will be raised and invalid WKB geometries will be returned as None.
ignore: invalid WKB geometries will be returned as None without a warning.
fix: an effort is made to fix invalid input geometries (e.g. close unclosed rings). If this is not possible, they are returned as
Nonewithout a warning. Requires GEOS >= 3.11 and shapely >= 2.1.
- vibespatial.api.geometry_array.to_wkb(geoms: GeometryArray, hex: bool = False, **kwargs)¶
Convert GeometryArray to a numpy object array of WKB objects.
- vibespatial.api.geometry_array.from_wkt(data, crs: Any | None = None, on_invalid: Literal['raise', 'warn', 'ignore'] = 'raise') GeometryArray¶
Convert a list or array of WKT objects to a GeometryArray.
Parameters¶
- dataarray-like
list or array of WKT objects
- crsvalue, optional
Coordinate Reference System of the geometry objects. Can be anything accepted by
pyproj.CRS.from_user_input(), such as an authority string (eg “EPSG:4326”) or a WKT string.- on_invalid{“raise”, “warn”, “ignore”}, default “raise”
raise: an exception will be raised if a WKT input geometry is invalid.
warn: a warning will be raised and invalid WKT geometries will be returned as
None.ignore: invalid WKT geometries will be returned as
Nonewithout a warning.fix: an effort is made to fix invalid input geometries (e.g. close unclosed rings). If this is not possible, they are returned as
Nonewithout a warning. Requires GEOS >= 3.11 and shapely >= 2.1.
- vibespatial.api.geometry_array.to_wkt(geoms: GeometryArray, **kwargs)¶
Convert GeometryArray to a numpy object array of WKT objects.
- vibespatial.api.geometry_array.points_from_xy(x: numpy.typing.ArrayLike, y: numpy.typing.ArrayLike, z: numpy.typing.ArrayLike = None, crs: Any | None = None) GeometryArray¶
Generate GeometryArray of shapely Point geometries from x, y(, z) coordinates.
In case of geographic coordinates, it is assumed that longitude is captured by
xcoordinates and latitude byy.Parameters¶
x, y, z : iterable crs : value, optional
Coordinate Reference System of the geometry objects. Can be anything accepted by
pyproj.CRS.from_user_input(), such as an authority string (eg “EPSG:4326”) or a WKT string.Examples¶
>>> import pandas as pd >>> df = pd.DataFrame({'x': [0, 1, 2], 'y': [0, 1, 2], 'z': [0, 1, 2]}) >>> df x y z 0 0 0 0 1 1 1 1 2 2 2 2 >>> geometry = geopandas.points_from_xy(x=[1, 0], y=[0, 1]) >>> geometry = geopandas.points_from_xy(df['x'], df['y'], df['z']) >>> gdf = geopandas.GeoDataFrame( ... df, geometry=geopandas.points_from_xy(df['x'], df['y']))
Having geographic coordinates:
>>> df = pd.DataFrame({'longitude': [-140, 0, 123], 'latitude': [-65, 1, 48]}) >>> df longitude latitude 0 -140 -65 1 0 1 2 123 48 >>> geometry = geopandas.points_from_xy(df.longitude, df.latitude, crs="EPSG:4326")
Returns¶
output : GeometryArray
- class vibespatial.api.geometry_array.GeometryArray(data, crs: Any | None = None)¶
Class wrapping a numpy array of Shapely objects.
It also holds the array-based implementations.
- property crs: pyproj.CRS¶
The Coordinate Reference System (CRS) represented as a
pyproj.CRSobject.Returns a
pyproj.CRSor None. When setting, the value Coordinate Reference System of the geometry objects. Can be anything accepted bypyproj.CRS.from_user_input(), such as an authority string (eg “EPSG:4326”) or a WKT string.
- classmethod from_owned(owned: vibespatial.geometry.owned.OwnedGeometryArray, crs=None) GeometryArray¶
Create a GeometryArray backed by an OwnedGeometryArray without materializing Shapely.
- property sindex: vibespatial.api.sindex.SpatialIndex¶
Spatial index for the geometries in this array.
- property has_sindex: bool¶
Check the existence of the spatial index without generating it.
Use the .sindex attribute on a GeoDataFrame or GeoSeries to generate a spatial index if it does not yet exist, which may take considerable time based on the underlying index implementation.
Note that the underlying spatial index may not be fully initialized until the first use.
See Also¶
GeoDataFrame.has_sindex
Returns¶
- bool
True if the spatial index has been generated or False if not.
- check_geographic_crs(stacklevel: int) None¶
Check CRS and warn if the planar operation is done in a geographic CRS.
- property dtype: GeometryDtype¶
An instance of ExtensionDtype.
See Also¶
api.extensions.ExtensionDtype : Base class for extension dtypes. api.extensions.ExtensionArray : Base class for extension array types. api.extensions.ExtensionArray.dtype : The dtype of an ExtensionArray. Series.dtype : The dtype of a Series. DataFrame.dtype : The dtype of a DataFrame.
Examples¶
>>> pd.array([1, 2, 3]).dtype Int64Dtype()
- owned_flat_sindex()¶
- supports_owned_spatial_input() bool¶
- property is_valid¶
- is_valid_reason()¶
- is_valid_coverage(gap_width: float = 0.0)¶
- invalid_coverage_edges(gap_width: float = 0.0)¶
- property is_empty¶
- property is_simple¶
- property is_ring¶
- property is_closed¶
- property is_ccw¶
- property has_z¶
- property has_m¶
- property geom_type¶
- property area¶
Return the area of the geometries in this array.
Raises a UserWarning if the CRS is geographic, as the area calculation is not accurate in that case.
Note that the area is calculated in the units of the CRS.
Returns¶
- np.ndarray of float
Area of the geometries.
- property length¶
- count_coordinates()¶
- count_geometries()¶
- count_interior_rings()¶
- get_precision()¶
- get_geometry(index)¶
- property boundary: GeometryArray¶
- property centroid: GeometryArray¶
- concave_hull(ratio, allow_holes)¶
- constrained_delaunay_triangles() GeometryArray¶
- property convex_hull: GeometryArray¶
Return the convex hull of the geometries in this array.
- property envelope: GeometryArray¶
Return the envelope of the geometries in this array.
- minimum_rotated_rectangle()¶
Return the minimum rotated rectangle of the geometries in this array.
- property exterior: GeometryArray¶
- extract_unique_points() GeometryArray¶
- offset_curve(distance, quad_segs=8, join_style='round', mitre_limit=5.0)¶
- property interiors: numpy.ndarray¶
- remove_repeated_points(tolerance=0.0) GeometryArray¶
- representative_point() GeometryArray¶
- minimum_bounding_circle() GeometryArray¶
- maximum_inscribed_circle(tolerance) GeometryArray¶
- minimum_bounding_radius()¶
- minimum_clearance()¶
- minimum_clearance_line() GeometryArray¶
- normalize() GeometryArray¶
- orient_polygons(exterior_cw: bool = False) GeometryArray¶
- make_valid(method: Literal['linework', 'structure'] = 'linework', keep_collapsed: bool = True) GeometryArray¶
- reverse() GeometryArray¶
- segmentize(max_segment_length) GeometryArray¶
- force_2d() GeometryArray¶
- force_3d(z=0) GeometryArray¶
- transform(transformation, include_z: bool = False) GeometryArray¶
- line_merge(directed: bool = False) GeometryArray¶
- set_precision(grid_size: float, mode='valid_output')¶
- covers(other)¶
- covered_by(other)¶
- contains(other)¶
- contains_properly(other)¶
- crosses(other)¶
- disjoint(other)¶
- geom_equals(other)¶
- intersects(other)¶
- overlaps(other)¶
- touches(other)¶
- within(other)¶
- dwithin(other, distance)¶
- geom_equals_exact(other, tolerance)¶
- geom_equals_identical(other)¶
- clip_by_rect(xmin, ymin, xmax, ymax) GeometryArray¶
- difference(other, grid_size=None) GeometryArray¶
- intersection(other, grid_size=None) GeometryArray¶
- symmetric_difference(other, grid_size=None) GeometryArray¶
- union(other, grid_size=None) GeometryArray¶
- shortest_line(other) GeometryArray¶
- snap(other, tolerance) GeometryArray¶
- distance(other)¶
- hausdorff_distance(other, **kwargs)¶
- frechet_distance(other, **kwargs)¶
- buffer(distance, quad_segs: int | None = None, **kwargs)¶
- interpolate(distance, normalized: bool = False) GeometryArray¶
Fill NaN values using an interpolation method.
Parameters¶
- methodstr, default ‘linear’
Interpolation technique to use. One of: * ‘linear’: Ignore the index and treat the values as equally spaced. This is the only method supported on MultiIndexes. * ‘time’: Works on daily and higher resolution data to interpolate given length of interval. * ‘index’, ‘values’: use the actual numerical values of the index. * ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’, ‘barycentric’, ‘polynomial’: Passed to scipy.interpolate.interp1d, whereas ‘spline’ is passed to scipy.interpolate.UnivariateSpline. These methods use the numerical values of the index. Both ‘polynomial’ and ‘spline’ require that you also specify an order (int), e.g. arr.interpolate(method=’polynomial’, order=5). * ‘krogh’, ‘piecewise_polynomial’, ‘spline’, ‘pchip’, ‘akima’, ‘cubicspline’: Wrappers around the SciPy interpolation methods of similar names. See Notes. * ‘from_derivatives’: Refers to scipy.interpolate.BPoly.from_derivatives.
- axisint
Axis to interpolate along. For 1-dimensional data, use 0.
- indexIndex
Index to use for interpolation.
- limitint or None
Maximum number of consecutive NaNs to fill. Must be greater than 0.
- limit_direction{‘forward’, ‘backward’, ‘both’}
Consecutive NaNs will be filled in this direction.
- limit_area{‘inside’, ‘outside’} or None
If limit is specified, consecutive NaNs will be filled with this restriction. * None: No fill restriction. * ‘inside’: Only fill NaNs surrounded by valid values (interpolate). * ‘outside’: Only fill NaNs outside valid values (extrapolate).
- copybool
If True, a copy of the object is returned with interpolated values.
- **kwargsoptional
Keyword arguments to pass on to the interpolating function.
Returns¶
- ExtensionArray
An ExtensionArray with interpolated values.
See Also¶
Series.interpolate : Interpolate values in a Series. DataFrame.interpolate : Interpolate values in a DataFrame.
Notes¶
All parameters must be specified as keyword arguments.
The ‘krogh’, ‘piecewise_polynomial’, ‘spline’, ‘pchip’ and ‘akima’ methods are wrappers around the respective SciPy implementations of similar names. These use the actual numerical values of the index.
Examples¶
Interpolating values in a NumPy array:
>>> arr = pd.arrays.NumpyExtensionArray(np.array([0, 1, np.nan, 3])) >>> arr.interpolate( ... method="linear", ... limit=3, ... limit_direction="forward", ... index=pd.Index(range(len(arr))), ... fill_value=1, ... copy=False, ... axis=0, ... limit_area="inside", ... ) <NumpyExtensionArray> [0.0, 1.0, 2.0, 3.0] Length: 4, dtype: float64
Interpolating values in a FloatingArray:
>>> arr = pd.array([1.0, pd.NA, 3.0, 4.0, pd.NA, 6.0], dtype="Float64") >>> arr.interpolate( ... method="linear", ... axis=0, ... index=pd.Index(range(len(arr))), ... limit=None, ... limit_direction="both", ... limit_area=None, ... copy=True, ... ) <FloatingArray> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] Length: 6, dtype: Float64
- simplify(tolerance, preserve_topology: bool = True) GeometryArray¶
- simplify_coverage(tolerance, simplify_boundary: bool = True) GeometryArray¶
- project(other, normalized=False)¶
- relate(other)¶
- relate_pattern(other, pattern)¶
- unary_union()¶
- union_all(method='unary', grid_size=None)¶
- intersection_all()¶
- affine_transform(matrix) GeometryArray¶
- translate(xoff: float = 0.0, yoff: float = 0.0, zoff: float = 0.0) GeometryArray¶
- rotate(angle, origin='center', use_radians: bool = False) GeometryArray¶
- scale(xfact: float = 1.0, yfact: float = 1.0, zfact: float = 1.0, origin='center') GeometryArray¶
- skew(xs: float = 0.0, ys: float = 0.0, origin='center', use_radians: bool = False) GeometryArray¶
- to_crs(crs: Any | None = None, epsg: int | None = None) GeometryArray¶
Transform all geometries to a different coordinate reference system.
Transform all geometries in a GeometryArray to a different coordinate reference system. The
crsattribute on the current GeometryArray must be set. Eithercrsorepsgmay be specified for output.This method will transform all points in all objects. It has no notion of projecting entire geometries. All segments joining points are assumed to be lines in the current projection, not geodesics. Objects crossing the dateline (or other projection boundary) will have undesirable behavior.
Parameters¶
- crspyproj.CRS, optional if epsg is specified
The value can be anything accepted by
pyproj.CRS.from_user_input(), such as an authority string (eg “EPSG:4326”) or a WKT string.- epsgint, optional if crs is specified
EPSG code specifying output projection.
Returns¶
GeometryArray
Examples¶
>>> from shapely.geometry import Point >>> from geopandas.array import from_shapely, to_wkt >>> a = from_shapely([Point(1, 1), Point(2, 2), Point(3, 3)], crs=4326) >>> to_wkt(a) array(['POINT (1 1)', 'POINT (2 2)', 'POINT (3 3)'], dtype=object) >>> a.crs <Geographic 2D CRS: EPSG:4326> Name: WGS 84 Axis Info [ellipsoidal]: - Lat[north]: Geodetic latitude (degree) - Lon[east]: Geodetic longitude (degree) Area of Use: - name: World - bounds: (-180.0, -90.0, 180.0, 90.0) Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
>>> a = a.to_crs(3857) >>> to_wkt(a) array(['POINT (111319.490793 111325.142866)', 'POINT (222638.981587 222684.208506)', 'POINT (333958.47238 334111.171402)'], dtype=object) >>> a.crs <Projected CRS: EPSG:3857> Name: WGS 84 / Pseudo-Mercator Axis Info [cartesian]: - X[east]: Easting (metre) - Y[north]: Northing (metre) Area of Use: - name: World - 85°S to 85°N - bounds: (-180.0, -85.06, 180.0, 85.06) Coordinate Operation: - name: Popular Visualisation Pseudo-Mercator - method: Popular Visualisation Pseudo Mercator Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
- estimate_utm_crs(datum_name: str = 'WGS 84') pyproj.CRS¶
Return the estimated UTM CRS based on the bounds of the dataset.
Added in version 0.9.
Note
Requires pyproj 3+
Parameters¶
- datum_namestr, optional
The name of the datum to use in the query. Default is WGS 84.
Returns¶
pyproj.CRS
Examples¶
>>> import geodatasets >>> df = geopandas.read_file( ... geodatasets.get_path("geoda.chicago_commpop") ... ) >>> df.geometry.values.estimate_utm_crs() <Derived Projected CRS: EPSG:32616> Name: WGS 84 / UTM zone 16N Axis Info [cartesian]: - E[east]: Easting (metre) - N[north]: Northing (metre) Area of Use: - name: Between 90°W and 84°W, northern hemisphere between equator and 84°N,... - bounds: (-90.0, 0.0, -84.0, 84.0) Coordinate Operation: - name: UTM zone 16N - method: Transverse Mercator Datum: World Geodetic System 1984 ensemble - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
- property x¶
Return the x location of point geometries in a GeoSeries.
- property y¶
Return the y location of point geometries in a GeoSeries.
- property z¶
Return the z location of point geometries in a GeoSeries.
- property m¶
Return the m coordinate of point geometries in a GeoSeries.
- property bounds¶
- property total_bounds¶
- property size¶
The number of elements in the array.
- property shape: tuple¶
Return a tuple of the array dimensions.
See Also¶
numpy.ndarray.shape : Similar attribute which returns the shape of an array. DataFrame.shape : Return a tuple representing the dimensionality of the
DataFrame.
Series.shape : Return a tuple representing the dimensionality of the Series.
Examples¶
>>> arr = pd.array([1, 2, 3]) >>> arr.shape (3,)
- property ndim: int¶
Extension Arrays are only allowed to be 1-dimensional.
See Also¶
ExtensionArray.shape: Return a tuple of the array dimensions. ExtensionArray.size: The number of elements in the array.
Examples¶
>>> arr = pd.array([1, 2, 3]) >>> arr.ndim 1
- copy(*args, **kwargs) GeometryArray¶
Return a copy of the array.
This method creates a copy of the ExtensionArray where modifying the data in the copy will not affect the original array. This is useful when you want to manipulate data without altering the original dataset.
Returns¶
- ExtensionArray
A new ExtensionArray object that is a copy of the current instance.
See Also¶
DataFrame.copy : Return a copy of the DataFrame. Series.copy : Return a copy of the Series.
Examples¶
>>> arr = pd.array([1, 2, 3]) >>> arr2 = arr.copy() >>> arr[0] = 2 >>> arr2 <IntegerArray> [1, 2, 3] Length: 3, dtype: Int64
- take(indices, allow_fill: bool = False, fill_value=None) GeometryArray¶
Take elements from an array.
Parameters¶
- indicessequence of int or one-dimensional np.ndarray of int
Indices to be taken.
- allow_fillbool, default False
How to handle negative values in indices.
False: negative values in indices indicate positional indices from the right (the default). This is similar to
numpy.take().True: negative values in indices indicate missing values. These values are set to fill_value. Any other other negative values raise a
ValueError.
- fill_valueany, optional
Fill value to use for NA-indices when allow_fill is True. This may be
None, in which case the default NA value for the type,self.dtype.na_value, is used.For many ExtensionArrays, there will be two representations of fill_value: a user-facing “boxed” scalar, and a low-level physical NA value. fill_value should be the user-facing version, and the implementation should handle translating that to the physical version for processing the take if necessary.
Returns¶
- ExtensionArray
An array formed with selected indices.
Raises¶
- IndexError
When the indices are out of bounds for the array.
- ValueError
When indices contains negative values other than
-1and allow_fill is True.
See Also¶
numpy.take : Take elements from an array along an axis. api.extensions.take : Take elements from an array.
Notes¶
ExtensionArray.take is called by
Series.__getitem__,.loc,iloc, when indices is a sequence of values. Additionally, it’s called bySeries.reindex(), or any other method that causes realignment, with a fill_value.Examples¶
Here’s an example implementation, which relies on casting the extension array to object dtype. This uses the helper method
pandas.api.extensions.take().def take(self, indices, allow_fill=False, fill_value=None): from pandas.api.extensions import take # If the ExtensionArray is backed by an ndarray, then # just pass that here instead of coercing to object. data = self.astype(object) if allow_fill and fill_value is None: fill_value = self.dtype.na_value # fill value should always be translated from the scalar # type for the array, to the physical storage type for # the data, before passing to take. result = take( data, indices, fill_value=fill_value, allow_fill=allow_fill ) return self._from_sequence(result, dtype=self.dtype)
- fillna(value=None, method=None, limit: int | None = None, copy: bool = True) GeometryArray¶
Fill NA values with geometry (or geometries) or using the specified method.
Parameters¶
- valueshapely geometry object or GeometryArray
If a geometry value is passed it is used to fill all missing values. Alternatively, a GeometryArray ‘value’ can be given. It’s expected that the GeometryArray has the same length as ‘self’.
- method{‘backfill’, ‘bfill’, ‘pad’, ‘ffill’, None}, default None
Method to use for filling holes in reindexed Series pad / ffill: propagate last valid observation forward to next valid backfill / bfill: use NEXT valid observation to fill gap
- limitint, default None
The maximum number of entries where NA values will be filled.
- copybool, default True
Whether to make a copy of the data before filling. If False, then the original should be modified and no new memory should be allocated.
Returns¶
GeometryArray
- astype(dtype, copy: bool = True) numpy.ndarray¶
Cast to a NumPy array with ‘dtype’.
Parameters¶
- dtypestr or dtype
Typecode or data-type to which the array is cast.
- copybool, default True
Whether to copy the data, even if not necessary. If False, a copy is made only if the old dtype does not match the new dtype.
Returns¶
- arrayndarray
NumPy ndarray with ‘dtype’ for its dtype.
- isna() numpy.ndarray¶
Boolean NumPy array indicating if each value is missing.
- value_counts(dropna: bool = True) pandas.Series¶
Compute a histogram of the counts of non-null values.
Parameters¶
- dropnabool, default True
Don’t include counts of NaN
Returns¶
pd.Series
- unique() pandas.api.extensions.ExtensionArray¶
Compute the ExtensionArray of unique values.
Returns¶
uniques : ExtensionArray
- property nbytes¶
The number of bytes needed to store this object in memory.
See Also¶
ExtensionArray.shape: Return a tuple of the array dimensions. ExtensionArray.size: The number of elements in the array.
Examples¶
>>> pd.array([1, 2, 3]).nbytes 27
- shift(periods: int = 1, fill_value: Any | None = None) GeometryArray¶
Shift values by desired number.
Newly introduced missing values are filled with
self.dtype.na_value.Parameters¶
- periodsint, default 1
The number of periods to shift. Negative values are allowed for shifting backwards.
- fill_valueobject, optional (default None)
The scalar value to use for newly introduced missing values. The default is
self.dtype.na_value.
Returns¶
- GeometryArray
Shifted.
Notes¶
If
selfis empty orperiodsis 0, a copy ofselfis returned.If
periods > len(self), then an array of size len(self) is returned, with all values filled withself.dtype.na_value.
- argmin(skipna: bool = True) int¶
Return the index of minimum value.
In case of multiple occurrences of the minimum value, the index corresponding to the first occurrence is returned.
Parameters¶
skipna : bool, default True
Returns¶
int
See Also¶
ExtensionArray.argmax : Return the index of the maximum value.
Examples¶
>>> arr = pd.array([3, 1, 2, 5, 4]) >>> arr.argmin() np.int64(1)
- argmax(skipna: bool = True) int¶
Return the index of maximum value.
In case of multiple occurrences of the maximum value, the index corresponding to the first occurrence is returned.
Parameters¶
skipna : bool, default True
Returns¶
int
See Also¶
ExtensionArray.argmin : Return the index of the minimum value.
Examples¶
>>> arr = pd.array([3, 1, 2, 5, 4]) >>> arr.argmax() np.int64(3)
- vibespatial.api.geometry_array.transform(data, func) numpy.ndarray¶