-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Respect the dtype parameter for empty CSV #14717
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
BUG: Respect the dtype parameter for empty CSV #14717
Conversation
|
||
if index_col is None or index_col is False: | ||
index = Index([]) | ||
else: | ||
index = [np.empty(0, dtype=dtype.get(index_name, np.object)) | ||
index = [np.empty(0, dtype=dtype[index_name]) |
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.
this will break on category
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.
Fixed.
for index_name in index_names] | ||
index = MultiIndex.from_arrays(index, names=index_names) | ||
index_col.sort() | ||
for i, n in enumerate(index_col): | ||
columns.pop(n - i) | ||
|
||
col_dict = dict((col_name, | ||
np.empty(0, dtype=dtype.get(col_name, np.object))) | ||
np.empty(0, dtype=dtype[col_name])) |
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.
this too
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.
Fixed.
dtype={'a': np.float64}) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
expected = pd.DataFrame(columns=['a', 'b']) |
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.
for completeness, can you tests with timedelta/datetime/category 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.
Yep, done.
30ac610
to
f87a976
Compare
Current coverage is 85.21% (diff: 100%)@@ master #14717 diff @@
==========================================
Files 143 143
Lines 50796 50800 +4
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 43285 43289 +4
Misses 7511 7511
Partials 0 0
|
f87a976
to
cee4d6a
Compare
lgtm. I restarted appveyor. If that doesn't pass, then pls have a look @gfyoung |
I would be fine with this for 0.19.2 a well. @jorisvandenbossche up to you. |
@jreback , @jorisvandenbossche : Everything passing. Ready to merge if there are no other concerns. |
@gfyoung Thanks. Moved to 0.19.2 |
Issue pandas-dev#14606 was fixed by PR pandas-dev#14717, adding one more specific test to confirm this
Issue pandas-dev#14606 was fixed by PR pandas-dev#14717, adding one more specific test to confirm this
…y CSV (pandas-dev#14717) (cherry picked from commit 75b606a)
…andas-dev#14752) Issue pandas-dev#14606 was fixed by PR pandas-dev#14717, adding one more specific test to confirm this
Title is self-explanatory. Closes #14712.
Should be merged in before #14295 because the bug could also exist for the Python parser.