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

Method test_dates

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

Source from the content-addressed store, hash-verified

1130 }
1131
1132 def test_dates(self):
1133 # Dates are inferred as date32 by default
1134 rows = b"a,b\n1970-01-01,1970-01-02\n1971-01-01,1971-01-02\n"
1135 table = self.read_bytes(rows)
1136 schema = pa.schema([('a', pa.date32()),
1137 ('b', pa.date32())])
1138 assert table.schema == schema
1139 assert table.to_pydict() == {
1140 'a': [date(1970, 1, 1), date(1971, 1, 1)],
1141 'b': [date(1970, 1, 2), date(1971, 1, 2)],
1142 }
1143
1144 # Can ask for date types explicitly
1145 opts = ConvertOptions()
1146 opts.column_types = {'a': pa.date32(), 'b': pa.date64()}
1147 table = self.read_bytes(rows, convert_options=opts)
1148 schema = pa.schema([('a', pa.date32()),
1149 ('b', pa.date64())])
1150 assert table.schema == schema
1151 assert table.to_pydict() == {
1152 'a': [date(1970, 1, 1), date(1971, 1, 1)],
1153 'b': [date(1970, 1, 2), date(1971, 1, 2)],
1154 }
1155
1156 # Can ask for timestamp types explicitly
1157 opts = ConvertOptions()
1158 opts.column_types = {'a': pa.timestamp('s'), 'b': pa.timestamp('ms')}
1159 table = self.read_bytes(rows, convert_options=opts)
1160 schema = pa.schema([('a', pa.timestamp('s')),
1161 ('b', pa.timestamp('ms'))])
1162 assert table.schema == schema
1163 assert table.to_pydict() == {
1164 'a': [datetime(1970, 1, 1), datetime(1971, 1, 1)],
1165 'b': [datetime(1970, 1, 2), datetime(1971, 1, 2)],
1166 }
1167
1168 def test_times(self):
1169 # Times are inferred as time32[s] by default

Callers

nothing calls this directly

Calls 3

read_bytesMethod · 0.95
ConvertOptionsClass · 0.90
schemaMethod · 0.45

Tested by

no test coverage detected