File tree 3 files changed +20
-7
lines changed
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.
13
13
14
14
Fixed regressions
15
15
~~~~~~~~~~~~~~~~~
16
- -
16
+ - Fixed regression for subclassed Series when constructing from a dictionary ( :issue: ` 52445 `)
17
17
18
18
.. ---------------------------------------------------------------------------
19
19
.. _whatsnew_201.bug_fixes :
Original file line number Diff line number Diff line change @@ -562,12 +562,7 @@ def _init_dict(
562
562
keys , values = (), []
563
563
564
564
# Input is now list-like, so rely on "standard" construction:
565
-
566
- s = self ._constructor (
567
- values ,
568
- index = keys ,
569
- dtype = dtype ,
570
- )
565
+ s = Series (values , index = keys , dtype = dtype )
571
566
572
567
# Now we just make sure the order is respected, if any
573
568
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):
58
58
s2 = tm .SubclassedSeries ([1 , 2 , 3 ])
59
59
assert s1 .equals (s2 )
60
60
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