Skip to content

BUG: Mismatch between get and set behavior for slices of floating indices #2727

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

Closed
stephenwlin opened this issue Jan 22, 2013 · 4 comments
Closed
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@stephenwlin
Copy link
Contributor

When df.index.inferred_type is 'floating', df.ix[start:end] uses only label-based indexing only when both start and end are floating on the getitem side but when either start or end are floating on the setitem side (where start and end are both either integers or floats within epsilon of integers)

In [2]: df=p.DataFrame(["a", "b", "c", "d"], index=[1.00, 2.00, 3.00, 4.00])

In [3]: df.ix[1.0:4] # uses positional indexing to get last three rows
Out[3]: 
   0
2  b
3  c
4  d

In [4]: df.ix[1.0:4.0] # uses label-based indexing to get all four rows
Out[4]: 
   0
1  a
2  b
3  c
4  d

In [5]: df.ix[1.0:4] = "y" # uses label-based indexing to set all four rows

In [6]: df
Out[6]:
   0
1  y
2  y
3  y
4  y

In [7]: df.ix[1.0:4.0] = "z" # uses label-based indexing to set all four rows

In [8]: df
Out[8]:
   0
1  z
2  z
3  z
4  z
@stephenwlin
Copy link
Contributor Author

Seems like changing the getitem behavior to match setitem breaks lots of unit tests, while the reverse does not, so I will go with the latter...

Results after fix:

In [2]: df=p.DataFrame(["a", "b", "c", "d"], index=[1.00, 2.00, 3.00, 4.00])

In [3]: df.ix[1.0:4] # uses positional indexing to get last three rows
Out[3]:
   0
2  b
3  c
4  d

In [4]: df.ix[1.0:4.0] # uses label-based indexing to get all four rows
Out[4]:
   0
1  a
2  b
3  c
4  d

In [5]: df.ix[1.0:4] = "y" # uses positional indexing to set last three rows

In [6]: df
Out[6]:
   0
1  a
2  y
3  y
4  y

In [7]: df.ix[1.0:4.0] = "z" # uses label-based indexing to set all four rows

In [8]: df
Out[8]:
   0
1  z
2  z
3  z
4  z

@jreback
Copy link
Contributor

jreback commented Feb 26, 2013

did you fix this? or is this informational?

@stephenwlin
Copy link
Contributor Author

yeah, it's "fixed" in #2777 in the sense that the get and set behaviors are consistent now, but they still don't make any sense really...

@jreback
Copy link
Contributor

jreback commented Feb 26, 2013

ahh I see
using floating point indicies is really weird anyhow
in fact probably should outlaw it :)

I mean already have label, integer, datetime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
2 participants