-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
ENH: Add to_latex() method to Series (#16180) #16465
Conversation
This changeset adds _repr_latex_ to the Series class and moves the to_latex() method from the DataFrame class to the NDFrame class.
3207a33
to
74889fc
Compare
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.
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 |
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.
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.
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.
Thanks for this suggestion--doing the check here rather than invoking to_frame()
in the Series _repr_latex method makes a lot of sense.
pandas/core/series.py
Outdated
@@ -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): |
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.
Can you actually remove this and move the _repr_latex_
from pandas/core/frame.py
and to NDFrame
in pandas/core/generic.py
?
Streamline things a bit by moving _repr_latex_ methods out of the Series and DataFrame classes
Codecov Report
@@ Coverage Diff @@
## master #16465 +/- ##
==========================================
+ Coverage 90.42% 90.42% +<.01%
==========================================
Files 161 161
Lines 51027 51032 +5
==========================================
+ Hits 46142 46147 +5
Misses 4885 4885
Continue to review full report at Codecov.
|
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
@TomAugspurger Thanks for the review! Moved things around per your suggestions and added a test explicitly for |
…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)
* 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)
…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
This changeset adds repr_latex to the Series class and moves
the to_latex() method from the DataFrame class to the NDFrame
class.
git diff upstream/master --name-only -- '*.py' | flake8 --diff