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
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
Installed Versions
Comment From: rhshadrach
Thanks for the report - confirmed on main. Further investigations and PRs to fix are welcome!
Comment From: jbrockmendel
This works on main. Could use a test.
Comment From: skalwaghe-56
take
Comment From: Tsarnas2003
take
Comment From: skalwaghe-56
@Tsarnas2003 Actually, I have already raised a PR and it just needs to be merged. Thanks for your interest, you can checkout some other issue.
Comment From: Tsarnas2003
@Tsarnas2003 Actually, I have already raised a PR and it just needs to be merged. Thanks for your interest, you can checkout some other issue.
I am looking for a good new issue to work on as a beginner can you lead me in the right direction
Comment From: skalwaghe-56
@Tsarnas2003 Actually, I have already raised a PR and it just needs to be merged. Thanks for your interest, you can checkout some other issue.
I am looking for a good new issue to work on as a beginner can you lead me in the right direction
I would suggest you to go through the following page: https://github.com/pandas-dev/pandas/contribute It has some good first issues recommended for newbies. Have a look and work on what you would like!