Skip to content

bedrock_ge.gi.io_utils

Utility functions for reading, parsing and writing data.

Functions:

Constants:

  • DEFAULT_ENCODING

Value: 'utf-8'

Converts a Bedrock GI (geospatial) database to a dictionary of DataFrames.

Parameters:

ParameterTypeDefaultDescription
brgi_dbbedrock_ge.gi.schemas.BedrockGIDatabase | bedrock_ge.gi.schemas.BedrockGIGeospatialDatabaseThe Bedrock GI (geospatial) database.

Returns:

Type: dict[str, pandas.core.frame.DataFrame | geopandas.geodataframe.GeoDataFrame]

A dictionary where the keys are the Bedrock GI table names and the values are the DataFrames that contain the data for each table.


Converts a string to an appropriate Python data type.

Parameters:

ParameterTypeDefaultDescription
string<class 'str'>The input string to be converted.

Returns:

Type: None | bool | float | str

None if the string is ‘none’, ‘null’, or empty. bool if the string is ‘true’ or ‘false’ (case insensitive). int if the string can be converted to a float and has no decimal part. float if the string can be converted to a float with a decimal part. str if the string cannot be converted to any of the above types.


Therefore, this function converts all the data in columns with the object dtype to strings, and then back to the object dtype.

Parameters:

ParameterTypeDefaultDescription
df<class 'pandas.core.frame.DataFrame'>The DataFrame to modify.
in_place<class 'bool'>TrueWhether to modify the DataFrame in-place (default) or return a new DataFrame.

Returns:

Type: <class 'pandas.core.frame.DataFrame'>

The modified DataFrame with object dtypes converted to string dtypes.


Detect the character encoding of various input types.

Parameters:

ParameterTypeDefaultDescription
sourceUnion[str, pathlib.Path, IO[str], IO[bytes], bytes]The source to detect encoding from.

Returns:

Type: <class 'str'>

The detected encoding name (e.g., ‘utf-8’, ‘iso-8859-1’, ‘ascii’, etc.)


Convenience function to convert GeoDataFrames to DataFrames for nicer display in notebook environments like marimo.

Parameters:

ParameterTypeDefaultDescription
geodf<class 'geopandas.geodataframe.GeoDataFrame'>

Returns:

Type: <class 'pandas.core.frame.DataFrame'>


Opens or wraps a given source for reading AGS (text-based) data.

Parameters:

ParameterTypeDefaultDescription
sourceUnion[str, pathlib.Path, IO[str], IO[bytes], bytes]The source to read from.
encodingstr | NoneNoneEncoding to use for decoding bytes. Default is None.

Returns:

Type: ContextManager[io.TextIOBase]

A context manager yielding a text stream.