-
Notifications
You must be signed in to change notification settings - Fork 301
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
Crashes with Period column or index #14048
Comments
Thansk I can replicate this issue, basically it comes down to |
Cool, thanks for that. FYI I've added a comment here in the Pandas repo, not sure if it's on their radar. One fix might be to be to convert all periods to date time, but you'd need to handle the case of a multi-index where only one of the indexes is Period (my use case and a common-ish format in hierarchical time series analysis). With very little testing, this seems to work... import pandas as pd
df = pd.DataFrame(
dict(
A=[1, 2, 12],
B=[1, 2, 12],
C=[1, 2, 12],
Date1=pd.period_range("2000-01-01", periods=3, freq="A"),
Date2=pd.period_range("2000-01-01", periods=3),
Date3=pd.date_range("2000-01-01", periods=3),
)
).set_index(["A", "Date1"])
def periods_to_timestamps(df):
new_df = df.copy()
for col_name, col in df.items():
if pd.api.types.is_period_dtype(col):
new_df[col_name] = col.dt.to_timestamp()
for level in range(df.index.nlevels):
index = df.index.get_level_values(level)
if pd.api.types.is_period_dtype(index):
new_df.index = new_df.index.set_levels(index.to_timestamp(), level=level)
return new_df
df2 = periods_to_timestamps(df) |
closing as the jupyter data viewer was deprecated #15486 |
Environment data
I'm using Pandas
2.0.3
. This happens in a WSL setup as well as just running in Windows.I didn't explicitly install Jupyter or IPython, I just let VS Code do whatever it had to do (install i-something-kernel to run the interactive window).
Expected behaviour
I should be able to view a DataFrame with the
Period
type in it (column or index).Actual behaviour
The data viewer crashes
Steps to reproduce:
venv
environment, installpandas
.test.py
with the contents:In VS Code, do
![image](https://private-user-images.githubusercontent.com/4443482/258010180-424032f2-f5f9-462b-bbc7-913e717a5343.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDAwMDc3MjUsIm5iZiI6MTc0MDAwNzQyNSwicGF0aCI6Ii80NDQzNDgyLzI1ODAxMDE4MC00MjQwMzJmMi1mNWY5LTQ2MmItYmJjNy05MTNlNzE3YTUzNDMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTlUMjMyMzQ1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MWYxYTI2NDE5OGVkMmVmZTc3ZGFhMzdiNDkxNWRiZGFiYThkNDk0MTliMGY5MDVlY2M1ZjBlNDNkYjQ1ZTM0ZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.pg-4QiTtQHrO7D51cI0Yca8b73d2slzMIG6Iy42r5lg)
Run Current File in Interactive Window
. Confirm the dataframe shows just fine in the interactive window:Click
Variables
in the interactive window, and try to view thedf
variable in the data viewer. Then it crashes.I found this issue #10446 but it was closed as a Pandas issue.
Logs
These logs are when testing with WSL, they're much the same with plain Windows.
Output for
Jupyter
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toJupyter
)The text was updated successfully, but these errors were encountered: