Skip to content

Commit e57acc2

Browse files
author
Rebecca Sweger
committed
Move _repr_latex_ to NDFrame
Streamline things a bit by moving _repr_latex_ methods out of the Series and DataFrame classes
1 parent d8d2b62 commit e57acc2

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

pandas/core/frame.py

-10
Original file line numberDiff line numberDiff line change
@@ -634,16 +634,6 @@ def _repr_html_(self):
634634
else:
635635
return None
636636

637-
def _repr_latex_(self):
638-
"""
639-
Returns a LaTeX representation for a particular Dataframe.
640-
Mainly for use with nbconvert (jupyter notebook conversion to pdf).
641-
"""
642-
if get_option('display.latex.repr'):
643-
return self.to_latex()
644-
else:
645-
return None
646-
647637
@property
648638
def style(self):
649639
"""

pandas/core/generic.py

+12
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,16 @@ def __setstate__(self, state):
10501050
# ----------------------------------------------------------------------
10511051
# IO
10521052

1053+
def _repr_latex_(self):
1054+
"""
1055+
Returns a LaTeX representation for a particular object.
1056+
Mainly for use with nbconvert (jupyter notebook conversion to pdf).
1057+
"""
1058+
if config.get_option('display.latex.repr'):
1059+
return self.to_latex()
1060+
else:
1061+
return None
1062+
10531063
# ----------------------------------------------------------------------
10541064
# I/O Methods
10551065

@@ -1562,6 +1572,8 @@ def to_latex(self, buf=None, columns=None, col_space=None, header=True,
15621572
encoding=None, decimal='.', multicolumn=None,
15631573
multicolumn_format=None, multirow=None):
15641574
# Get defaults from the pandas config
1575+
if self.ndim == 1:
1576+
self = self.to_frame()
15651577
if longtable is None:
15661578
longtable = config.get_option("display.latex.longtable")
15671579
if escape is None:

pandas/core/series.py

-10
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,6 @@ def get_values(self):
391391
""" same as values (but handles sparseness conversions); is a view """
392392
return self._data.get_values()
393393

394-
def _repr_latex_(self):
395-
"""
396-
Returns a LaTeX representation for a particular Series.
397-
Mainly for use with nbconvert (jupyter notebook conversion to pdf).
398-
"""
399-
if get_option('display.latex.repr'):
400-
return self.to_frame().to_latex()
401-
else:
402-
return None
403-
404394
@property
405395
def asobject(self):
406396
"""

0 commit comments

Comments
 (0)