@@ -310,7 +310,13 @@ def _infer_compression(
310
310
311
311
312
312
def _get_handle (
313
- path_or_buf , mode , encoding = None , compression = None , memory_map = False , is_text = True
313
+ path_or_buf ,
314
+ mode ,
315
+ encoding = None ,
316
+ compression = None ,
317
+ memory_map = False ,
318
+ is_text = True ,
319
+ encoding_errors = "strict" ,
314
320
):
315
321
"""
316
322
Get file handle for given path/buffer and mode.
@@ -331,6 +337,11 @@ def _get_handle(
331
337
is_text : boolean, default True
332
338
whether file/buffer is in text format (csv, json, etc.), or in binary
333
339
mode (pickle, etc.)
340
+ encoding_errors : str, default 'strict'
341
+ Behavior when the input string can’t be converted according to
342
+ the encoding’s rules (strict, ignore, replace, etc.)
343
+ See: https://docs.python.org/3/library/codecs.html#codec-base-classes
344
+ .. versionadded:: 1.0.0
334
345
335
346
Returns
336
347
-------
@@ -407,10 +418,12 @@ def _get_handle(
407
418
elif is_path :
408
419
if encoding :
409
420
# Encoding
410
- f = open (path_or_buf , mode , encoding = encoding , newline = "" )
421
+ f = open (
422
+ path_or_buf , mode , errors = encoding_errors , encoding = encoding , newline = ""
423
+ )
411
424
elif is_text :
412
425
# No explicit encoding
413
- f = open (path_or_buf , mode , errors = "replace" , newline = "" )
426
+ f = open (path_or_buf , mode , errors = encoding_errors , newline = "" )
414
427
else :
415
428
# Binary mode
416
429
f = open (path_or_buf , mode )
0 commit comments