sustaingym.data.utils
#
Module Contents#
Functions#
|
Reads bytes from file pre-packaged with SustainGym. |
|
Reads text from file pre-packaged with SustainGym. |
|
Reads file pre-packaged with SustainGym into a buffered IO stream. |
|
Reads file pre-packaged with SustainGym into a buffered IO stream. |
|
Reads CSV data files pre-packaged with SustainGym. |
|
Converts a relative path to a path within the SustainGym package. |
|
|
|
Writes CSV data files to a path within the SustainGym package. |
- sustaingym.data.utils.read_bytes(path: str) bytes [source]#
Reads bytes from file pre-packaged with SustainGym.
- Parameters:
path (str) – path to file, relative to main sustaingym package
- Return type:
bytes
- sustaingym.data.utils.read_text(path: str, encoding: str = 'utf-8') str [source]#
Reads text from file pre-packaged with SustainGym.
- Parameters:
path (str) – path to file, relative to main sustaingym package
encoding (str) – any text encoding supported by Python
- Return type:
str
- sustaingym.data.utils.read_to_bytesio(path: str) io.BytesIO [source]#
Reads file pre-packaged with SustainGym into a buffered IO stream.
- Parameters:
path (str) – path to file, relative to main sustaingym package
- Return type:
io.BytesIO
- sustaingym.data.utils.read_to_stringio(path: str) io.StringIO [source]#
Reads file pre-packaged with SustainGym into a buffered IO stream.
- Parameters:
path (str) – path to file, relative to main sustaingym package
- Return type:
io.StringIO
- sustaingym.data.utils.read_csv(csv_path: str, **kwargs: Any) pandas.DataFrame [source]#
Reads CSV data files pre-packaged with SustainGym.
- Parameters:
csv_path (str) – path to CSV, relative to main sustaingym package
**kwargs (Any) – parameters to pass on to pd.read_csv()
- Return type:
pandas.DataFrame
- sustaingym.data.utils.get_save_path(path: str) str [source]#
Converts a relative path to a path within the SustainGym package.
Creates intermediate directories as needed.
This method may raise an Exception if the sustaingym package is not installed in a write-enabled directory.
- Parameters:
path (str) – path for saving file, relative to sustaingym package
- Returns:
full_path – final path
- Return type:
str
- sustaingym.data.utils.save_pickle(obj: Any, path: str) None [source]#
- Parameters:
obj (Any) – any Python object
path (str) – path for saving file, relative to sustaingym package
- Return type:
None
- sustaingym.data.utils.to_csv(df: pandas.DataFrame, path: str, **kwargs: Any) None [source]#
Writes CSV data files to a path within the SustainGym package.
This method may raise an Exception if the sustaingym package is not installed in a write-enabled directory.
- Parameters:
df (pandas.DataFrame) – DataFrame to save to disk
path (str) – path to save CSV, relative to main sustaingym package
**kwargs (Any) – parameters to pass on to
df.to_csv()
- Return type:
None