Skip to content

Commit e54fbee

Browse files
committed
Merge pull request #7040 from immerrr/perf-index-delete
PERF: optimize Index.delete for dtype=object
2 parents 4c79859 + 7beac12 commit e54fbee

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

doc/source/release.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ API Changes
124124

125125
- ``concat`` will now concatenate mixed Series and DataFrames using the Series name
126126
or numbering columns as needed (:issue:`2385`)
127-
- Slicing and advanced/boolean indexing operations on ``Index`` classes will no
128-
longer change type of the resulting index (:issue:`6440`).
127+
- Slicing and advanced/boolean indexing operations on ``Index`` classes as well
128+
as :meth:`Index.delete` and :meth:`Index.drop` methods will no longer change type of the
129+
resulting index (:issue:`6440`, :issue:`7040`)
129130
- ``set_index`` no longer converts MultiIndexes to an Index of tuples (:issue:`6459`).
130131
- Slicing with negative start, stop & step values handles corner cases better (:issue:`6531`):
131132

doc/source/v0.14.0.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,15 @@ API changes
163163

164164
- ``concat`` will now concatenate mixed Series and DataFrames using the Series name
165165
or numbering columns as needed (:issue:`2385`). See :ref:`the docs <merging.mixed_ndims>`
166-
- Slicing and advanced/boolean indexing operations on ``Index`` classes will no
167-
longer change type of the resulting index (:issue:`6440`)
166+
- Slicing and advanced/boolean indexing operations on ``Index`` classes as well
167+
as :meth:`Index.delete` and :meth:`Index.drop` methods will no longer change type of the
168+
resulting index (:issue:`6440`, :issue:`7040`)
168169

169170
.. ipython:: python
170171

171172
i = pd.Index([1, 2, 3, 'a' , 'b', 'c'])
172173
i[[0,1,2]]
174+
i.drop(['a', 'b', 'c'])
173175

174176
Previously, the above operation would return ``Int64Index``. If you'd like
175177
to do this manually, use :meth:`Index.astype`

pandas/core/index.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1760,14 +1760,13 @@ def slice_locs(self, start=None, end=None):
17601760

17611761
def delete(self, loc):
17621762
"""
1763-
Make new Index with passed location deleted
1763+
Make new Index with passed location(-s) deleted
17641764
17651765
Returns
17661766
-------
17671767
new_index : Index
17681768
"""
1769-
arr = np.delete(self.values, loc)
1770-
return Index(arr)
1769+
return np.delete(self, loc)
17711770

17721771
def insert(self, loc, item):
17731772
"""

0 commit comments

Comments
 (0)