Skip to content

Commit ec7a3bf

Browse files
committed
Updated rapidjson w/ fix for empty structured arrays & pandas data frames
1 parent 2d62ff0 commit ec7a3bf

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

tests/test_numpy.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ def test_structured_array(dumps, loads):
125125
np.testing.assert_equal(loaded, value)
126126

127127

128+
def test_structured_array_empty(dumps, loads):
129+
value = np.array([], dtype=[('name', 'U0'), ('age', 'i4'),
130+
('weight', 'f4'), ('color', 'S0')])
131+
dumped = dumps(value)
132+
loaded = loads(dumped)
133+
assert type(loaded) is type(value) and loaded.dtype == value.dtype
134+
np.testing.assert_equal(loaded, value)
135+
136+
128137
def test_pandas(dumps, loads):
129138
try:
130139
import pandas as pd
@@ -147,20 +156,13 @@ def test_pandas_empty(dumps, loads):
147156
pytest.skip("requires pandas")
148157
value = np.array([], dtype=[('name', 'U0'), ('age', 'i4'),
149158
('weight', 'f4'), ('color', 'S0')])
159+
# Because pandas stores both unicode & bytes as object type, the
160+
# type defaults to bytes for empty arrays where the elements cannot
161+
# be inspected for their type
162+
value_def = np.array([], dtype=[('name', 'S0'), ('age', 'i4'),
163+
('weight', 'f4'), ('color', 'S0')])
150164
value_pd = pd.DataFrame(value)
151165
dumped = dumps(value_pd)
152166
loaded = loads(dumped)
153-
loaded_value = loads(dumps(value))
154-
print(loaded, loaded_value)
155-
print(type(loaded), type(loaded_value))
156-
# import pdb; pdb.set_trace()
157-
assert (type(loaded) is type(loaded_value))
158-
if isinstance(loaded, list):
159-
assert len(loaded) == len(loaded_value)
160-
np.testing.assert_equal(loaded, loaded_value)
161-
# for a, b in zip(loaded, loaded_value):
162-
# np.testing.assert_equal(a, b)
163-
else:
164-
assert loaded.dtype == loaded_value.dtype
165-
np.testing.assert_equal(loaded, value)
166-
np.testing.assert_equal(loaded, loaded_value)
167+
assert type(loaded) is type(value) and loaded.dtype == value_def.dtype
168+
np.testing.assert_equal(loaded, value_def)

0 commit comments

Comments
 (0)