Skip to content

Commit

Permalink
Move future.no_silent_downcasting to cli.py
Browse files Browse the repository at this point in the history
The rationale is to not force this global option on all users of the library. The main point for the fix is so that sssom-py's CLI print to stdout functionality is not compromised by this output!
  • Loading branch information
matentzn committed Nov 9, 2024
1 parent e0cbe73 commit 634b1d9
Show file tree
Hide file tree
Showing 4 changed files with 1,181 additions and 1,177 deletions.
9 changes: 0 additions & 9 deletions src/sssom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import importlib.metadata

import pandas as pd

try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError:
Expand All @@ -26,10 +24,3 @@
)

from .constants import generate_mapping_set_id, get_default_metadata # noqa:401

# Context https://github.com/pandas-dev/pandas/issues/57734
try:
pd.set_option("future.no_silent_downcasting", True)
except KeyError:
# Option does not exist in this version of pandas
pass
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
9 changes: 9 additions & 0 deletions src/sssom/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,3 +1497,12 @@ def _safe_infer_objects(df):
return df.infer_objects(copy=False)
else:
return df.infer_objects()


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

0 comments on commit 634b1d9

Please sign in to comment.