Skip to content
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

DataFrame with DatetimeIndex is shown as RangeIndex #196

Closed
juanfcocontreras opened this issue May 3, 2020 · 4 comments
Closed

DataFrame with DatetimeIndex is shown as RangeIndex #196

juanfcocontreras opened this issue May 3, 2020 · 4 comments

Comments

@juanfcocontreras
Copy link

When I try to show a DataFrame that has an index of type DatetimeIndex, in dtale it is shown as a RangeIndex.

It would be very useful to display that DatetimeIndex.

Sample code:

import pandas as pd
import pandas._testing as tm

df = tm.makeTimeDataFrame()
df

Capto_Capture 2020-05-03_05-03-28_p  m

from dtale import show

show(df)

Capto_Capture 2020-05-03_05-03-46_p  m

@aschonfeld
Copy link
Collaborator

So in order to get this to work correctly you would have to updated your code to this:

import dtale
import pandas._testing as tm

df = tm.makeTimeDataFrame()
df.index.name = 'date_index'
dtale.show(df)

The problem is that on startup it doesn't maintain indexes because it would be too hard to keep track of. So it runs .reset_index() on any startup and drops any columns names index by default. Because in most instances users are giving dataframes with index names and it will the resulting columns after the reset_index() call will be pre-locked on the grid (to show the users they were the original index).

The best option I can offer other than the code fix above is that I can check to see if the index on the dataframe is not dtype('int64') (which is the default 0 to n-1 natural index in pandas) and if it isn't then I will allow the default naming convention of "index" to pass through for those.

But the best solution is to just include a name on any index column that isn't "index".

Hope this helps!

@juanfcocontreras
Copy link
Author

The best option I can offer other than the code fix above is that I can check to see if the index on the dataframe is not dtype('int64') (which is the default 0 to n-1 natural index in pandas) and if it isn't then I will allow the default naming convention of "index" to pass through for those.

I think that alternative would be great, but while this workaround is enough for me.

Thank you very much!

@juanfcocontreras
Copy link
Author

juanfcocontreras commented May 4, 2020

I think it would be better to do the following check instead of df.index.dtype != "int64". This way you could have a custom RangeIndex and it would be kept.

if not df.index.equals(pd.RangeIndex(0, len(df))):
...

aschonfeld added a commit that referenced this issue May 5, 2020
* #196: dataframes that have datatime indexes without a name
aschonfeld added a commit that referenced this issue May 5, 2020
* #196: dataframes that have datatime indexes without a name
aschonfeld added a commit that referenced this issue May 15, 2020
* #196: dataframes that have datatime indexes without a name
* jest test refactoring
* fix for CicleCI JS memory issues
* Added the ability to apply formats to all columns of same dtype
@aschonfeld aschonfeld mentioned this issue May 15, 2020
aschonfeld added a commit that referenced this issue May 15, 2020
* #196: dataframes that have datatime indexes without a name
* jest test refactoring
* fix for CicleCI JS memory issues
* Added the ability to apply formats to all columns of same dtype
aschonfeld added a commit that referenced this issue May 15, 2020
* #196: dataframes that have datatime indexes without a name
* jest test refactoring
* fix for CicleCI JS memory issues
* Added the ability to apply formats to all columns of same dtype
aschonfeld added a commit that referenced this issue May 15, 2020
* #196: dataframes that have datatime indexes without a name
* jest test refactoring
* fix for CicleCI JS memory issues
* Added the ability to apply formats to all columns of same dtype
@aschonfeld
Copy link
Collaborator

Added v1.8.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants