parameters: (
      filepath_or_buffer: FilePathOrBuffer, compression: Optional[str]
  )
docstring: Get the compression method for filepath_or_buffer. If compression='infer',
      the inferred compression method is returned. Otherwise, the input
      compression method is returned unchanged, unless it's invalid, in which
      case an error is raised.
  
      Parameters
      ----------
      filepath_or_buffer : str or file handle
          File path or object.
      compression : {'infer', 'gzip', 'bz2', 'zip', 'xz', None}
          If 'infer' and `filepath_or_buffer` is path-like, then detect
          compression from the following extensions: '.gz', '.bz2', '.zip',
          or '.xz' (otherwise no compression).
  
      Returns
      -------
      string or None
  
      Raises
      ------
      ValueError on invalid compression specified.
docstring_summary: Get the compression method for filepath_or_buffer. If compression='infer',
      the inferred compression method is returned. Otherwise, the input
      compression method is returned unchanged, unless it's invalid, in which
      case an error is raised.
docstring_tokens: Get the compression method for filepath_or_buffer . If compression = infer the inferred compression method is returned . Otherwise the input compression method is returned unchanged unless it s invalid in which case an error is raised .
function: def infer_compression(
      filepath_or_buffer: FilePathOrBuffer, compression: Optional[str]
  ) -> Optional[str]:
      """
      Get the compression method for filepath_or_buffer. If compression='infer',
      the inferred compression method is returned. Otherwise, the input
      compression method is returned unchanged, unless it's invalid, in which
      case an error is raised.
  
      Parameters
      ----------
      filepath_or_buffer : str or file handle
          File path or object.
      compression : {'infer', 'gzip', 'bz2', 'zip', 'xz', None}
          If 'infer' and `filepath_or_buffer` is path-like, then detect
          compression from the following extensions: '.gz', '.bz2', '.zip',
          or '.xz' (otherwise no compression).
  
      Returns
      -------
      string or None
  
      Raises
      ------
      ValueError on invalid compression specified.
      """
  
      # No compression has been explicitly specified
      if compression is None:
          return None
  
      # Infer compression
      if compression == "infer":
          # Convert all path types (e.g. pathlib.Path) to strings
          filepath_or_buffer = stringify_path(filepath_or_buffer)
          if not isinstance(filepath_or_buffer, str):
              # Cannot infer compression of a buffer, assume no compression
              return None
  
          # Infer compression from the filename/URL extension
          for compression, extension in _compression_to_extension.items():
              if filepath_or_buffer.endswith(extension):
                  return compression
          return None
  
      # Compression has been specified. Check that it's valid
      if compression in _compression_to_extension:
          return compression
  
      msg = f"Unrecognized compression type: {compression}"
      valid = ["infer", None] + sorted(_compression_to_extension)
      msg += f"\nValid compression types are {valid}"
      raise ValueError(msg)
function_tokens: def infer_compression ( filepath_or_buffer : FilePathOrBuffer , compression : Optional [ str ] ) -> Optional [ str ] : # No compression has been explicitly specified if compression is None : return None # Infer compression if compression == "infer" : # Convert all path types (e.g. pathlib.Path) to strings filepath_or_buffer = stringify_path ( filepath_or_buffer ) if not isinstance ( filepath_or_buffer , str ) : # Cannot infer compression of a buffer, assume no compression return None # Infer compression from the filename/URL extension for compression , extension in _compression_to_extension . items ( ) : if filepath_or_buffer . endswith ( extension ) : return compression return None # Compression has been specified. Check that it's valid if compression in _compression_to_extension : return compression msg = f"Unrecognized compression type: {compression}" valid = [ "infer" , None ] + sorted ( _compression_to_extension ) msg += f"\nValid compression types are {valid}" raise ValueError ( msg )