Skip to content

BUG/ER: (GH2702) Bug with Series indexing not raising an error when the right-hand-side has an incorrect length #4756

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

Merged
merged 1 commit into from
Sep 6, 2013

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Sep 5, 2013

closes #2702

Base use cases (note that a completely changed series will morph to the new dtype if necessary)

In [1]: s = Series(list('abc'))
In [2]: s[0:3] = list(range(3))

In [3]: s
Out[3]: 
0    0
1    1
2    2
dtype: int64

In [4]: s = Series(list('abc'))

In [5]: s[0:2] = list(range(2))

In [6]: s
Out[6]: 
0    0
1    1
2    c
dtype: object

This is a bit odd, but allowed

In [4]: s[0] = list(range(10))

In [5]: s
Out[5]: 
0    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
1                                 b
2                                 c
dtype: object

These all will raise error messages now

In [1]: s = Series(list('abc'))

In [2]: s[0:3] = list(range(27))
ValueError: cannot set using a slice indexer with a different length than the value

In [3]: s[[0,1,2]] = list(range(27))
ValueError: cannot set using a list-like indexer with a different length than the value

In [4]: s[[0,1,2]] = list(range(2))
ValueError: cannot set using a list-like indexer with a different length than the value

With a step and a slice indexer (not sure was tested before)

When the length of the slicer matches exactly it works

In [5]: s = Series(list('abcdef'))

In [6]: s[0:4:2] = list(range(2))

In [7]: s
Out[7]: 
0    0
1    b
2    1
3    d
4    e
5    f
dtype: object

Raises when it doesn't

In [8]: s[0:4:2] = list(range(27))
ValueError: cannot set using a slice indexer with a different length than the value

@jreback
Copy link
Contributor Author

jreback commented Sep 5, 2013

@cpcloud @jtratner pls have a look when you can

step = indexer.step
if start is None:
start = 0
elif start < 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be tests for negative slices? Or are those somewhere else?

@jreback
Copy link
Contributor Author

jreback commented Sep 5, 2013

there are some in test_frame

jreback added a commit that referenced this pull request Sep 6, 2013
BUG/ER:  (GH2702) Bug with Series indexing not raising an error when the right-hand-side has an incorrect length
@jreback jreback merged commit 67229f0 into pandas-dev:master Sep 6, 2013
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

Successfully merging this pull request may close these issues.

Bug in Fancy/Boolean Indexing with nested lists
2 participants