-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
allow using Iterable in Series and DataFrame constructor #21987
allow using Iterable in Series and DataFrame constructor #21987
Conversation
This test failed. But a single-column pandas/pandas/tests/frame/test_constructors.py Lines 868 to 872 in 27ebb3e
pd.DataFrame((1, 2, 3))
# 0
#0 1
#1 2
#2 3 |
b498a5c
to
d1c1bc2
Compare
|
||
expected = Series(list(range(10)), dtype='int64') | ||
result = Series(range(10), dtype='int64') | ||
result = Series(Iter(), dtype='int64') |
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.
cant this simply be iter(range(10))
?
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.
range
is list-like, subclass of Sequence
, which doesn't need consuming by data = list(data)
. I'd like to add back range(10)
test and keep both.
d1c1bc2
to
4fb3b38
Compare
Allow |
Codecov Report
@@ Coverage Diff @@
## master #21987 +/- ##
==========================================
- Coverage 92.02% 92.02% -0.01%
==========================================
Files 170 170
Lines 50707 50704 -3
==========================================
- Hits 46661 46658 -3
Misses 4046 4046
Continue to review full report at Codecov.
|
expected = DataFrame([[1, 2, 3]] * 10) | ||
result = DataFrame(Iter()) | ||
tm.assert_frame_equal(result, expected) | ||
|
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.
Reference the issue number in a comment below the functional definition.
Applies to all newly-added tests.
4fb3b38
to
166f4f6
Compare
Context: That goes back a long way to DataMatrix: c34ac74#diff-225c6e44f997b9b698ab52a48b223018R39 +1 for allowing it. |
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.
Merging later today, unless someone else beats me to it.
will have a look don’t merge |
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.
pls add a whatsnew note, other enhancements in 0.24
pandas/core/frame.py
Outdated
@@ -390,8 +390,9 @@ def __init__(self, data=None, index=None, columns=None, dtype=None, | |||
else: | |||
mgr = self._init_ndarray(data, index, columns, dtype=dtype, | |||
copy=copy) | |||
elif isinstance(data, (list, types.GeneratorType)): | |||
if isinstance(data, types.GeneratorType): | |||
elif (isinstance(data, collections.Iterable) |
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.
can you add a comment here (1 line above) which defines what this clause is checking
pandas/core/series.py
Outdated
elif isinstance(data, (set, frozenset)): | ||
raise TypeError("{0!r} type is unordered" | ||
"".format(data.__class__.__name__)) | ||
elif (isinstance(data, collections.Iterable) |
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.
same
166f4f6
to
a2ace52
Compare
thanks @holymonson ! |
git diff upstream/master -u -- "*.py" | flake8 --diff
@TomAugspurger Hope you can review this.
BTW, perhpas you may want to change
Iterable
inis_list_like()
toSequence
.