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

REGR: empty list selection resets index types #7774

Closed
jreback opened this issue Jul 17, 2014 · 14 comments · Fixed by #8462
Closed

REGR: empty list selection resets index types #7774

jreback opened this issue Jul 17, 2014 · 14 comments · Fixed by #8462
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Jul 17, 2014

regression from 0.14.0 (which return Index, which is also not correct).

iloc DOES work correctly though

In [9]: df = tm.makeTimeDataFrame()

In [10]: df.index
Out[10]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-03, ..., 2000-02-11]
Length: 30, Freq: B, Timezone: None

In [11]: df.loc[[]].index
Out[11]: Float64Index([], dtype='float64')

# this is the correct result
In [4]: df.iloc[[]].index
Out[4]: 
<class 'pandas.tseries.index.DatetimeIndex'>
Length: 0, Freq: None, Timezone: None
In [7]: p = tm.makePanel()

In [8]: p.major_axis
Out[8]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-03, ..., 2000-02-11]
Length: 30, Freq: B, Timezone: None

In [9]: p.loc[:,[],:].major_axis
Out[9]: Float64Index([], dtype='float64')
@jreback jreback added this to the 0.15.0 milestone Jul 17, 2014
@jreback
Copy link
Contributor Author

jreback commented Jul 17, 2014

cc @immerrr I don't remember changing anything specifically.....any thoughts?

@cpcloud
Copy link
Member

cpcloud commented Jul 17, 2014

I can take a look at this.

@jreback
Copy link
Contributor Author

jreback commented Jul 17, 2014

@cpcloud gr8!

@immerrr
Copy link
Contributor

immerrr commented Jul 17, 2014

Got it running a debugger for a bit: there's a point when ax.reindex(new_labels) is invoked and at that point new_labels has gone all the way of [] -> np.array([], dtype=float) -> Index(np.array([], dtype=float)) -> Float64Index([]). If you skip conversion to ndarray, you get Index([]) which is what I see on v0.14.0:

In [1]: pd.Series(index=pd.date_range('2013', periods=20))
Out[1]: 
2013-07-17   NaN
2013-07-18   NaN
2013-07-19   NaN
2013-07-20   NaN
2013-07-21   NaN
2013-07-22   NaN
2013-07-23   NaN
2013-07-24   NaN
2013-07-25   NaN
2013-07-26   NaN
2013-07-27   NaN
2013-07-28   NaN
2013-07-29   NaN
2013-07-30   NaN
2013-07-31   NaN
2013-08-01   NaN
2013-08-02   NaN
2013-08-03   NaN
2013-08-04   NaN
2013-08-05   NaN
Freq: D, dtype: float64

In [2]: _1.loc[[]]
Out[2]: Series([], dtype: float64)

In [3]: _1.loc[[]].index
Out[3]: Index([], dtype='object')

In [4]: pd.__version__
Out[4]: '0.14.0'

May be Index.reindex should be smarter about preserving type & metadata of the original container. Incidentally, I've recently encountered the same problem when investigating this issue.

@jreback
Copy link
Contributor Author

jreback commented Jul 17, 2014

@immerrr thanks, yes I think .reindex should try to preserve if at all possible (might need something special for the 0-len case, but prob just a big buggy somewhere)

@immerrr
Copy link
Contributor

immerrr commented Jul 17, 2014

All magic happens here, I don't see anything terribly out of line.

@jreback
Copy link
Contributor Author

jreback commented Jul 17, 2014

so either take and/or reindex_axis are not preserving (dtype, maybe other attributes) on 0-len then.

@jreback
Copy link
Contributor Author

jreback commented Jul 17, 2014

bet its getting passed correctly in take, but then re-inferred in the constructor which then returns Index or (something else). prob need to explicity pass in dtype in _simple_new

@immerrr
Copy link
Contributor

immerrr commented Jul 17, 2014

It's reindex_axis, yes. _asarray_tuplesafe([]) produces array([], dtype=float) which is then passed to Index.reindex, which brings us to the question above.

@jreback
Copy link
Contributor Author

jreback commented Jul 17, 2014

yep, which then takes the character of the passed in index.

@jreback
Copy link
Contributor Author

jreback commented Sep 9, 2014

@immerrr doable for 0.15.0?

@immerrr
Copy link
Contributor

immerrr commented Sep 10, 2014

Yes, it's the same as #6552.

@jreback
Copy link
Contributor Author

jreback commented Sep 30, 2014

@immerrr ?

@immerrr
Copy link
Contributor

immerrr commented Oct 2, 2014

Will do at the weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants