File tree Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ including other versions of pandas.
1313
1414Fixed regressions
1515~~~~~~~~~~~~~~~~~
16- -
16+ - Fixed regression for subclassed Series when constructing from a dictionary ( :issue: ` 52445 `)
1717
1818.. ---------------------------------------------------------------------------
1919 .. _whatsnew_201.bug_fixes :
Original file line number Diff line number Diff line change @@ -561,12 +561,7 @@ def _init_dict(
561561 keys , values = (), []
562562
563563 # Input is now list-like, so rely on "standard" construction:
564-
565- s = self ._constructor (
566- values ,
567- index = keys ,
568- dtype = dtype ,
569- )
564+ s = Series (values , index = keys , dtype = dtype )
570565
571566 # Now we just make sure the order is respected, if any
572567 if data and index is not None :
Original file line number Diff line number Diff line change @@ -58,3 +58,21 @@ def test_equals(self):
5858 s2 = tm .SubclassedSeries ([1 , 2 , 3 ])
5959 assert s1 .equals (s2 )
6060 assert s2 .equals (s1 )
61+
62+
63+ class SubclassedSeries (pd .Series ):
64+ @property
65+ def _constructor (self ):
66+ def _new (* args , ** kwargs ):
67+ # some constructor logic that accesses the Series' name
68+ if self .name == "test" :
69+ return pd .Series (* args , ** kwargs )
70+ return SubclassedSeries (* args , ** kwargs )
71+
72+ return _new
73+
74+
75+ def test_constructor_from_dict ():
76+ # https://github.com/pandas-dev/pandas/issues/52445
77+ result = SubclassedSeries ({"a" : 1 , "b" : 2 , "c" : 3 })
78+ assert isinstance (result , SubclassedSeries )
You can’t perform that action at this time.
0 commit comments