Skip to content

CLN use default_index more #49478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ Performance improvements
- Performance improvements to :func:`read_sas` (:issue:`47403`, :issue:`47405`, :issue:`47656`, :issue:`48502`)
- Memory improvement in :meth:`RangeIndex.sort_values` (:issue:`48801`)
- Performance improvement in :class:`DataFrameGroupBy` and :class:`SeriesGroupBy` when ``by`` is a categorical type and ``sort=False`` (:issue:`48976`)
- 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`)

.. ---------------------------------------------------------------------------
.. _whatsnew_200.bug_fixes:
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
Index,
MultiIndex,
all_indexes_same,
default_index,
)
from pandas.core.indexes.category import CategoricalIndex
from pandas.core.series import Series
Expand Down Expand Up @@ -1159,7 +1160,7 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs)

if not self.as_index:
self._insert_inaxis_grouper_inplace(result)
result.index = Index(range(len(result)))
result.index = default_index(len(result))

return result

Expand Down Expand Up @@ -1778,7 +1779,7 @@ def nunique(self, dropna: bool = True) -> DataFrame:
)

if not self.as_index:
results.index = Index(range(len(results)))
results.index = default_index(len(results))
self._insert_inaxis_grouper_inplace(results)

return results
Expand Down
7 changes: 5 additions & 2 deletions pandas/core/reshape/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
from pandas.core.arrays import SparseArray
from pandas.core.arrays.categorical import factorize_from_iterable
from pandas.core.frame import DataFrame
from pandas.core.indexes.api import Index
from pandas.core.indexes.api import (
Index,
default_index,
)
from pandas.core.series import Series


Expand Down Expand Up @@ -249,7 +252,7 @@ def get_empty_frame(data) -> DataFrame:
if isinstance(data, Series):
index = data.index
else:
index = Index(range(len(data)))
index = default_index(len(data))
return DataFrame(index=index)

# if all NaN
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import pandas.core.common as com
from pandas.core.construction import extract_array
from pandas.core.frame import _merge_doc
from pandas.core.indexes.api import default_index
from pandas.core.sorting import is_int64_overflow_possible

if TYPE_CHECKING:
Expand Down Expand Up @@ -1060,7 +1061,7 @@ def _get_join_info(
else:
join_index = self.left.index.take(left_indexer)
else:
join_index = Index(np.arange(len(left_indexer)))
join_index = default_index(len(left_indexer))

if len(join_index) == 0:
join_index = join_index.astype(object)
Expand Down