Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexing DataFrame with DateOffset is nearly impossible #20948

Open
JoergVanAken opened this issue May 4, 2018 · 3 comments
Open

Indexing DataFrame with DateOffset is nearly impossible #20948

JoergVanAken opened this issue May 4, 2018 · 3 comments
Labels
Bug Frequency DateOffsets Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@JoergVanAken
Copy link

Code Sample, a copy-pastable example if possible

offsets = pd.Series(data=[-15, -10, -5, 0, 5, 10, 15], dtype=float).map(pd.DateOffset)
df = pd.DataFrame(index=[0, 1], columns=offsets)

df.loc[0, offsets[0]]          # raises an error
df.at[0, offsets[0]]           # this works
df.at[0, offsets[0]] = 1       # raises an error
df.set_value(0, offsets[0], 1) # this works but raises a FutureWarning

Problem description

It is very difficult to access cells of a DataFrame if the columns are of type DateOffset.

Expected Output

Accessing a cell via df.loc[0, offsets[0]] should be possible for read and write.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.2.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.22.0
pytest: 3.2.1
pip: 9.0.1
setuptools: 36.4.0
Cython: 0.26
numpy: 1.13.1
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 6.1.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented May 4, 2018

what are you trying to do? this is a very odd thing to actually try to index by

@JoergVanAken
Copy link
Author

The above code is only a demonstration. In fact I have a couple of timeseries which I want to compare for example by correlation. Sometimes these series match better after introducing a time lag. The dataframe is used to store the results.

Of course it is more a kind of "sugar" and not really necessary.

First of all, I was just surprised that the code did not work as expected and it took me while to see that it was not my fault.

@chris-b1
Copy link
Contributor

chris-b1 commented May 4, 2018

xref to #19211, probably some others.

Right now offsets aren't a first-class data type in pandas, they 'work' by being treated as generic python objects. Seems to be some kind of over-aggressive type inference here, you're welcome to take a look.

@gfyoung gfyoung added the Indexing Related to indexing on series/frames, not to indexes themselves label May 8, 2018
@mroeschke mroeschke added Bug Frequency DateOffsets labels Jun 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

5 participants