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.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
>>> import pandas as pd
>>> pd.DataFrame([1]).index
RangeIndex(start=0, stop=1, step=1) # ok
>>> pd.DataFrame().index
Index([], dtype='object') # not ok
>>> pd.Series([1]).index
RangeIndex(start=0, stop=1, step=1) # ok
>>> pd.Series([]).index
RangeIndex(start=0, stop=0, step=1) # ok
>>> pd.Series().index
Index([], dtype='object') # not ok
Issue Description
When users don't specify indexes, pandas infers the index type for them. It infers to be a RangeIndex
, except when the frame/series is emtpy, then the index is inferred to be a Index[object]
.
The type of index should be consistently RangeIndex, when users don't declare the index. Same for columns.
Expected Behavior
Empty frames/series should have index/columns like RangeIndex(0)
instead an empty object index.
Found working on #49560.
Installed Versions
Comment From: ramvikrams
Sir I looked in the series/frame.py files to find the places to be changed but I was unsuccesful so can you please guide
Comment From: topper-123
Hi @ramvikrams. Thanks for taking a look at it:-) I didn’t know where to change the code when I wrote the issue, it’s just going head first in and grinding till I figured it out :-).
You can see the results of my own work in the linked PR #49637. However it turns out that adjusting the test suite is quite a lot of work, so if you want to help out, I’d absolutely appreciate it.
For example, you could take on some subset of the test suite and make it pass. I’ve already done tests/frame, tests/series and tests/indexing, but there are several others with failing tests in #49637 that you could take on. I think you should be able to just push your changes to my branch and I’ll review and merge it when ok.
Maybe you will want to see if my question in #49637 are answered positively before starting just in case the other devs think differently about this…
Comment From: ramvikrams
thanks @topper-123 sir. I will surely take a look at the linked pr and try to add try to add the tests . Thank you again sir for your help.
Comment From: ramvikrams
Sir it will take some time for writing tests have some college work this weekend.
Comment From: topper-123
Alright no problem. If you got the time you're welcome to join back in (or do other separate PRs if that is more to your liking).
Comment From: ramvikrams
Alright no problem. If you got the time you're welcome to join back in (or do other separate PRs if that is more to your liking).
i'll join back sir
Comment From: rhshadrach
+1, cc @jbrockmendel @phofl