From 0c9fa193863a13c78a6c551434678974ed938f32 Mon Sep 17 00:00:00 2001 From: Leo Ghignone Date: Mon, 26 Feb 2024 15:49:39 +1100 Subject: [PATCH] Fix inferring datetime when no geometry is present --- stac_table.py | 5 ++++- test_stac_table.py | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/stac_table.py b/stac_table.py index 5be0300..c3ee50c 100644 --- a/stac_table.py +++ b/stac_table.py @@ -155,7 +155,10 @@ def generate( or infer_datetime != InferDatetimeOptions.no or proj is True ): - data = dask_geopandas.read_parquet(uri, storage_options=storage_options) + if proj: + data = dask_geopandas.read_parquet(uri, storage_options=storage_options) + else: + data = dask.dataframe.read_parquet(uri, storage_options=storage_options) # # TODO: this doesn't actually work # data = dask_geopandas.read_parquet( # ds.files, storage_options={"filesystem": ds.filesystem} diff --git a/test_stac_table.py b/test_stac_table.py index 339b492..690397b 100644 --- a/test_stac_table.py +++ b/test_stac_table.py @@ -51,11 +51,11 @@ def test_generate_item(self, partition): ) expected_columns = [ - {"name": "pop_est", "type": "int64"}, + {"name": "pop_est", "type": "double"}, {"name": "continent", "type": "byte_array"}, {"name": "name", "type": "byte_array"}, {"name": "iso_a3", "type": "byte_array"}, - {"name": "gdp_md_est", "type": "double"}, + {"name": "gdp_md_est", "type": "int64"}, {"name": "geometry", "type": "byte_array"}, ] assert result.properties["table:columns"] == expected_columns @@ -146,6 +146,20 @@ def test_infer_datetime_range(self): assert result.properties["start_datetime"] == "2000-01-01T00:00:00Z" assert result.properties["end_datetime"] == "2000-01-03T00:00:00Z" + def test_infer_datetime_nogeom(self): + df = pd.DataFrame( + {"A": [pd.Timestamp("2000-01-01"), pd.Timestamp("2000-01-03")]}, + ) + df.to_parquet("data.parquet") + item = pystac.Item( + "naturalearth_lowres", None, None, datetime.datetime(2021, 1, 1), {} + ) + result = stac_table.generate( + "data.parquet", item, datetime_column="A", infer_datetime="midpoint", + proj=False + ) + assert result.properties["datetime"] == "2021-01-01T00:00:00Z" + def test_metadata(self): df = geopandas.GeoDataFrame( {"A": [pd.Timestamp("2000-01-01"), pd.Timestamp("2000-01-03")]},