MCPcopy Create free account
hub / github.com/apache/arrow / test_times

Method test_times

python/pyarrow/tests/test_csv.py:1168–1193  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1166 }
1167
1168 def test_times(self):
1169 # Times are inferred as time32[s] by default
1170 from datetime import time
1171
1172 rows = b"a,b\n12:34:56,12:34:56.789\n23:59:59,23:59:59.999\n"
1173 table = self.read_bytes(rows)
1174 # Column 'b' has subseconds, so cannot be inferred as time32[s]
1175 schema = pa.schema([('a', pa.time32('s')),
1176 ('b', pa.string())])
1177 assert table.schema == schema
1178 assert table.to_pydict() == {
1179 'a': [time(12, 34, 56), time(23, 59, 59)],
1180 'b': ["12:34:56.789", "23:59:59.999"],
1181 }
1182
1183 # Can ask for time types explicitly
1184 opts = ConvertOptions()
1185 opts.column_types = {'a': pa.time64('us'), 'b': pa.time32('ms')}
1186 table = self.read_bytes(rows, convert_options=opts)
1187 schema = pa.schema([('a', pa.time64('us')),
1188 ('b', pa.time32('ms'))])
1189 assert table.schema == schema
1190 assert table.to_pydict() == {
1191 'a': [time(12, 34, 56), time(23, 59, 59)],
1192 'b': [time(12, 34, 56, 789000), time(23, 59, 59, 999000)],
1193 }
1194
1195 def test_auto_dict_encode(self):
1196 opts = ConvertOptions(auto_dict_encode=True)

Callers

nothing calls this directly

Calls 4

read_bytesMethod · 0.95
ConvertOptionsClass · 0.90
schemaMethod · 0.45
stringMethod · 0.45

Tested by

no test coverage detected