File tree 2 files changed +8
-4
lines changed
2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change 3
3
and latex files. This module also applies to display formatting.
4
4
"""
5
5
6
- import codecs
7
6
from contextlib import contextmanager
8
7
from datetime import tzinfo
9
8
import decimal
@@ -495,7 +494,11 @@ def get_buffer(
495
494
if hasattr (buf , "write" ):
496
495
yield buf
497
496
elif isinstance (buf , str ):
498
- with codecs .open (buf , "w" , encoding = encoding ) as f :
497
+ with open (buf , "w" , encoding = encoding , newline = "" ) as f :
498
+ # GH#30034 open instead of codecs.open prevents a file leak
499
+ # if we have an invalid encoding argument.
500
+ # newline="" is needed to roundtrip correctly on
501
+ # windows test_to_latex_filename
499
502
yield f
500
503
else :
501
504
raise TypeError ("buf is not a file name and it has no write method" )
Original file line number Diff line number Diff line change @@ -3259,8 +3259,9 @@ def test_filepath_or_buffer_arg(
3259
3259
):
3260
3260
getattr (df , method )(buf = filepath_or_buffer , encoding = encoding )
3261
3261
elif encoding == "foo" :
3262
- with pytest .raises (LookupError , match = "unknown encoding" ):
3263
- getattr (df , method )(buf = filepath_or_buffer , encoding = encoding )
3262
+ with tm .assert_produces_warning (None ):
3263
+ with pytest .raises (LookupError , match = "unknown encoding" ):
3264
+ getattr (df , method )(buf = filepath_or_buffer , encoding = encoding )
3264
3265
else :
3265
3266
expected = getattr (df , method )()
3266
3267
getattr (df , method )(buf = filepath_or_buffer , encoding = encoding )
You can’t perform that action at this time.
0 commit comments