File tree 3 files changed +14
-6
lines changed
3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ Fixed regressions
16
16
~~~~~~~~~~~~~~~~~
17
17
- Fixed regression in :meth: `DataFrame.nsmallest ` led to wrong results when ``np.nan `` in the sorting column (:issue: `46589 `)
18
18
- Fixed regression in :func: `read_fwf ` raising ``ValueError `` when ``widths `` was specified with ``usecols `` (:issue: `46580 `)
19
- -
19
+ - Fixed regression is :meth: ` .Styler.to_latex ` and :meth: ` .Styler.to_html ` where `` buf `` failed in combination with `` encoding `` ( :issue: ` 47053 `)
20
20
21
21
.. ---------------------------------------------------------------------------
22
22
Original file line number Diff line number Diff line change @@ -1153,10 +1153,12 @@ def to_latex(
1153
1153
clines = clines ,
1154
1154
)
1155
1155
1156
- encoding = encoding or get_option ("styler.render.encoding" )
1157
- return save_to_buffer (
1158
- latex , buf = buf , encoding = None if buf is None else encoding
1156
+ encoding = (
1157
+ (encoding or get_option ("styler.render.encoding" ))
1158
+ if isinstance (buf , str ) # i.e. a filepath
1159
+ else encoding
1159
1160
)
1161
+ return save_to_buffer (latex , buf = buf , encoding = encoding )
1160
1162
1161
1163
@Substitution (buf = buf , encoding = encoding )
1162
1164
def to_html (
@@ -1273,15 +1275,14 @@ def to_html(
1273
1275
if caption is not None :
1274
1276
obj .set_caption (caption )
1275
1277
1276
- encoding = encoding or get_option ("styler.render.encoding" )
1277
1278
# Build HTML string..
1278
1279
html = obj ._render_html (
1279
1280
sparse_index = sparse_index ,
1280
1281
sparse_columns = sparse_columns ,
1281
1282
max_rows = max_rows ,
1282
1283
max_cols = max_columns ,
1283
1284
exclude_styles = exclude_styles ,
1284
- encoding = encoding ,
1285
+ encoding = encoding or get_option ( "styler.render.encoding" ) ,
1285
1286
doctype_html = doctype_html ,
1286
1287
** kwargs ,
1287
1288
)
Original file line number Diff line number Diff line change @@ -1557,3 +1557,10 @@ def test_no_empty_apply(mi_styler):
1557
1557
# 45313
1558
1558
mi_styler .apply (lambda s : ["a:v;" ] * 2 , subset = [False , False ])
1559
1559
mi_styler ._compute ()
1560
+
1561
+
1562
+ @pytest .mark .parametrize ("format" , ["html" , "latex" , "string" ])
1563
+ def test_output_buffer (mi_styler , format ):
1564
+ # gh 47053
1565
+ with open (f"delete_me.{ format } " , "w" ) as f :
1566
+ getattr (mi_styler , f"to_{ format } " )(f )
You can’t perform that action at this time.
0 commit comments