Skip to content

bug: unexpected in-place modification of dataframe index inside class method #3263

@AzulGarza

Description

@AzulGarza

hey! just a heads up, these lines:

if timestamp is not None:
logger.info(f"Indexing data by '{timestamp}'.")
dataframe.index = pd.to_datetime(dataframe[timestamp])

are modifying the dataframe in-place by setting its index. since this happens inside a class method, it might be unexpected for whoever passed the dataframe, especially if they rely on its original structure later. in my case, i iterate over the same dataframe later on, but after calling the method (second print), the index has been altered, which breaks assumptions about its structure.

Image

to avoid side effects, we probably want to work on a copy instead (or at least document that this changes the input). otherwise, it can silently break downstream code.

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