Skip to content

Commit

Permalink
Geometry metadata in pas files (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulcollenteur committed Apr 9, 2024
2 parents 4fcf9c8 + eaf3e54 commit bf64e28
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit bf64e28

Please sign in to comment.