stac-utils / stac-table

MIT License
6 stars 2 forks source link

Error inferring datetime when data has no geometry #5

Open barbuz opened 8 months ago

barbuz commented 8 months ago

I use stac-table to generate metadata for geospatial datasets, but once in a while I need to manage parquet files without a geometry column. This works fine with stac-table by setting proj=False, unless I also need to infer datetime information, in which case the generation fails.

Sample code to reproduce the issue:

import datetime
import pandas as pd
import pystac
import stac_table

# Create a sample DataFrame
data = {
    'time': pd.date_range(start='2022-01-01', periods=5, freq='H'),
    'value1': [1, 2, 3, 4, 5],
    'value2': [10, 20, 30, 40, 50],
}
df = pd.DataFrame(data)

# Save DataFrame to Parquet
df.to_parquet('sample.parquet')

# Item template
template = pystac.Item(
    "test",
    geometry=None,
    bbox=None,
    datetime=datetime.datetime.now(datetime.timezone.utc),
    properties={},
)

# Create a STAC Table
stac_table.generate(
    'sample.parquet',
    template,
    proj=False,
    infer_datetime=stac_table.InferDatetimeOptions.range,
    datetime_column='time',
)

When running I get this error:

ValueError: An error occurred while calling the read_parquet method registered to the pandas backend. Original Message: Missing geo metadata in Parquet/Feather file. Use pandas.read_parquet/read_feather() instead.