Skip to content

BUG: pd.frequency.get_offset cache may be overwritten #11192

Closed
@sinhrks

Description

@sinhrks

Because frequencies.get_offset may be broken by user operation because of its cache.

https://github.com/pydata/pandas/blob/master/pandas/tseries/frequencies.py#L515

import pandas as pd
x = pd.tseries.frequencies.get_offset('D')
x.__dict__
# {'normalize': False, 'kwds': {}, 'n': 1, '_offset': datetime.timedelta(1), '_named': 'D', '_use_relativedelta': False}

# modify its property
x.n = 5

# NG, modified instance is returned
y = pd.tseries.frequencies.get_offset('D')
y.__dict__
# {'normalize': False, 'kwds': {}, 'n': 5, '_offset': datetime.timedelta(1), '_named': 'D', '_use_relativedelta': False}

It should return a copy of the cache.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions