BUG: ExtensionArray formatting of datetime-like forces nanosecond precision #33319
Labels
Bug
ExtensionArray
Extending pandas with custom dtypes or arrays.
Output-Formatting
__repr__ of pandas objects, to_string
When passing in an
ExtensionArray
column into the formatting code, we always do a cast withnumpy.asarray(…)
and then re-enter the if-clauses informat_array
. This enables us to re-use some of the formatting code that already is there for the existing columns but also is problematic for columns that are slightly different than the existing ones but can coerce to them.In my current example I have a
FletcherContinuousDtype(timestamp[us])
with values that are not representable in the nanosecond range (e.g. year 3000 or year 9999, typical dates used in traditional DB setups for the very far future). It is passed intoExtensionArrayFormatter
then transformed into annp.ndarray[datetime64[us]]
and then passed again intoformat_array
where it steps into theDatetime64Formatter
. There a forceful cast to nanoseconds is done throughpandas/pandas/io/formats/format.py
Lines 1438 to 1439 in 01f7310
We could either fix this by:
Datetime64Formatter
fmt_values = [values._formatter(x) for x in self.values]
The text was updated successfully, but these errors were encountered: