Skip to content

Commit 867461d

Browse files
committed
Merge pull request #10026 from shoyer/fix-tdi-name
Fix TimedeltaIndex constructor fastpath when name is set
2 parents b7c3271 + 404917d commit 867461d

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

doc/source/whatsnew/v0.16.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ Bug Fixes
235235
- Bug in ``read_sql_table`` error when reading postgres table with timezone (:issue:`7139`)
236236
- Bug in ``DataFrame`` slicing may not retain metadata (:issue:`9776`)
237237
- Bug where ``TimdeltaIndex`` were not properly serialized in fixed ``HDFStore`` (:issue:`9635`)
238+
- Bug with ``TimedeltaIndex`` constructor ignoring ``name`` when given another ``TimedeltaIndex`` as data (:issue:`10025`).
238239
- Bug in ``DataFrameFormatter._get_formatted_index`` with not applying ``max_colwidth`` to the ``DataFrame`` index (:issue:`7856`)
239240

240241
- Bug in ``groupby.apply()`` that would raise if a passed user defined function either returned only ``None`` (for all input). (:issue:`9685`)

pandas/tseries/tdi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def __new__(cls, data=None, unit=None,
140140
copy=False, name=None,
141141
closed=None, verify_integrity=True, **kwargs):
142142

143-
if isinstance(data, TimedeltaIndex) and freq is None:
143+
if isinstance(data, TimedeltaIndex) and freq is None and name is None:
144144
if copy:
145145
data = data.copy()
146146
return data

pandas/tseries/tests/test_timedeltas.py

+4
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,10 @@ def test_constructor_name(self):
949949
name='TEST')
950950
self.assertEqual(idx.name, 'TEST')
951951

952+
# GH10025
953+
idx2 = TimedeltaIndex(idx, name='something else')
954+
self.assertEqual(idx2.name, 'something else')
955+
952956
def test_freq_conversion(self):
953957

954958
# doc example

0 commit comments

Comments
 (0)