Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle two warnings that pollute the output of sssom-py CLI #561

Merged
merged 9 commits into from
Nov 9, 2024
4 changes: 4 additions & 0 deletions src/sssom/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
filter_redundant_rows,
invert_mappings,
merge_msdf,
pandas_set_no_silent_downcasting,
reconcile_prefix_and_data,
remove_unmatched,
sort_df_rows_columns,
Expand Down Expand Up @@ -126,6 +127,9 @@
def main(verbose: int, quiet: bool):
"""Run the SSSOM CLI."""
logger = _logging.getLogger()

pandas_set_no_silent_downcasting()

if verbose >= 2:
logger.setLevel(level=_logging.DEBUG)
elif verbose == 1:
Expand Down
4 changes: 1 addition & 3 deletions src/sssom/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,7 @@ def from_sssom_dataframe(
# Need to revisit this solution.
# This is to address: A value is trying to be set on a copy of a slice from a DataFrame
if CONFIDENCE in df.columns:
df2 = df.copy()
df2[CONFIDENCE].replace(r"^\s*$", np.nan, regex=True, inplace=True)
df = df2
df.replace({CONFIDENCE: r"^\s*$"}, np.nan, regex=True, inplace=True)

mapping_set = _get_mapping_set_from_df(df=df, meta=meta)
doc = MappingSetDocument(mapping_set=mapping_set, converter=converter)
Expand Down
16 changes: 10 additions & 6 deletions src/sssom/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,9 @@ def from_mapping_set_document(cls, doc: MappingSetDocument) -> "MappingSetDataFr
df = pd.DataFrame(get_dict_from_mapping(mapping) for mapping in doc.mapping_set.mappings)
meta = _extract_global_metadata(doc)

if pandas_version >= (2, 0, 0):
# For pandas >= 2.0.0, use the 'copy' parameter
df = df.infer_objects(copy=False)
else:
# For pandas < 2.0.0, call 'infer_objects()' without any parameters
df = df.infer_objects()
# remove columns where all values are blank.
df.replace("", np.nan, inplace=True)
df = df.infer_objects()
df.dropna(axis=1, how="all", inplace=True) # remove columns with all row = 'None'-s.

slots = _get_sssom_schema_object().dict["slots"]
Expand Down Expand Up @@ -1493,3 +1488,12 @@ def safe_compress(uri: str, converter: Converter) -> str:
:return: A CURIE
"""
return converter.compress_or_standardize(uri, strict=True)


def pandas_set_no_silent_downcasting(no_silent_downcasting=True):
"""Set pandas future.no_silent_downcasting option. Context https://github.com/pandas-dev/pandas/issues/57734."""
try:
pd.set_option("future.no_silent_downcasting", no_silent_downcasting)
except KeyError:
# Option does not exist in this version of pandas
pass
Loading