hydromt.data_catalog.drivers.PandasDriver#

pydantic model hydromt.data_catalog.drivers.PandasDriver[source]#

Driver for DataFrames using the pandas library: pandas.

Supports reading and writing csv, excel (xls, xlsx), parquet, fixed width formatted files (fwf) using pandas.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

name: ClassVar[str] = 'pandas'#
supports_writing: ClassVar[bool] = True#

“Whether the driver supports writing data.

read(uris: list[str], *, handle_nodata: NoDataStrategy = NoDataStrategy.RAISE, variables: str | List[str] | None = None) DataFrame[source]#

Read tabular data into a pandas DataFrame using the pandas library.

Supports multiple file formats including CSV, Parquet, Excel (xls, xlsx), and fixed-width text files (fwf). Applies hydromt’s NoDataStrategy if no records are found. Column selection can be controlled through the variables argument. Only a single file can be read per call.

Parameters:
  • uris (list[str]) – List containing a single URI to read from. Multiple files are not supported.

  • handle_nodata (NoDataStrategy, optional) – Strategy to handle missing or empty data. Default is NoDataStrategy.RAISE.

  • variables (Variables | None, optional) – List of columns to read from the file. Ignored if None.

Returns:

The loaded DataFrame containing the data from the source file.

Return type:

pd.DataFrame

Raises:
  • ValueError – If multiple files are provided or the file extension is unsupported.

  • IOError – If the file extension is not recognized.

write(path: Path | str, data: DataFrame, *, write_kwargs: dict[str, Any] | None = None) Path[source]#

Write a pandas DataFrame to disk using the pandas library.

Supports writing to common tabular formats including CSV, Parquet, and Excel (xls, xlsx). The file format is automatically inferred from the file extension in the provided path.

Parameters:
  • path (Path | str) – Destination path where the DataFrame will be saved. The file extension determines the output format: .csv, .parquet, .xls, .xlsx.

  • data (pd.DataFrame) – The DataFrame to be written.

  • write_kwargs (dict[str, Any], optional) – Additional keyword arguments passed to the pandas write function (e.g., compression, index, sheet_name). Default is None.

Returns:

The path where the DataFrame was written.

Return type:

Path

Raises:

ValueError – If the path type or file extension is unsupported.