(self)
| 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 |
nothing calls this directly
no test coverage detected