Skip to content

Commit 6ce01a8

Browse files
authored
Handle two warnings that pollute the output of sssom-py CLI (#561)
See commits for a more detailed description of the changes; This PR should not introduce any functional changes.
1 parent 4cad7d6 commit 6ce01a8

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/sssom/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
filter_redundant_rows,
5555
invert_mappings,
5656
merge_msdf,
57+
pandas_set_no_silent_downcasting,
5758
reconcile_prefix_and_data,
5859
remove_unmatched,
5960
sort_df_rows_columns,
@@ -126,6 +127,9 @@
126127
def main(verbose: int, quiet: bool):
127128
"""Run the SSSOM CLI."""
128129
logger = _logging.getLogger()
130+
131+
pandas_set_no_silent_downcasting()
132+
129133
if verbose >= 2:
130134
logger.setLevel(level=_logging.DEBUG)
131135
elif verbose == 1:

src/sssom/parsers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,7 @@ def from_sssom_dataframe(
424424
# Need to revisit this solution.
425425
# This is to address: A value is trying to be set on a copy of a slice from a DataFrame
426426
if CONFIDENCE in df.columns:
427-
df2 = df.copy()
428-
df2[CONFIDENCE].replace(r"^\s*$", np.nan, regex=True, inplace=True)
429-
df = df2
427+
df.replace({CONFIDENCE: r"^\s*$"}, np.nan, regex=True, inplace=True)
430428

431429
mapping_set = _get_mapping_set_from_df(df=df, meta=meta)
432430
doc = MappingSetDocument(mapping_set=mapping_set, converter=converter)

src/sssom/util.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,9 @@ def from_mapping_set_document(cls, doc: MappingSetDocument) -> "MappingSetDataFr
158158
df = pd.DataFrame(get_dict_from_mapping(mapping) for mapping in doc.mapping_set.mappings)
159159
meta = _extract_global_metadata(doc)
160160

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

171166
slots = _get_sssom_schema_object().dict["slots"]
@@ -1493,3 +1488,12 @@ def safe_compress(uri: str, converter: Converter) -> str:
14931488
:return: A CURIE
14941489
"""
14951490
return converter.compress_or_standardize(uri, strict=True)
1491+
1492+
1493+
def pandas_set_no_silent_downcasting(no_silent_downcasting=True):
1494+
"""Set pandas future.no_silent_downcasting option. Context https://github.com/pandas-dev/pandas/issues/57734."""
1495+
try:
1496+
pd.set_option("future.no_silent_downcasting", no_silent_downcasting)
1497+
except KeyError:
1498+
# Option does not exist in this version of pandas
1499+
pass

0 commit comments

Comments
 (0)