Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Fix inferring datetime when no geometry is present #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion stac_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
18 changes: 16 additions & 2 deletions test_stac_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")]},
Expand Down