Skip to content

Commit

Permalink
Dropping copy=False from pd.DataFrame.infer_objects
Browse files Browse the repository at this point in the history
As explained by @gouttegd in #561 (comment), 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)
  • Loading branch information
matentzn committed Nov 9, 2024
1 parent 634b1d9 commit d2b244e
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/sssom/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d2b244e

Please sign in to comment.