Skip to content

Commit 1ac71f7

Browse files
committed
Fix time type _arrow_to_datasets_dtype conversion
1 parent 84fc3ad commit 1ac71f7

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/datasets/features/features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def _arrow_to_datasets_dtype(arrow_type: pa.DataType) -> str:
7878
elif pyarrow.types.is_float64(arrow_type):
7979
return "float64" # pyarrow dtype is "double"
8080
elif pyarrow.types.is_time32(arrow_type):
81-
return f"time32[{arrow_type.unit}]"
81+
return f"time32[{pa.type_for_alias(str(arrow_type)).unit}]"
8282
elif pyarrow.types.is_time64(arrow_type):
83-
return f"time64[{arrow_type.unit}]"
83+
return f"time64[{pa.type_for_alias(str(arrow_type)).unit}]"
8484
elif pyarrow.types.is_timestamp(arrow_type):
8585
if arrow_type.tz is None:
8686
return f"timestamp[{arrow_type.unit}]"

tests/features/test_features.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
from dataclasses import asdict
23
from unittest import TestCase
34
from unittest.mock import patch
@@ -58,6 +59,7 @@ def test_string_to_arrow_bijection_for_primitive_types(self):
5859
pa.string(),
5960
pa.int32(),
6061
pa.float64(),
62+
pa.array([datetime.time(1, 1, 1)]).type, # arrow type: DataType(time64[us])
6163
]
6264
for dt in supported_pyarrow_datatypes:
6365
self.assertEqual(dt, string_to_arrow(_arrow_to_datasets_dtype(dt)))

0 commit comments

Comments
 (0)