Skip to content

ERR: Add check for iterators when creating DataFrame, fixes #5357 #6977

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
Apr 27, 2014

Conversation

onesandzeroes
Copy link
Contributor

This is a fix for #5357, and adds a more helpful error message when trying to use an iterator as the data argument for a DataFrame. I've added the type check for iterators in the final else clause where all the valid options have already been exhausted, so it shouldn't interfere with any valid cases like passing a list of iterators.

@jtratner
Copy link
Contributor

Thanks for the PR! One key thing this needs is a test case demonstrating the error. Also, stylistically, it would be nicer/clearer to move this up a level (ie as an elif rather than a nested if). Would you mind making that change?

When the above is addressed we can mergw

@onesandzeroes
Copy link
Contributor Author

Alright, I've added a (simple) test case to test_frame.py and moved the type check up two levels, since that's where the rest of the explicit type checks are happening.

@@ -3121,6 +3121,10 @@ def test_constructor_miscast_na_int_dtype(self):
expected = DataFrame([[np.nan, 1], [1, 0]])
assert_frame_equal(df, expected)

def test_constructor_iterator_failure(self):
with assertRaises(TypeError):
Copy link
Contributor

Choose a reason for hiding this comment

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

hey sorry to be nitpicky here, can you change this to with assertRaisesRegexp(TypeError, 'iterator')? we like to avoid straight TypeError checks because they can be raised from wrong type signatures.

@jtratner
Copy link
Contributor

@onesandzeroes looks great - can you repush your branch so Travis can retry the tests? The build failed because of unrelated network issues.

@jreback
Copy link
Contributor

jreback commented Apr 27, 2014

@onesandzeroes pls add a release notes in the API section referecing the issue, other looks good

@jreback jreback added this to the 0.14.0 milestone Apr 27, 2014
@onesandzeroes
Copy link
Contributor Author

Alright, should be all set now, thanks for walking me through the steps that needed to be done!

@jreback
Copy link
Contributor

jreback commented Apr 27, 2014

gr8!

if you want to try your git-fu, squash down to 1 commit (if you can't I will do it...but good practice)

see here: https://github.com/pydata/pandas/wiki/Using-Git

ping me when squashed / green

Add test case for iterator data argument

Move the type check up to where other checks are performed

Use asserRaisesRegexp for more specific checking

Add fix to the release notes
@onesandzeroes
Copy link
Contributor Author

OK, should be squashed into a single commit now.

jreback added a commit that referenced this pull request Apr 27, 2014
ERR: Add check for iterators when creating DataFrame, fixes #5357
@jreback jreback merged commit b9efa31 into pandas-dev:master Apr 27, 2014
@jreback
Copy link
Contributor

jreback commented Apr 27, 2014

@onesandzeroes thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants