Skip to content

Serializer fails on NaT (not a time in pandas) #43

@duetosymmetry

Description

@duetosymmetry

Minimal example demonstrating the problem:

import pandas as pd
from wolframclient.serializers import export

# this has type pandas.Timestamp
good_time = pd.to_datetime('2026-02-25T17:30:16+00:00')
# this rather has type pandas.api.typing.NaTType
bad_time = pd.NaT

export(good_time)
# returns b'DateObject[{2026, 2, 25, 17, 30, 16.}, "Instant", "Gregorian", "UTC"]'

export(bad_time)
# raises the below ValueError

Here is the resulting exception:

----> 1 export(bad_time)

File ~/miniconda3/envs/test_wolframclient/lib/python3.14/site-packages/wolframclient/serializers/__init__.py:68, in export(data, stream, target_format, **options)
     63 if not target_format in available_formats:
     64     raise ValueError(
     65         "Invalid export format %s. Choices are: %s"
     66         % (target_format, ", ".join(available_formats.keys()))
     67     )
---> 68 return available_formats[target_format](**options).export(data, stream=stream)

File ~/miniconda3/envs/test_wolframclient/lib/python3.14/site-packages/wolframclient/serializers/base.py:35, in FormatSerializer.export(self, data, stream)
     32         stream.write(token)
     33     return stream
---> 35 return concatenate_bytes(self.generate_bytes(data))

File ~/miniconda3/envs/test_wolframclient/lib/python3.14/site-packages/wolframclient/serializers/wl.py:17, in yield_with_separators(iterable, first, last, separator)
     15     if i:
     16         yield separator
---> 17     for sub in arg:
     18         yield sub
     19 yield last

File ~/miniconda3/envs/test_wolframclient/lib/python3.14/site-packages/wolframclient/serializers/wl.py:17, in yield_with_separators(iterable, first, last, separator)
     15     if i:
     16         yield separator
---> 17     for sub in arg:
     18         yield sub
     19 yield last

File ~/miniconda3/envs/test_wolframclient/lib/python3.14/site-packages/wolframclient/serializers/wl.py:58, in WLSerializer.serialize_int(self, number)
     57 def serialize_int(self, number):
---> 58     yield b"%i" % number

ValueError: cannot convert float NaN to integer

This is different from how the exporter handles NaN (not a number):

import numpy as np

export(np.nan)
# returns b'Indeterminate'

Expected behavior: The serializer should detect NaT and treat it like NaN, returning Indeterminate.

EDITED to add: This affects both target_format='wl' and target_format='wxf'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions