Skip to content

FutureWarning from Pandas in opencadd/databases/klifs/core.py #165

Description

@craldaz

I'm using your library to interact with the KLIFS database and have noticed a FutureWarning from Pandas. The warning is triggered by the us of inplace=True on a chained assignment, which will be deprecated in Pandas 3.0.

This doesn't break functionality right now, but I wanted to bring it to your attention so the code can be updated for future compatibility.

Here is the warning I'm seeing:

/path/to/venv/lib/python3.10/site-packages/opencadd/
     databases/klifs/core.py:143: FutureWarning: A value is
     trying to be set on a copy of a DataFrame or Series through
     chained assignment using an inplace method.
   The behavior will change in pandas 3.0. This inplace method
     will never work because the intermediate object on which we
     are setting values always behaves as a copy.
  
For example, when doing 'df[col].method(value, 
     inplace=True)', try using 'df.method({col: value}, 
     inplace=True)' or df[col] = df[col].method(value) instead,
     to perform the operation inplace on the original object.
 dataframe["structure.alternate_model"].replace("", "-",
     inplace=True)

Location
The warning points to several lines in opencadd/databases/klifs/core.py, including lines 143 and 145.

Environment

  • opencadd version:1.0.1+88.g57eafc2 (installed from github)
  • pandas version: 2.3.2
  • Python version: 3.10

The warning message itself suggests the fix, which is to avoid chained assignment with inplace=True.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions