Skip to content

Commit 7e9ca6e

Browse files
authored
CLN use default_index more (#49478)
* use default_index more * dont change for columns * 📝 add whatsnew note Co-authored-by: MarcoGorelli <>
1 parent 4d7d921 commit 7e9ca6e

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ Performance improvements
456456
- Performance improvements to :func:`read_sas` (:issue:`47403`, :issue:`47405`, :issue:`47656`, :issue:`48502`)
457457
- Memory improvement in :meth:`RangeIndex.sort_values` (:issue:`48801`)
458458
- Performance improvement in :class:`DataFrameGroupBy` and :class:`SeriesGroupBy` when ``by`` is a categorical type and ``sort=False`` (:issue:`48976`)
459+
- Performance improvement in :func:`merge` when not merging on the index - the new index will now be :class:`RangeIndex` instead of :class:`Int64Index` (:issue:`49478`)
459460

460461
.. ---------------------------------------------------------------------------
461462
.. _whatsnew_200.bug_fixes:

pandas/core/groupby/generic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
Index,
9696
MultiIndex,
9797
all_indexes_same,
98+
default_index,
9899
)
99100
from pandas.core.indexes.category import CategoricalIndex
100101
from pandas.core.series import Series
@@ -1159,7 +1160,7 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs)
11591160

11601161
if not self.as_index:
11611162
self._insert_inaxis_grouper_inplace(result)
1162-
result.index = Index(range(len(result)))
1163+
result.index = default_index(len(result))
11631164

11641165
return result
11651166

@@ -1778,7 +1779,7 @@ def nunique(self, dropna: bool = True) -> DataFrame:
17781779
)
17791780

17801781
if not self.as_index:
1781-
results.index = Index(range(len(results)))
1782+
results.index = default_index(len(results))
17821783
self._insert_inaxis_grouper_inplace(results)
17831784

17841785
return results

pandas/core/reshape/encoding.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
from pandas.core.arrays import SparseArray
2222
from pandas.core.arrays.categorical import factorize_from_iterable
2323
from pandas.core.frame import DataFrame
24-
from pandas.core.indexes.api import Index
24+
from pandas.core.indexes.api import (
25+
Index,
26+
default_index,
27+
)
2528
from pandas.core.series import Series
2629

2730

@@ -249,7 +252,7 @@ def get_empty_frame(data) -> DataFrame:
249252
if isinstance(data, Series):
250253
index = data.index
251254
else:
252-
index = Index(range(len(data)))
255+
index = default_index(len(data))
253256
return DataFrame(index=index)
254257

255258
# if all NaN

pandas/core/reshape/merge.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import pandas.core.common as com
8585
from pandas.core.construction import extract_array
8686
from pandas.core.frame import _merge_doc
87+
from pandas.core.indexes.api import default_index
8788
from pandas.core.sorting import is_int64_overflow_possible
8889

8990
if TYPE_CHECKING:
@@ -1060,7 +1061,7 @@ def _get_join_info(
10601061
else:
10611062
join_index = self.left.index.take(left_indexer)
10621063
else:
1063-
join_index = Index(np.arange(len(left_indexer)))
1064+
join_index = default_index(len(left_indexer))
10641065

10651066
if len(join_index) == 0:
10661067
join_index = join_index.astype(object)

0 commit comments

Comments
 (0)