Closed
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