Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
[X] I have checked that this issue has not already been reported.
[X] 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
# multiindex with the second level being a Timestamp
df = pd.DataFrame({('A', pd.Timestamp('2024-01-01')): [0]})
# insert using only the top level
df.insert(1, 'B', [1])
print(df.to_string())
# A B
# 2023-01-01 NaT
# 0 0 1
# raises RecursionError
del df['B']
Issue Description
Creating and deleting a column is leading to an unexpected error.
This is a contrived example, but was observed in wild when joining two dataframes which had MultiIndex columns with str and timestamp levels with a named index, say 'Index'. The join ends up adding a column ('Index', pd.NaT) then deleting it to set it as the index.
Expected Behavior
It should just delete the column.
del df['B']
print(df.to_string())
# A
# 2023-01-01
# 0 0
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] 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
Issue Description
Creating and deleting a column is leading to an unexpected error.
This is a contrived example, but was observed in wild when joining two dataframes which had
MultiIndex
columns with str and timestamp levels with a named index, say'Index'
. The join ends up adding a column('Index', pd.NaT)
then deleting it to set it as the index.Expected Behavior
It should just delete the column.
Installed Versions