File tree 3 files changed +26
-1
lines changed
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import pandas as pd
4
4
from pandas import (
5
+ NA ,
5
6
Categorical ,
6
7
DataFrame ,
8
+ Float64Dtype ,
7
9
MultiIndex ,
8
10
Series ,
9
11
Timestamp ,
@@ -138,6 +140,27 @@ def time_frame_from_range(self):
138
140
self .df = DataFrame (self .data )
139
141
140
142
143
+ class FromScalar :
144
+ def setup (self ):
145
+ self .nrows = 100_000
146
+
147
+ def time_frame_from_scalar_ea_float64 (self ):
148
+ DataFrame (
149
+ 1.0 ,
150
+ index = range (self .nrows ),
151
+ columns = list ("abc" ),
152
+ dtype = Float64Dtype (),
153
+ )
154
+
155
+ def time_frame_from_scalar_ea_float64_na (self ):
156
+ DataFrame (
157
+ NA ,
158
+ index = range (self .nrows ),
159
+ columns = list ("abc" ),
160
+ dtype = Float64Dtype (),
161
+ )
162
+
163
+
141
164
class FromArrays :
142
165
143
166
goal_time = 0.2
Original file line number Diff line number Diff line change @@ -244,6 +244,7 @@ Performance improvements
244
244
- Performance improvement in :meth: `DataFrame.duplicated ` when subset consists of only one column (:issue: `45236 `)
245
245
- Performance improvement in :meth: `.GroupBy.transform ` when broadcasting values for user-defined functions (:issue: `45708 `)
246
246
- Performance improvement in :meth: `.GroupBy.transform ` for user-defined functions when only a single group exists (:issue: `44977 `)
247
+ - Performance improvement in :class: `DataFrame ` and :class: `Series ` constructors for extension dtype scalars (:issue: `45854 `)
247
248
-
248
249
249
250
.. ---------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -1652,7 +1652,8 @@ def construct_1d_arraylike_from_scalar(
1652
1652
1653
1653
if isinstance (dtype , ExtensionDtype ):
1654
1654
cls = dtype .construct_array_type ()
1655
- subarr = cls ._from_sequence ([value ] * length , dtype = dtype )
1655
+ seq = [] if length == 0 else [value ]
1656
+ subarr = cls ._from_sequence (seq , dtype = dtype ).repeat (length )
1656
1657
1657
1658
else :
1658
1659
You can’t perform that action at this time.
0 commit comments