pandera.geopandas.GeoDataFrameModelΒΆ

class pandera.geopandas.GeoDataFrameModel(*args, **kwargs)[source]ΒΆ

Class-based schema for geopandas.GeoDataFrame data.

Inherits DataFrameModel and reuses the same schema-building and validation logic. Use this model when validate(), example(), empty(), and strategy() should return a geopandas.GeoDataFrame (preserving geometry columns and CRS metadata) even if the pandas backend produced a plain pandas.DataFrame.

Requires the geopandas extra. Use with pandera.typing.geopandas.GeoDataFrame for validate-on-init, e.g. GeoDataFrame[MyModel](...).

Validate a DataFrame based on the schema specification.

Parameters:
  • check_obj (pd.DataFrame) – the dataframe to be validated.

  • head – validate the first n rows. Rows overlapping with tail or sample are de-duplicated.

  • tail – validate the last n rows. Rows overlapping with head or sample are de-duplicated.

  • sample – validate a random sample of n rows. Rows overlapping with head or tail are de-duplicated.

  • random_state – random seed for the sample argument.

  • lazy – if True, lazily evaluates dataframe against all validation checks and raises a SchemaErrors. Otherwise, raise SchemaError as soon as one occurs.

  • inplace – if True, applies coercion to the object of validation, otherwise creates a copy of the data.

Returns:

validated DataFrame

Raises:

SchemaError – when DataFrame violates built-in or custom checks.

Methods

classmethod build_schema_(**kwargs)[source]ΒΆ

Build a GeoDataFrameSchema from the model definition.

Return type:

GeoDataFrameSchema

classmethod empty(*_args)[source]ΒΆ

Create an empty geopandas.GeoDataFrame with this schema.

Return type:

GeoDataFrameT[Self]

classmethod example(cls, **kwargs)[source]ΒΆ

Generate an example of this data model specification.

Return type:

GeoDataFrameT[Self]

classmethod strategy(cls, **kwargs)[source]ΒΆ

Create a data synthesis strategy.

classmethod validate(check_obj, head=None, tail=None, sample=None, random_state=None, lazy=False, inplace=False)[source]ΒΆ

Validate a DataFrame based on the schema specification.

Parameters:
  • check_obj (pd.DataFrame) – the dataframe to be validated.

  • head (int | None) – validate the first n rows. Rows overlapping with tail or sample are de-duplicated.

  • tail (int | None) – validate the last n rows. Rows overlapping with head or sample are de-duplicated.

  • sample (int | None) – validate a random sample of n rows. Rows overlapping with head or tail are de-duplicated.

  • random_state (int | None) – random seed for the sample argument.

  • lazy (bool) – if True, lazily evaluates dataframe against all validation checks and raises a SchemaErrors. Otherwise, raise SchemaError as soon as one occurs.

  • inplace (bool) – if True, applies coercion to the object of validation, otherwise creates a copy of the data.

Return type:

GeoDataFrameT[Self]

Returns:

validated DataFrame

Raises:

SchemaError – when DataFrame violates built-in or custom checks.