@@ -310,7 +310,13 @@ def _infer_compression(
310310
311311
312312def _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" ,
314320):
315321 """
316322 Get file handle for given path/buffer and mode.
@@ -331,6 +337,11 @@ def _get_handle(
331337 is_text : boolean, default True
332338 whether file/buffer is in text format (csv, json, etc.), or in binary
333339 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
334345
335346 Returns
336347 -------
@@ -407,10 +418,12 @@ def _get_handle(
407418 elif is_path :
408419 if encoding :
409420 # 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+ )
411424 elif is_text :
412425 # No explicit encoding
413- f = open (path_or_buf , mode , errors = "replace" , newline = "" )
426+ f = open (path_or_buf , mode , errors = encoding_errors , newline = "" )
414427 else :
415428 # Binary mode
416429 f = open (path_or_buf , mode )
0 commit comments