From d2b244e309e39d5199ba686f56df386db9775209 Mon Sep 17 00:00:00 2001 From: Nico Matentzoglu Date: Sat, 9 Nov 2024 16:45:17 +0200 Subject: [PATCH] Dropping copy=False from pd.DataFrame.infer_objects As explained by @gouttegd in https://github.com/mapping-commons/sssom-py/pull/561#discussion_r1835405243, we do not actually benefit from the small performance gain enabled by copy=False here, so we decided to drop it (which means a considerable simplification of the code as well) --- src/sssom/util.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/sssom/util.py b/src/sssom/util.py index dbe734a3..6684f9a1 100644 --- a/src/sssom/util.py +++ b/src/sssom/util.py @@ -160,7 +160,7 @@ def from_mapping_set_document(cls, doc: MappingSetDocument) -> "MappingSetDataFr # remove columns where all values are blank. df.replace("", np.nan, inplace=True) - df = _safe_infer_objects(df) + 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"] @@ -1490,15 +1490,6 @@ def safe_compress(uri: str, converter: Converter) -> str: return converter.compress_or_standardize(uri, strict=True) -def _safe_infer_objects(df): - """Infer object types in a DataFrame, compatible with multiple pandas versions.""" - _pandas_version = tuple(map(int, pd.__version__.split(".")[:2])) - if _pandas_version >= (2, 0): - 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: