Skip to content

Fix #12695 : RangeIndex generated with pd.concat with ignore_index as True #12696

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

Closed
wants to merge 3 commits into from
Closed
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
11 changes: 4 additions & 7 deletions pandas/tools/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ def get_result(self):
# names (because set via the 'key' argument in the 'concat'
# function call. If that's not the case, use the series names
# as column names
if (columns.equals(Index(np.arange(len(self.objs)))) and
if (columns.equals(com._default_index(len(self.objs))) and
not self.ignore_index):
columns = np.array([data[i].name
for i in range(len(data))],
Expand Down Expand Up @@ -1079,8 +1079,7 @@ def _get_concat_axis(self):
if self.axis == 0:
indexes = [x.index for x in self.objs]
elif self.ignore_index:
idx = Index(np.arange(len(self.objs)))
idx.is_unique = True # arange is always unique
idx = com._default_index(len(self.objs))
return idx
elif self.keys is None:
names = []
Expand All @@ -1092,8 +1091,7 @@ def _get_concat_axis(self):
if x.name is not None:
names.append(x.name)
else:
idx = Index(np.arange(len(self.objs)))
idx.is_unique = True
idx = com._default_index(len(self.objs))
return idx

return Index(names)
Expand All @@ -1103,8 +1101,7 @@ def _get_concat_axis(self):
indexes = [x._data.axes[self.axis] for x in self.objs]

if self.ignore_index:
idx = Index(np.arange(sum(len(i) for i in indexes)))
idx.is_unique = True
idx = com._default_index(sum(len(i) for i in indexes))
return idx

if self.keys is None:
Expand Down