Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geometry metadata in pas files #718

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions pastas/io/pas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@
from io import StringIO as stringIO
from logging import getLogger

try:
from shapely.geometry.base import BaseGeometry

SHAPELY = True
except ModuleNotFoundError:
SHAPELY = False
BaseGeometry = None

from pandas import (
DataFrame,
Series,
Timedelta,
Timestamp,
isna,
read_json,
to_numeric,
to_timedelta,
)

Expand Down Expand Up @@ -78,7 +85,7 @@ class PastasEncoder(json.JSONEncoder):
"""

def default(self, o):
if isinstance(o, (Timestamp, datetime.datetime)):
if isinstance(o, (Timestamp, datetime.datetime, datetime.date)):
return o.isoformat()
elif isinstance(o, Series):
return o.to_json(date_format="iso", orient="split")
Expand All @@ -90,6 +97,8 @@ def default(self, o):
if isinstance(o, datetime.timedelta):
o = to_timedelta(o)
return o.to_timedelta64().__str__()
elif SHAPELY and isinstance(o, BaseGeometry):
return o.wkt
elif isna(o):
return None
else:
Expand Down