Closed
Description
Once we have a DatetimeArray, we'll almost be able to share the implementation of _format_native_types
. The main sticking point is that Period has a different default date format. It only prints the resolution necessary for the frequency.
In [2]: pd.Timestamp('2000')
Out[2]: Timestamp('2000-01-01 00:00:00')
In [3]: pd.Period('2000', 'D')
Out[3]: Period('2000-01-01', 'D')
In [4]: pd.Period('2000', 'H')
Out[4]: Period('2000-01-01 00:00', 'H')
We could refactor period_format
in _libs/tslibs/period.pyx
into two functions
get_period_format_string(freq)
. Get the format string like%Y
for a given freq.period_format(value, fat)
: given a freq string, format the values.
Looking at that, WK frequency may cause some issues, not sure.
In [5]: pd.Period('2000', 'W-SUN')
Out[5]: Period('1999-12-27/2000-01-02', 'W-SUN')
If we can do that, then PeriodArray._format_native_types can be
def _format_native_types(self, na_rep=u'NaT', date_format=None, **kwargs):
""" actually format my specific types """
return self.to_timestamp()._format_native_types(na_rep=na_rep,
date_format=date_format,
**kwargs)
This is blocked by #23185