-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
BugIndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesRegressionFunctionality that used to work in a prior pandas versionFunctionality that used to work in a prior pandas version
Milestone
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
df = pd.DataFrame(columns=["a", "b"]).set_index("a")
print(df.index, id(df.index)) # Index([], dtype='object', name='a') 4644041536
df.loc[0] = {"b": 0}
print(df.index, id(df.index)) # Int64Index([0], dtype='int64') 4726025904
Issue Description
Given an empty dataframe with a index column name set, when adding a row on a specific index using df.loc[INDEX]
, the original index is not preserved. Furthermore, what gets returned is not typeIndex
but is Int64Index
when the passed in index is an integer.
Expected Behavior
The modified index should print out Index([0], dtype='int64', name='a')
.
Installed Versions
1.4.0
Metadata
Metadata
Assignees
Labels
BugIndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesRegressionFunctionality that used to work in a prior pandas versionFunctionality that used to work in a prior pandas version