Skip to content

ENH: Add to_latex() method to Series (#16180) #16465

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 4 commits into from
May 26, 2017

Conversation

bsweger
Copy link
Contributor

@bsweger bsweger commented May 23, 2017

This changeset adds repr_latex to the Series class and moves
the to_latex() method from the DataFrame class to the NDFrame
class.

This changeset adds _repr_latex_ to the Series class and moves
the to_latex() method from the DataFrame class to the NDFrame
class.
@bsweger bsweger force-pushed the series_latex_enhancements branch from 3207a33 to 74889fc Compare May 23, 2017 22:56
Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

Sorry I missed this yesterday. A couple of comments.

Could you also add some tests for Series.to_latex directly (keep the one testing _repr_latex_ though. They can go in pandas/tests/io/formats/test_to_latex.py

Thanks!

column_format=None, longtable=None, escape=None,
encoding=None, decimal='.', multicolumn=None,
multicolumn_format=None, multirow=None):
# Get defaults from the pandas config
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you'll need to start this with

if self.ndim == 1:
    self = self.to_frame()

then the rest of it should be ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for this suggestion--doing the check here rather than invoking to_frame() in the Series _repr_latex method makes a lot of sense.

@@ -391,6 +391,16 @@ def get_values(self):
""" same as values (but handles sparseness conversions); is a view """
return self._data.get_values()

def _repr_latex_(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you actually remove this and move the _repr_latex_ from pandas/core/frame.py and to NDFrame in pandas/core/generic.py?

@TomAugspurger TomAugspurger modified the milestones: 0.21.0, 0.20.2 May 24, 2017
Rebecca Sweger added 2 commits May 25, 2017 23:38
Streamline things a bit by moving _repr_latex_ methods out of
the Series and DataFrame classes
@codecov
Copy link

codecov bot commented May 26, 2017

Codecov Report

Merging #16465 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16465      +/-   ##
==========================================
+ Coverage   90.42%   90.42%   +<.01%     
==========================================
  Files         161      161              
  Lines       51027    51032       +5     
==========================================
+ Hits        46142    46147       +5     
  Misses       4885     4885
Flag Coverage Δ
#multiple 88.26% <100%> (ø) ⬆️
#single 40.17% <26.08%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/frame.py 97.67% <ø> (-0.02%) ⬇️
pandas/core/generic.py 92.2% <100%> (+0.07%) ⬆️
pandas/core/series.py 94.73% <100%> (+0.01%) ⬆️

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 04356a8...e57acc2. Read the comment docs.

@codecov
Copy link

codecov bot commented May 26, 2017

Codecov Report

Merging #16465 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16465      +/-   ##
==========================================
+ Coverage   90.42%   90.43%   +<.01%     
==========================================
  Files         161      161              
  Lines       51027    51048      +21     
==========================================
+ Hits        46142    46164      +22     
+ Misses       4885     4884       -1
Flag Coverage Δ
#multiple 88.27% <100%> (ø) ⬆️
#single 40.16% <24%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/frame.py 97.66% <ø> (-0.03%) ⬇️
pandas/core/generic.py 92.26% <100%> (+0.13%) ⬆️
pandas/io/feather_format.py 85.71% <0%> (-2.17%) ⬇️
pandas/io/parsers.py 95.33% <0%> (+0.01%) ⬆️
pandas/core/ops.py 91.69% <0%> (+0.01%) ⬆️
pandas/plotting/_core.py 81.92% <0%> (+0.02%) ⬆️
pandas/core/window.py 96.48% <0%> (+0.23%) ⬆️

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 04356a8...95ab565. Read the comment docs.

@bsweger
Copy link
Contributor Author

bsweger commented May 26, 2017

@TomAugspurger Thanks for the review! Moved things around per your suggestions and added a test explicitly for Series.to_latex(). It's a very simple test to make sure the function works; wasn't sure if the entire suite of dataframe-related latex test options was worth repeating for a series. Happy to add more if you think it's helpful.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented May 26, 2017

@bsweger this looks fantastic. I'm pushing a tiny doc change that I forgot to ask for (adding a note that it was added to series in 0.20.2), then merging.

95ab565 has the doc fixup.

Thanks!

@TomAugspurger TomAugspurger merged commit 6a6227d into pandas-dev:master May 26, 2017
TomAugspurger pushed a commit to TomAugspurger/pandas that referenced this pull request May 29, 2017
…6465)

* ENH: Add to_latex() method to Series (pandas-dev#16180)

This changeset adds _repr_latex_ to the Series class and moves
the to_latex() method from the DataFrame class to the NDFrame
class.

* Add Series to_latex test

* Move _repr_latex_ to NDFrame

Streamline things a bit by moving _repr_latex_ methods out of
the Series and DataFrame classes

* DOC: Added versionchanged

(cherry picked from commit 6a6227d)
TomAugspurger pushed a commit that referenced this pull request May 30, 2017
* ENH: Add to_latex() method to Series (#16180)

This changeset adds _repr_latex_ to the Series class and moves
the to_latex() method from the DataFrame class to the NDFrame
class.

* Add Series to_latex test

* Move _repr_latex_ to NDFrame

Streamline things a bit by moving _repr_latex_ methods out of
the Series and DataFrame classes

* DOC: Added versionchanged

(cherry picked from commit 6a6227d)
stangirala pushed a commit to stangirala/pandas that referenced this pull request Jun 11, 2017
…6465)

* ENH: Add to_latex() method to Series (pandas-dev#16180)

This changeset adds _repr_latex_ to the Series class and moves
the to_latex() method from the DataFrame class to the NDFrame
class.

* Add Series to_latex test

* Move _repr_latex_ to NDFrame

Streamline things a bit by moving _repr_latex_ methods out of
the Series and DataFrame classes

* DOC: Added versionchanged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Add Series.to_latex() and _repr_latex_
3 participants