Skip to content

REGR: Series.__repr__ is broken for SparseDtype("datetime64[ns]") #35843

@dsaxton

Description

@dsaxton

Regression due to 1fa0635 :

import pandas as pd print(pd.__version__) values = [pd.Timestamp('2012-05-01T01:00:00.000000'), pd.Timestamp('2016-05-01T01:00:00.000000')] arr = pd.arrays.SparseArray(values) ser = pd.Series(arr) ser
1.2.0.dev0+147.g07983803b Out[1]: --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) ~/opt/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj) 700 type_pprinters=self.type_printers, 701 deferred_pprinters=self.deferred_printers) --> 702 printer.pretty(obj) 703 printer.flush() 704 return stream.getvalue() ~/opt/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/IPython/lib/pretty.py in pretty(self, obj) 392 if cls is not object \ 393 and callable(cls.__dict__.get('__repr__')): --> 394 return _repr_pprint(obj, self, cycle) 395 396 return _default_pprint(obj, self, cycle) ~/opt/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle) 698 """A pprint that just redirects to the normal repr function.""" 699 # Find newlines and replace them with p.break_() --> 700 output = repr(obj) 701 lines = output.splitlines() 702 with p.group(): ~/pandas/pandas/core/series.py in __repr__(self) 1315 show_dimensions = get_option("display.show_dimensions") 1316 -> 1317 self.to_string( 1318 buf=buf, 1319 name=self.name, ~/pandas/pandas/core/series.py in to_string(self, buf, na_rep, float_format, header, index, length, dtype, name, max_rows, min_rows) 1386 max_rows=max_rows, 1387 ) -> 1388 result = formatter.to_string() 1389 1390 # catch contract violations ~/pandas/pandas/io/formats/format.py in to_string(self) 356 357 fmt_index, have_header = self._get_formatted_index() --> 358 fmt_values = self._get_formatted_values() 359 360 if self.truncate_v: ~/pandas/pandas/io/formats/format.py in _get_formatted_values(self) 341 342 def _get_formatted_values(self) -> List[str]: --> 343 return format_array( 344 self.tr_series._values, 345 None, ~/pandas/pandas/io/formats/format.py in format_array(values, formatter, float_format, na_rep, digits, space, justify, decimal, leading_space, quoting) 1179 ) 1180 -> 1181 return fmt_obj.get_result() 1182 1183 ~/pandas/pandas/io/formats/format.py in get_result(self) 1210 1211 def get_result(self) -> List[str]: -> 1212 fmt_values = self._format_strings() 1213 return _make_fixed_width(fmt_values, self.justify) 1214 ~/pandas/pandas/io/formats/format.py in _format_strings(self) 1467 1468 if not isinstance(values, DatetimeIndex): -> 1469 values = DatetimeIndex(values) 1470 1471 if self.formatter is not None and callable(self.formatter): ~/pandas/pandas/core/indexes/datetimes.py in __new__(cls, data, freq, tz, normalize, closed, ambiguous, dayfirst, yearfirst, dtype, copy, name) 269 name = maybe_extract_name(name, data, cls) 270 --> 271 dtarr = DatetimeArray._from_sequence( 272 data, 273 dtype=dtype, ~/pandas/pandas/core/arrays/datetimes.py in _from_sequence(cls, data, dtype, copy, tz, freq, dayfirst, yearfirst, ambiguous) 314 freq, freq_infer = dtl.maybe_infer_freq(freq) 315 --> 316 subarr, tz, inferred_freq = sequence_to_dt64ns( 317 data, 318 dtype=dtype, ~/pandas/pandas/core/arrays/datetimes.py in sequence_to_dt64ns(data, dtype, copy, tz, dayfirst, yearfirst, ambiguous) 1957 if is_datetime64tz_dtype(data_dtype): 1958 # DatetimeArray -> ndarray -> 1959 tz = _maybe_infer_tz(tz, data.tz) 1960 result = data._data 1961 AttributeError: 'SparseArray' object has no attribute 'tz'

xref #35762

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeOutput-Formatting__repr__ of pandas objects, to_stringRegressionFunctionality that used to work in a prior pandas versionSparseSparse Data Type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions