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

Didn't found any option which allow me to tell the write_rds function "don't save rownames" #102

Closed
yhm-amber opened this issue Jun 19, 2024 · 1 comment

Comments

@yhm-amber
Copy link

yhm-amber commented Jun 19, 2024

I saw this at README:

Writing rownames is currently not supported.

But this is what I meet:

>>> import pyreadr as readr
>>> readr.read_r("df0.rds")[None]
   A  B
0  1  4
1  2  3
2  3  2
>>> readr.write_rds("df0x.rds",readr.read_r("df0.rds")[None])
>>> readr.read_r("df0x.rds")[None]
          A  B
rownames      
1         1  4
2         2  3
3         3  2
>>> 

Looks some thing more be saved at the calling of readr.write_rds forcely ?

And, I didn't find any option like save_rownames at this function's help doc also ...

File example

You can make the first rds file by this in R:

data.frame(A = 1:3, B = 4:2) |> saveRDS("df0.rds")

Expected behavior

The behavior of write_rds should just like saveRDS in R ... If the object have row names then save it, if don't, then don't save it ... Well, that's just my suggestion, I don't know did that possible on python.

Setup Information

  • How did you install pyreadr? (pip)
  • Platform (linux 64 bit)
  • Python Version (3.10)
  • Python Distribution (plain python)
  • Using Virtualenv or condaenv? (yes)
@ofajardo
Copy link
Owner

ofajardo commented Jul 2, 2024

Thanks for the report. Regarding not being able to save your pandas index into R rownames, the issue has been already reported here. Basically pyreadr is a wrapper around the C library librdata, and since the funcitonality is not supported by the C library it cannot be fixed for now, until they fix it first in the C library.

Regarding the R dataframe having rownames by default, it seems that is the behavior in R itself if you do not define the rownames explicitly (see screenshot), therefore nothing to be fixed there I think.

image

@ofajardo ofajardo closed this as completed Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants