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

Method test_timestamp_parsers

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

Source from the content-addressed store, hash-verified

1096 }
1097
1098 def test_timestamp_parsers(self):
1099 # Infer timestamps with custom parsers
1100 rows = b"a,b\n1970/01/01,1980-01-01 00\n1970/01/02,1980-01-02 00\n"
1101 opts = ConvertOptions()
1102
1103 table = self.read_bytes(rows, convert_options=opts)
1104 schema = pa.schema([('a', pa.string()),
1105 ('b', pa.timestamp('s'))])
1106 assert table.schema == schema
1107 assert table.to_pydict() == {
1108 'a': ['1970/01/01', '1970/01/02'],
1109 'b': [datetime(1980, 1, 1), datetime(1980, 1, 2)],
1110 }
1111
1112 opts.timestamp_parsers = ['%Y/%m/%d']
1113 table = self.read_bytes(rows, convert_options=opts)
1114 schema = pa.schema([('a', pa.timestamp('s')),
1115 ('b', pa.string())])
1116 assert table.schema == schema
1117 assert table.to_pydict() == {
1118 'a': [datetime(1970, 1, 1), datetime(1970, 1, 2)],
1119 'b': ['1980-01-01 00', '1980-01-02 00'],
1120 }
1121
1122 opts.timestamp_parsers = ['%Y/%m/%d', ISO8601]
1123 table = self.read_bytes(rows, convert_options=opts)
1124 schema = pa.schema([('a', pa.timestamp('s')),
1125 ('b', pa.timestamp('s'))])
1126 assert table.schema == schema
1127 assert table.to_pydict() == {
1128 'a': [datetime(1970, 1, 1), datetime(1970, 1, 2)],
1129 'b': [datetime(1980, 1, 1), datetime(1980, 1, 2)],
1130 }
1131
1132 def test_dates(self):
1133 # Dates are inferred as date32 by default

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