Skip to content

Commit 8ba0522

Browse files
authored
fix: avoid casting tuples after Dataset.map (#4993)
* fix: avoid casting tuples after Dataset.map * fix: fix test_cast_to_python_objects_tuple test
1 parent 1b4c3cb commit 8ba0522

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/datasets/features/features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,12 @@ def _cast_to_python_objects(obj: Any, only_1d_for_numpy: bool, optimize_list_cas
379379
for elmt in obj
380380
], True
381381
else:
382-
if isinstance(obj, list):
382+
if isinstance(obj, (list, tuple)):
383383
return obj, False
384384
else:
385385
return list(obj), True
386386
else:
387-
return obj if isinstance(obj, list) else [], isinstance(obj, tuple)
387+
return obj, False
388388
else:
389389
return obj, False
390390

tests/features/test_features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def test_cast_to_python_objects_list(self):
463463

464464
def test_cast_to_python_objects_tuple(self):
465465
obj = {"col_1": [{"vec": (1, 2, 3), "txt": "foo"}] * 3, "col_2": [(1, 2), (3, 4), (5, 6)]}
466-
expected_obj = {"col_1": [{"vec": [1, 2, 3], "txt": "foo"}] * 3, "col_2": [[1, 2], [3, 4], [5, 6]]}
466+
expected_obj = {"col_1": [{"vec": (1, 2, 3), "txt": "foo"}] * 3, "col_2": [(1, 2), (3, 4), (5, 6)]}
467467
casted_obj = cast_to_python_objects(obj)
468468
self.assertDictEqual(casted_obj, expected_obj)
469469

0 commit comments

Comments
 (0)