ofajardo/pyreadr

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

yhm-amber opened this issue · 1 comments

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)

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