Skip to content

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

Merged
merged 2 commits into from
Nov 24, 2016

Conversation

gfyoung
Copy link
Member

@gfyoung gfyoung commented Nov 22, 2016

Title is self-explanatory. Closes #14712.

Should be merged in before #14295 because the bug could also exist for the Python parser.

@jreback jreback added Bug Dtype Conversions Unexpected or buggy dtype conversions IO CSV read_csv, to_csv labels Nov 22, 2016

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])
Copy link
Contributor

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

Copy link
Member Author

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]))
Copy link
Contributor

Choose a reason for hiding this comment

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

this too

Copy link
Member Author

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'])
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, done.

@codecov-io
Copy link

codecov-io commented Nov 23, 2016

Current coverage is 85.21% (diff: 100%)

Merging #14717 into master will increase coverage by <.01%

@@             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          

Powered by Codecov. Last update 880de30...cee4d6a

@jreback jreback added this to the 0.20.0 milestone Nov 23, 2016
@jreback
Copy link
Contributor

jreback commented Nov 23, 2016

lgtm. I restarted appveyor. If that doesn't pass, then pls have a look @gfyoung
ping when passed / fixed.

@jreback
Copy link
Contributor

jreback commented Nov 23, 2016

I would be fine with this for 0.19.2 a well. @jorisvandenbossche up to you.

@gfyoung
Copy link
Member Author

gfyoung commented Nov 23, 2016

@jreback , @jorisvandenbossche : Everything passing. Ready to merge if there are no other concerns.

@jorisvandenbossche jorisvandenbossche modified the milestones: 0.19.2, 0.20.0 Nov 24, 2016
@jorisvandenbossche jorisvandenbossche merged commit 75b606a into pandas-dev:master Nov 24, 2016
@jorisvandenbossche
Copy link
Member

@gfyoung Thanks. Moved to 0.19.2

@gfyoung gfyoung deleted the csv-empty-dtype branch November 24, 2016 21:21
jorisvandenbossche added a commit to jorisvandenbossche/pandas that referenced this pull request Nov 26, 2016
Issue pandas-dev#14606 was fixed by PR pandas-dev#14717, adding one more specific test to confirm this
jorisvandenbossche added a commit to jorisvandenbossche/pandas that referenced this pull request Nov 26, 2016
Issue pandas-dev#14606 was fixed by PR pandas-dev#14717, adding one more specific test to confirm this
jorisvandenbossche added a commit that referenced this pull request Dec 10, 2016
…14752)

Issue #14606 was fixed by PR #14717, adding one more specific test to confirm this
jorisvandenbossche pushed a commit to jorisvandenbossche/pandas that referenced this pull request Dec 14, 2016
ischurov pushed a commit to ischurov/pandas that referenced this pull request Dec 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants