Skip to content

Polars dfs is 0-based indexed if no conversion to data.frame explicitly #1703

Open
@ivan-balashov

Description

@ivan-balashov

Hi! I've found that while Polars dataframes can be used, the indices cannot be properly used without explicit conversion to a data frame (still 0-based indexing instead of the 1-based indexing used in Pandas conversion). I think there should be some kind of warning about this at least.

Test pandas and polars dfs

import pandas as pd
import polars as pl

data = {'aa':[1,2,3,4,5,6,7,8,9,10,11,12]}

pl_df  = pl.DataFrame(data)
pd_df  = pd.DataFrame(data)
library(reticulate)
head(py$pd_df)
  aa
1  1
2  2
3  3
4  4
5  5
6  6
head(as.data.frame(py$pd_df))
  aa
1  1
2  2
3  3
4  4
5  5
6  6
head(py$pl_df)
shape: (6, 1)
┌─────┐
│ aa  │
│ --- │
│ i64 │
╞═════╡
│ 2   │
│ 3   │
│ 4   │
│ 5   │
│ 6   │
│ 7   │
└─────┘
head(as.data.frame(py$pl_df))
  aa
1  1
2  2
3  3
4  4
5  5
6  6
utils::sessionInfo() 
R version 4.4.2 (2024-10-31)
Platform: x86_64-apple-darwin20
Running under: macOS Ventura 13.5.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] ru_RU.UTF-8/ru_RU.UTF-8/ru_RU.UTF-8/C/ru_RU.UTF-8/ru_RU.UTF-8

time zone: 
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] reticulate_1.40.0

loaded via a namespace (and not attached):
 [1] digest_0.6.37     fastmap_1.2.0     xfun_0.49         Matrix_1.7-1     
 [5] lattice_0.22-6    knitr_1.49        htmltools_0.5.8.1 png_0.1-8        
 [9] rmarkdown_2.29    cli_3.6.3         grid_4.4.2        renv_1.0.11      
[13] compiler_4.4.2    tools_4.4.2       evaluate_1.0.1    Rcpp_1.0.13-1    
[17] yaml_2.3.10       rlang_1.1.4       jsonlite_1.8.9   
reticulate::py_config()
python:        my_folder/.venv/bin/python
libpython:      /Users/ivanbalashov/.local/share/uv/python/cpython-3.12.7-macos-x86_64-none/lib/libpython3.12.dylib
pythonhome:     my_folder/.venv
virtualenv:     my_folder/.venv/bin/activate_this.py
version:        3.12.7 (main, Oct 16 2024, 09:10:10) [Clang 18.1.8 ]
numpy:         my_folder/.venv/lib/python3.12/site-packages/numpy
numpy_version:  2.2.0

NOTE: Python version was forced by VIRTUAL_ENV

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions