ioutils
ioutils ¶
Module for helper functions for io operations
Functions¶
find_and_read_file ¶
Tries to find a file in a list of search paths and reads it with given read function
Parameters:
-
filepath
(str
) –path to file
-
search_paths
(Optional[List[str]]
, default:None
) –list of paths to search for file
-
read_func
–function to read the file
-
file_system
(Optional[AbstractFileSystem]
, default:None
) –Allow the function to be used with different file systems; default = local
Returns:
-
Tuple[str, Any]
–Content of file
Source code in niceml/utilities/ioutils.py
list_dir ¶
Returns a list of files in a directory
Parameters:
-
path
(str
) –path to directory, which should be listed
-
return_full_path
(bool
, default:False
) –Returns full filepaths (True) or relative path (False)
-
recursive
(bool
, default:False
) –Determine if the function should look into subfolders
-
file_system
(Optional[AbstractFileSystem]
, default:None
) –Allow the function to be used with different file systems; default = local
-
filter_ext
(Optional[List[str]]
, default:None
) –List of file extension to filter for; default = all files
Returns:
-
List[str]
–A list of files in the specified directory
Source code in niceml/utilities/ioutils.py
read_csv ¶
Reads csv with optional AbstractFileSystem given
Parameters:
-
filepath
(str
) –path to csv file
-
file_system
(Optional[AbstractFileSystem]
, default:None
) –Allow the function to be used with different file systems; default = local
-
***kwargs
–additional arguments for pd.read_csv function
Returns:
-
DataFrame
–dataframe from csv file
Source code in niceml/utilities/ioutils.py
read_image ¶
Reads image with optional AbstractFileSystem given
Parameters:
-
filepath
(str
) –Path to load the image from
-
file_system
(Optional[AbstractFileSystem]
, default:None
) –Allow the function to be used with different file systems; default = local
-
**kwargs
–additional arguments for Image.open function
Returns:
-
Image
–loaded image object
Source code in niceml/utilities/ioutils.py
read_json ¶
Reads a json file with optional AbstractFileSystem given
Parameters:
-
filepath
(str
) –path to json file
-
file_system
(Optional[AbstractFileSystem]
, default:None
) –Allow the function to be used with different file systems; default = local
Returns:
-
dict
–Content of json as dictionary
Source code in niceml/utilities/ioutils.py
read_parquet ¶
Reads parquet with optional AbstractFileSystem given
Parameters:
-
filepath
(str
) –path to parquet file
-
file_system
(Optional[AbstractFileSystem]
, default:None
) –Allow the function to be used with different file systems; default = local
Returns:
-
DataFrame
–dataframe from parquet file
Source code in niceml/utilities/ioutils.py
read_yaml ¶
Reads a yaml file with optional AbstractFileSystem given
Parameters:
-
filepath
(str
) –path to yaml file
-
file_system
(Optional[AbstractFileSystem]
, default:None
) –Allow the function to be used with different file systems; default = local
Returns:
-
dict
–Content of yaml as dictionary
Source code in niceml/utilities/ioutils.py
write_csv ¶
Writes dataframe to csv file with optional AbstractFileSystem given
Parameters:
-
data
(DataFrame
) –Dataframe to write to csv file
-
filepath
(str
) –Path to save the csv file to
-
file_system
(Optional[AbstractFileSystem]
, default:None
) –Allow the function to be used with different file systems; default = local
-
**kwargs
–additional arguments for data.to_csv function
Source code in niceml/utilities/ioutils.py
write_image ¶
Saves image to filepath with optional AbstractFileSystem given
Parameters:
-
image
(Image
) –Image object
-
filepath
(str
) –Path to save the image to
-
file_system
(Optional[AbstractFileSystem]
, default:None
) –Allow the function to be used with different file systems; default = local
-
**kwargs
–additional arguments for Image.save function
Source code in niceml/utilities/ioutils.py
write_json ¶
Writes dictionary to json with optional AbstractFileSystem given
Parameters:
-
data
(dict
) –dictionary to be saved as json
-
filepath
(str
) –path to save the json file to
-
file_system
(Optional[AbstractFileSystem]
, default:None
) –Allow the function to be used with different file systems; default = local
-
**kwargs
–additional arguments for json.dump function
Source code in niceml/utilities/ioutils.py
write_parquet ¶
Writes dataframe to parquet file with optional AbstractFileSystem given
Parameters:
-
dataframe
(DataFrame
) –Dataframe to write to parquet file
-
filepath
(str
) –Path to save the parquet file to
-
compression
(Optional[str]
, default:'gzip'
) –Compression method
-
file_system
(Optional[AbstractFileSystem]
, default:None
) –Allow the function to be used with different file systems; default = local
-
**kwargs
–additional arguments for fastparquet.write function
Source code in niceml/utilities/ioutils.py
write_yaml ¶
Writes dictionary to yaml with optional AbstractFileSystem given
Parameters:
-
data
(dict
) –dictionary to be saved as yaml
-
filepath
(str
) –path to save the yaml file to
-
file_system
(Optional[AbstractFileSystem]
, default:None
) –Allow the function to be used with different file systems; default = local
-
**kwargs
–additional arguments for yaml.dump function