Skip to content

Commit a5762a4

Browse files
committed
Pull request #290: Bugfix/pandas nat clean
Merge in LCL/wolframclientforpython from bugfix/pandas-nat-clean to master * commit '914236ef22f9bf9a0108d5b539ebedd95f776815': add test Encode the pandas NaT (not-a-time) singleton type (fixes #43)
2 parents 965da78 + 914236e commit a5762a4

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

wolframclient/serializers/encoders/pandas.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,8 @@ def encode_panda_series(serializer, o):
200200
if is_legacy_mode():
201201
return legacy_encode_series(serializer, o)
202202
return pyarrow_serialize(serializer, o.to_frame())
203+
204+
205+
@encoder.dispatch(pandas.NaT)
206+
def encode_pandas_not_a_time(serializer, o):
207+
return serializer.serialize_symbol(b"Indeterminate")

wolframclient/tests/serializers/pandas.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,15 @@ def test_serialization_works(self):
5555
)
5656
export(data, target_format="wl")
5757
export(data, target_format="wxf")
58+
59+
def test_nat_encodes_as_indeterminate(self):
60+
import pandas as pd
61+
62+
result = export(pd.NaT, target_format="wl")
63+
self.assertEqual(result, b"Indeterminate")
64+
65+
def test_nat_wxf(self):
66+
import pandas as pd
67+
68+
result = export(pd.NaT, target_format="wxf")
69+
self.assertIn(b"Indeterminate", result)

wolframclient/utils/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
SparseArray="pandas.SparseArray",
154154
RangeIndex="pandas.RangeIndex",
155155
ArrowDtype="pandas.ArrowDtype",
156+
NaT="pandas.api.typing.NaTType",
156157
)
157158

158159
pyarrow = API(

0 commit comments

Comments
 (0)