-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Iterableiterator #12173
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
Iterableiterator #12173
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
|
||
from pandas.io import common | ||
|
||
from pandas import read_csv, concat | ||
|
||
try: | ||
from pathlib import Path | ||
except ImportError: | ||
|
@@ -21,6 +23,14 @@ | |
|
||
|
||
class TestCommonIOCapabilities(tm.TestCase): | ||
data1 = """index,A,B,C,D | ||
foo,2,3,4,5 | ||
bar,7,8,9,10 | ||
baz,12,13,14,15 | ||
qux,12,13,14,15 | ||
foo2,12,13,14,15 | ||
bar2,12,13,14,15 | ||
""" | ||
|
||
def test_expand_user(self): | ||
filename = '~/sometest' | ||
|
@@ -64,3 +74,16 @@ def test_get_filepath_or_buffer_with_buffer(self): | |
input_buffer = StringIO() | ||
filepath_or_buffer, _, _ = common.get_filepath_or_buffer(input_buffer) | ||
self.assertEqual(filepath_or_buffer, input_buffer) | ||
|
||
def test_iterator(self): | ||
reader = read_csv(StringIO(self.data1), chunksize=1) | ||
result = concat(reader, ignore_index=True) | ||
expected = read_csv(StringIO(self.data1)) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# GH12153 | ||
it = read_csv(StringIO(self.data1), chunksize=1) | ||
first = next(it) | ||
tm.assert_frame_equal(first, expected.iloc[[0]]) | ||
expected.index = [0 for i in range(len(expected))] | ||
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. Each chunk has an index restarting from 0 (also in 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. No, that shouldn't be the case
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. I mean when the index is not loaded:
Wouldn't we prefer a consistent index? 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. hmm yes I agree you'd have to keep state in the in the iterators I think though - but might be a bit non trivial if u think u can fix easily - go ahead 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. No, I'd like to do it but it probably won't be immediate: #12185 . |
||
tm.assert_frame_equal(concat(it), expected.iloc[1:]) |
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 tests for
read_stata
&read_sas
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.
yep, done