question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

to_csv regression in 0.23.1

See original GitHub issue

Writing to gzip no longer works with 0.23.1:

with gzip.open('test.txt.gz', 'wt') as f:
    pd.DataFrame([0,1],index=['a','b'], columns=['c']).to_csv(f, sep='\t')

produces corrupted output. This works fine in 0.23.0.

Presumably this is related to #21241 and #21118.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
saidiecommented, Jun 14, 2018

Hi, I also encountered a to_csv problem on 0.23.1 although my case is different to others:

import sys
import pandas as pd
df = pd.DataFrame([0,1])
df.to_csv(sys.stdout)

This code writes the dataframe to a file named <stdout> while it is expected to be printed out to the stdout.

2reactions
littleK0icommented, Jun 14, 2018

@WillAyd , I did a quick research.

It seems that all “file-like” objects which cannot be converted to string file paths are affected. Gzip wrapper, stdout, FD’s - all these problems have the same origin.

Example with FD:

import pandas
import os

with os.fdopen(3, 'w') as f:
    print(f)
    pandas.DataFrame([0, 1]).to_csv(f)

Output:

<_io.TextIOWrapper name=3 mode='w' encoding='UTF-8'>
Traceback (most recent call last):
  File "gg.py", line 6, in <module>
    pandas.DataFrame([0, 1]).to_csv(f)
  File "/Users/wr/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py", line 1745, in to_csv
    formatter.save()
  File "/Users/wr/anaconda3/lib/python3.6/site-packages/pandas/io/formats/csvs.py", line 166, in save
    f.write(buf)
AttributeError: 'int' object has no attribute 'write'

I guess, integer comes from “name” attribute of TextIOWrapper. For STDOUT it will be <stdout>, etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Release Notes — pandas 0.23.1 documentation - PyData |
This is a minor bug-fix release in the 0.21.x series and includes some small regression fixes, bug fixes and performance improvements.
Read more >
Reading csv to array, performing linear regression on array ...
I think you should be able to do this in a fairly simple script using glob to iterate through your files, and pandas...
Read more >
Regression Examples
Automatically back-transforms estimates and confidence intervals, when the model requires it. Can use robust standard errors for the calculation ...
Read more >
Interpret Poisson Regression Coefficients - Quantifying Health
What is this? In this case: eβ 1 = e0.23 = 1.26 can be interpreted as follows: Going up from 1 level of...
Read more >
sklearn.linear_model.LinearRegression
Ordinary least squares Linear Regression. LinearRegression fits a linear model with coefficients w = (w1, …, wp) to minimize the residual sum of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found