Skip to content

Cannot open csv file from path anymore #1243

@hboisgon

Description

@hboisgon

HydroMT version checks

  • I have checked that this issue has not already been reported.
  • I have checked that this bug exists on the latest version of HydroMT.

Reproducible Example

Create a stations.csv file with this content

ID,Name,x,y,uparea
1001,Gauge1,11.9594,45.8925,3642
1002,Gauge2,12.3395,46.1492,2
1003,Gauge3,12.0785,46.1122,837

Current behaviour

With geodataframe:

data_catalog.get_geodataframe("stations.csv")

returns

Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    data_catalog.get_geodataframe("stations.csv")
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "D:\Repos\hydromt\hydromt_wflow\.pixi\envs\default\Lib\site-packages\hydromt\data_catalog\data_catalog.py", line 1465, in get_geodataframe
    gdf = source.read_data(
        mask=mask,
    ...<2 lines>...
        variables=variables,
    )
  File "D:\Repos\hydromt\hydromt_wflow\.pixi\envs\default\Lib\site-packages\hydromt\data_catalog\sources\geodataframe.py", line 72, in read_data
    gdf: gpd.GeoDataFrame = self.driver.read(
                            ~~~~~~~~~~~~~~~~^
        uris,
        ^^^^^
    ...<4 lines>...
        handle_nodata=handle_nodata,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "D:\Repos\hydromt\hydromt_wflow\.pixi\envs\default\Lib\site-packages\hydromt\data_catalog\drivers\geodataframe\pyogrio_driver.py", line 63, in read
    raise IOError(f"DataFrame from uri: '{_uri}' contains no geometry column.")
OSError: DataFrame from uri: 'D:/Repos/hydromt/hydromt_wflow/examples/test_stations.csv' contains no geometry column.

With dataframe

data_catalog.get_dataframe("stations.csv")

returns

Traceback (most recent call last):
  File "<python-input-5>", line 1, in <module>
    cat.get_dataframe("test_stations.csv")
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "D:\Repos\hydromt\hydromt_wflow\.pixi\envs\default\Lib\site-packages\hydromt\data_catalog\data_catalog.py", line 1771, in get_dataframe
    raise ValueError(f"Source '{source.name}' is not a DataFrame.")
ValueError: Source 'test_stations.csv' is not a DataFrame.

Desired behaviour

Was this support intentionally dropped? I cannot find anything in the migration docs or changelog.

Additional context

In hydromt_wflow, for setup_gauges we used to support this option and add a few workaround options (crs) that we for now had to delete:

     if isfile(gauges_fn):
            # try to get epsg number directly, important when writing back data_catalog
            if hasattr(self.crs, "to_epsg"):
                code = self.crs.to_epsg()
            else:
                code = self.crs
            kwargs.update(crs=code)
            gdf_gauges = self.data_catalog.get_geodataframe(
                gauges_fn,
                geom=self.basins,
                assert_gtype="Point",
                handle_nodata=NoDataStrategy.IGNORE,
                **kwargs,
            )

Note that the assert g_type also seems to have been removed? Is it on purpose or do plugins have to add this geometry check type now?

Metadata

Metadata

Labels

BugSomething isn't workingNeeds refinementissue still needs refinement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions