Skip to content

Commit 8ea2d08

Browse files
jorisvandenbosscheWillAyd
authored andcommitted
BUG: fix empty Series repr for subclasses (pandas-dev#27001)
1 parent 83fe8d7 commit 8ea2d08

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ Other
793793

794794
- Removed unused C functions from vendored UltraJSON implementation (:issue:`26198`)
795795
- Allow :class:`Index` and :class:`RangeIndex` to be passed to numpy ``min`` and ``max`` functions (:issue:`26125`)
796+
- Use actual class name in repr of empty objects of a ``Series`` subclass (:issue:`27001`).
796797

797798
.. _whatsnew_0.250.contributors:
798799

pandas/io/formats/format.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ def to_string(self):
257257
footer = self._get_footer()
258258

259259
if len(series) == 0:
260-
return 'Series([], ' + footer + ')'
260+
return "{name}([], {footer})".format(
261+
name=self.series.__class__.__name__, footer=footer)
261262

262263
fmt_index, have_header = self._get_formatted_index()
263264
fmt_values = self._get_formatted_values()

pandas/tests/series/test_subclass.py

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def test_subclass_unstack(self):
3939

4040
tm.assert_frame_equal(res, exp)
4141

42+
def test_subclass_empty_repr(self):
43+
assert 'SubclassedSeries' in repr(tm.SubclassedSeries())
44+
4245

4346
@pytest.mark.filterwarnings("ignore:Sparse:FutureWarning")
4447
class TestSparseSeriesSubclassing:

0 commit comments

Comments
 (0)