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

index of pandas dataframe is lost when writing to Rds #68

Open
julibeg opened this issue Mar 17, 2021 · 2 comments
Open

index of pandas dataframe is lost when writing to Rds #68

julibeg opened this issue Mar 17, 2021 · 2 comments
Labels
enhancement New feature or request waiting for librdata changes the issue needs some fixes to the C library librdata before it can be solved

Comments

@julibeg
Copy link

julibeg commented Mar 17, 2021

Perhaps it's a known limitation, but I didn't find it in the README.

When writing a pd.DataFrame to .Rds, the index is lost.

Example:
In Python

>>> import pandas as pd
>>> import numpy as np
>>> import pyreadr
>>> bla = pd.DataFrame(np.arange(12).reshape(4, 3), index=list('abcd'))
>>> bla
   0   1   2
a  0   1   2
b  3   4   5
c  6   7   8
d  9  10  11
>>> pyreadr.write_rds("bla.Rds", bla)

In R:

> bla = readRDS("bla.Rds")
> bla
  0  1  2
1 0  1  2
2 3  4  5
3 6  7  8
4 9 10 11

I'm on linux 64 bit with Python 3.8.6 (Anaconda), R 4.0.3, and pyreadr 0.4.0 (installed from conda).

Expected behavior:

That the rownames of the R dataframe are the index of the pandas dataframe (i.e. 'a', 'b', 'c', 'd').

@ofajardo
Copy link
Owner

Good catch!, I think the api from the C library I am using in the back currently does not allow to set the rownames when writing a dataframe.

I will therefore add it to the list of known limitations and open a ticket in the C library to ask for the implementation of this feature. We may eventually get it implemented some day =)

@julibeg
Copy link
Author

julibeg commented Mar 18, 2021

That would be nice, fingers crossed 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request waiting for librdata changes the issue needs some fixes to the C library librdata before it can be solved
Projects
None yet
Development

No branches or pull requests

2 participants