@@ -363,6 +363,7 @@ def _get_handle(
363363 compression : Optional [Union [str , Dict [str , Any ]]] = None ,
364364 memory_map : bool = False ,
365365 is_text : bool = True ,
366+ encoding_errors : Optional [str ] = "strict" ,
366367):
367368 """
368369 Get file handle for given path/buffer and mode.
@@ -395,6 +396,11 @@ def _get_handle(
395396 is_text : boolean, default True
396397 whether file/buffer is in text format (csv, json, etc.), or in binary
397398 mode (pickle, etc.).
399+ encoding_errors : str, default 'strict'
400+ Behavior when the input string can’t be converted according to
401+ the encoding’s rules (strict, ignore, replace, etc.)
402+ See: https://docs.python.org/3/library/codecs.html#codec-base-classes
403+ .. versionadded:: 1.0.0
398404
399405 Returns
400406 -------
@@ -472,10 +478,12 @@ def _get_handle(
472478 elif is_path :
473479 if encoding :
474480 # Encoding
475- f = open (path_or_buf , mode , encoding = encoding , newline = "" )
481+ f = open (
482+ path_or_buf , mode , errors = encoding_errors , encoding = encoding , newline = ""
483+ )
476484 elif is_text :
477485 # No explicit encoding
478- f = open (path_or_buf , mode , errors = "replace" , newline = "" )
486+ f = open (path_or_buf , mode , errors = encoding_errors , newline = "" )
479487 else :
480488 # Binary mode
481489 f = open (path_or_buf , mode )
0 commit comments