Skip to content

Commit

Permalink
ts resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Mar 24, 2024
1 parent fb798f4 commit 5c646cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions stac_geoparquet/stac_geoparquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def to_geodataframe(
items: Sequence[dict[str, Any]],
add_self_link: bool = False,
dtype_backend: DTYPE_BACKEND | None = None,
datetime_precision: str = "us",
) -> geopandas.GeoDataFrame:
"""
Convert a sequence of STAC items to a :class:`geopandas.GeoDataFrame`.
Expand Down Expand Up @@ -86,6 +87,10 @@ def to_geodataframe(
with fields ``{"href": "a.tif", "title", None}``. pyarrow will
infer that the struct field ``asset.title`` is nullable.
datetime_precision: str, default "us"
The precision to use for the datetime columns. For example,
"us" is microsecond and "ns" is nanosecond.
Returns
-------
The converted GeoDataFrame.
Expand Down Expand Up @@ -150,17 +155,18 @@ def to_geodataframe(
if dtype_backend == "pyarrow":
for k, v in items2.items():
if k in DATETIME_COLUMNS:
items2[k] = pd.arrays.ArrowExtensionArray(
pa.array(pd.to_datetime(v, format="ISO8601"))
)
dt = pd.to_datetime(v, format="ISO8601").as_unit(datetime_precision)
items2[k] = pd.arrays.ArrowExtensionArray(pa.array(dt))

elif k != "geometry":
items2[k] = pd.arrays.ArrowExtensionArray(pa.array(v))

elif dtype_backend == "numpy_nullable":
for k, v in items2.items():
if k in DATETIME_COLUMNS:
items2[k] = pd.to_datetime(v, format="ISO8601")
items2[k] = pd.to_datetime(v, format="ISO8601").as_unit(
datetime_precision
)

if k in {"type", "stac_version", "id", "collection", SELF_LINK_COLUMN}:
items2[k] = pd.array(v, dtype="string")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_stac_geoparquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def test_assert_equal():
],
"collection": ["naip"],
"gsd": [0.6],
"datetime": pd.to_datetime(["2019-08-28 00:00:00+0000"]),
"datetime": pd.to_datetime(["2019-08-28 00:00:00+0000"]).as_unit("us"),
"naip:year": ["2019"],
"proj:bbox": [[592596.0, 4663966.8, 598495.8, 4671633.0]],
"proj:epsg": [26915],
Expand Down

0 comments on commit 5c646cb

Please sign in to comment.