Skip to content

add test case when to_csv argument is sys.stdout #21572

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 7 commits into from
Jun 22, 2018

Conversation

r00ta
Copy link
Contributor

@r00ta r00ta commented Jun 21, 2018

Add new test case when to_csv argument is sys.stdout

@pep8speaks
Copy link

pep8speaks commented Jun 21, 2018

Hello @r00ta! Thanks for updating the PR.

Line 291:60: W291 trailing whitespace

Comment last updated on June 22, 2018 at 13:01 Hours UTC

def test_to_csv_stdout_file(self):
# GH 21561
str_array = [{'names': ['foo', 'bar']}, {'names': ['baz', 'qux']}]
df = pd.DataFrame(str_array)
Copy link
Contributor

Choose a reason for hiding this comment

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

might be simpler to:
DataFrame([['foo', 'bar'], ['baz', 'qux']], columns=['name_1', 'name_2'])

output = out.getvalue()
assert output == expected_ascii
sys.stdout = saved_stdout
assert sys.stdout.closed is False
Copy link
Contributor

@minggli minggli Jun 21, 2018

Choose a reason for hiding this comment

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

I would do below instead:
assert not sys.stdout.closed

@WillAyd
Copy link
Member

WillAyd commented Jun 21, 2018

Is it possible to parametrize this as a value in an existing test rather than adding a separate test case?

Copy link
Contributor

@minggli minggli left a comment

Choose a reason for hiding this comment

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

there appear to be an existing pandas.util.testing.capture_stdout decorator

@codecov
Copy link

codecov bot commented Jun 21, 2018

Codecov Report

Merging #21572 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21572      +/-   ##
==========================================
+ Coverage    91.9%    91.9%   +<.01%     
==========================================
  Files         153      153              
  Lines       49557    49549       -8     
==========================================
- Hits        45545    45539       -6     
+ Misses       4012     4010       -2
Flag Coverage Δ
#multiple 90.3% <ø> (ø) ⬆️
#single 41.78% <ø> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/util/testing.py 85.27% <0%> (ø) ⬆️
pandas/core/generic.py 96.22% <0%> (ø) ⬆️
pandas/core/tools/numeric.py 100% <0%> (ø) ⬆️
pandas/core/indexing.py 93.37% <0%> (+0.13%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1638331...b250259. Read the comment docs.

@r00ta
Copy link
Contributor Author

r00ta commented Jun 21, 2018

Thanks for the tips! I've updated the PR :D

@gfyoung gfyoung added Testing pandas testing functions or related to the test suite IO Data IO issues that don't fit into a more specific label labels Jun 21, 2018
@gfyoung
Copy link
Member

gfyoung commented Jun 21, 2018

@r00ta : You have a couple of linting errors:

https://travis-ci.org/pandas-dev/pandas/jobs/395098214#L2876

@jreback jreback added this to the 0.24.0 milestone Jun 22, 2018
@jreback
Copy link
Contributor

jreback commented Jun 22, 2018

lgtm. merge on green.

@@ -6,7 +6,7 @@
import pytest
from pandas import DataFrame
from pandas.util import testing as tm

from pandas.util.testing import capture_stdout
Copy link
Contributor

Choose a reason for hiding this comment

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

would it be possible to use tm.capture_stdout rather add another import?

Copy link
Contributor

Choose a reason for hiding this comment

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

good point!

@jorisvandenbossche jorisvandenbossche modified the milestones: 0.24.0, 0.23.2 Jun 22, 2018
@jorisvandenbossche
Copy link
Member

The remaining failure is a linting error:

pandas/tests/io/formats/test_to_csv.py:10:1: E302 expected 2 blank lines, found 1
pandas/tests/io/formats/test_to_csv.py:291:60: W291 trailing whitespace

@jreback jreback modified the milestones: 0.23.2, 0.24.0 Jun 22, 2018
@jreback jreback merged commit 66fea91 into pandas-dev:master Jun 22, 2018
@jreback
Copy link
Contributor

jreback commented Jun 22, 2018

thanks @r00ta

jorisvandenbossche pushed a commit that referenced this pull request Jun 29, 2018
jorisvandenbossche pushed a commit that referenced this pull request Jul 2, 2018
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO Data IO issues that don't fit into a more specific label Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test Case for to_csv to sys.stdout
7 participants