-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: constructing a DataFrame using range doesn't work #26343
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
jreback
merged 2 commits into
pandas-dev:master
from
topper-123:dataframe_range_constructor
May 12, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,11 +33,13 @@ class TestDataFrameConstructors(TestData): | |
lambda: DataFrame(()), | ||
lambda: DataFrame([]), | ||
lambda: DataFrame((x for x in [])), | ||
lambda: DataFrame(range(0)), | ||
lambda: DataFrame(data=None), | ||
lambda: DataFrame(data={}), | ||
lambda: DataFrame(data=()), | ||
lambda: DataFrame(data=[]), | ||
lambda: DataFrame(data=(x for x in [])) | ||
lambda: DataFrame(data=(x for x in [])), | ||
lambda: DataFrame(data=range(0)), | ||
]) | ||
def test_empty_constructor(self, constructor): | ||
expected = DataFrame() | ||
|
@@ -999,6 +1001,17 @@ def __len__(self, n): | |
array.array('i', range(10))]) | ||
tm.assert_frame_equal(result, expected, check_dtype=False) | ||
|
||
def test_constructor_range(self): | ||
# GH26342 | ||
result = DataFrame(range(10)) | ||
expected = DataFrame(list(range(10))) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_constructor_list_of_ranges(self): | ||
result = DataFrame([range(10), range(10)]) | ||
expected = DataFrame([list(range(10)), list(range(10))]) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_constructor_iterable(self): | ||
# GH 21987 | ||
class Iter: | ||
|
@@ -1011,9 +1024,13 @@ def __iter__(self): | |
tm.assert_frame_equal(result, expected) | ||
|
||
def test_constructor_iterator(self): | ||
result = DataFrame(iter(range(10))) | ||
expected = DataFrame(list(range(10))) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_constructor_list_of_iterators(self): | ||
result = DataFrame([iter(range(10)), iter(range(10))]) | ||
expected = DataFrame([list(range(10)), list(range(10))]) | ||
result = DataFrame([range(10), range(10)]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A plain The range case is now placed in |
||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_constructor_generator(self): | ||
|
@@ -2251,8 +2268,13 @@ def test_to_frame_with_falsey_names(self): | |
|
||
@pytest.mark.parametrize('dtype', [None, 'uint8', 'category']) | ||
def test_constructor_range_dtype(self, dtype): | ||
# GH 16804 | ||
expected = DataFrame({'A': [0, 1, 2, 3, 4]}, dtype=dtype or 'int64') | ||
|
||
# GH 26342 | ||
result = DataFrame(range(5), columns=['A'], dtype=dtype) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# GH 16804 | ||
result = DataFrame({'A': range(5)}, dtype=dtype) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would reference the issue as a comment above this line as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is just an existing test that has been moved. It already passed before this PR.