Skip to content

Commit a222499

Browse files
committed
Merge pull request #5321 from jreback/assign_index_perf
PERF: vbench for time-series index assignment in frame (GH5320)
2 parents 8941429 + f36cc17 commit a222499

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

pandas/core/frame.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,11 @@ def insert(self, loc, column, value, allow_duplicates=False):
19141914
def _sanitize_column(self, key, value):
19151915
# Need to make sure new columns (which go into the BlockManager as new
19161916
# blocks) are always copied
1917-
if _is_sequence(value):
1917+
1918+
# dont' need further processing on an equal index
1919+
if isinstance(value, Index) and (not len(self.index) or value.equals(self.index)):
1920+
value = value.values.copy()
1921+
elif isinstance(value, Series) or _is_sequence(value):
19181922
is_frame = isinstance(value, DataFrame)
19191923
if isinstance(value, Series) or is_frame:
19201924
if value.index.equals(self.index) or not len(self.index):

vb_suite/frame_methods.py

+15
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ def j():
120120
frame_getitem_single_column2 = Benchmark('j()', setup,
121121
start_date=datetime(2010, 6, 1))
122122

123+
#----------------------------------------------------------------------
124+
# assignment
125+
126+
setup = common_setup + """
127+
idx = date_range('1/1/2000', periods=100000, freq='D')
128+
df = DataFrame(randn(100000, 1),columns=['A'],index=idx)
129+
def f(x):
130+
x = x.copy()
131+
x['date'] = x.index
132+
"""
133+
134+
frame_assign_timeseries_index = Benchmark('f(df)', setup,
135+
start_date=datetime(2013, 10, 1))
136+
137+
123138
#----------------------------------------------------------------------
124139
# to_string
125140

vb_suite/timeseries.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ def date_range(start=None, end=None, periods=None, freq=None):
229229
# tz_localize with infer argument. This is an attempt to emulate the results
230230
# of read_csv with duplicated data. Not passing infer_dst will fail
231231
setup = common_setup + """
232-
dst_rng = date_range('10/29/2000 1:00:00',
232+
dst_rng = date_range('10/29/2000 1:00:00',
233233
'10/29/2000 1:59:59', freq='S')
234234
index = date_range('10/29/2000', '10/29/2000 00:59:59', freq='S')
235235
index = index.append(dst_rng)
236236
index = index.append(dst_rng)
237-
index = index.append(date_range('10/29/2000 2:00:00',
237+
index = index.append(date_range('10/29/2000 2:00:00',
238238
'10/29/2000 3:00:00', freq='S'))
239239
"""
240240

0 commit comments

Comments
 (0)