Skip to content

Commit

Permalink
fix(polars): handle integers coming out of high precision numpy datet…
Browse files Browse the repository at this point in the history
…ime64 values
  • Loading branch information
cpcloud authored and gforsyth committed Dec 19, 2023
1 parent dc9a590 commit bcf36cb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ibis/formats/pandas.py
Expand Up @@ -291,6 +291,18 @@ def converter(value, dtype=dtype):
with contextlib.suppress(AttributeError):
value = value.item()

if isinstance(value, int):
# this can only mean a numpy or pandas timestamp because they
# both support nanosecond precision
#
# when the precision is less than or equal to the value
# supported by Python datetime.dateimte a call to .item() will
# return a datetime.datetime but when the precision is higher
# than the value supported by Python the value is an integer
#
# TODO: can we do better than implicit truncation to microseconds?
value = datetime.datetime.utcfromtimestamp(value / 1e9)

if (tz := dtype.timezone) is not None:
return value.astimezone(normalize_timezone(tz))

Expand Down

0 comments on commit bcf36cb

Please sign in to comment.