Skip to content

[R] Error: Cannot convert Dictionary Array of type dictionary<values=large_string, indices=uint32, ordered=0> to R #39603

Closed

Description

@lgautier

Describe the bug, including details regarding any error messages, version, and platform.

ChunkedArray objects of type "DictionnaryType" have the method as_vector (as do ChunkedArray objects of other types) but calling that method ends with an error.

I am using the R package polars to create a problematic ChunkedArray. This is how I discovered the issue and I did not find how to create a similar ChunkedArray using the R package arrow alone:

> require("arrow"); require("polars")
> pl_df <- polars::as_polars_df(data.frame(foo = factor(c("x", "y", "x"))))
> ar_df <- arrow::as_arrow_table(pl_df)
> ar_df$foo
ChunkedArray
<dictionary<values=large_string, indices=uint32>>
[

  -- dictionary:
    [
      "x",
      "y"
    ]
  -- indices:
    [
      0,
      1,
      0
    ]
]
> ar_df$foo$as_vector()
Error: Cannot convert Dictionary Array of type `dictionary<values=large_string, indices=uint32, ordered=0>` to R

arrow version: 12.0.0.9000
R version: 4.2.3

Component(s)

R

Activity

  1. lgautier commented on Jan 14, 2024

    @lgautier
    Author

    I found this in the documentation, where the conversion of a ChunkedArray of type dictionnary to an R vector is working: https://arrow.apache.org/docs/r/articles/data_types.html

    The issue seems to be when values is of type large_string.

  2. changed the title [-]Error: Cannot convert Dictionary Array of type `dictionary<values=large_string, indices=uint32, ordered=0>` to R[/-] [+][R] Error: Cannot convert Dictionary Array of type `dictionary<values=large_string, indices=uint32, ordered=0>` to R[/+] on Jan 15, 2024
  3. amoeba commented on Jan 18, 2024

    @amoeba
    Member

    Hi @lgautier, thanks for the report. It looks like the issue is that the conversion routine this uses doesn't support uint32 indices:

    switch (indices_type.id()) {
    case Type::UINT8:
    case Type::INT8:
    case Type::UINT16:
    case Type::INT16:
    case Type::INT32:
    // TODO: also add int64, uint32, uint64 downcasts, if possible
    break;
    default:
    cpp11::stop("Cannot convert Dictionary Array of type `%s` to R",
    dict_type.ToString().c_str());

    As a workaround until this feature is added, you should be able to cast() to a similar type but with int32 indices so long as your indices can be contained within an int32:

    ar_df$foo$cast(dictionary(index_type = int32(), value_type = large_utf8()))$as_vector()

    The pure arrow reproducer for this is,

    Array$create(factor(c("x", "y", "z")))$cast(dictionary(index_type = uint32(), value_type = large_utf8()))
  4. nick-ulle commented on Jul 22, 2025

    @nick-ulle

    This bug or one with the same error message also seems to prevent R Arrow from reading Parquet files with Categorical or Enum columns created in Python Polars.

    Reprex tested with Python Polars 1.31.0 and R Arrow 20.0.0.2:

    # In Python:
    import polars as pl
    
    data = pl.DataFrame({"x": ["a", "b"]}, schema={"x": pl.Categorical})
    data.write_parquet("test.parquet")
    # In R:
    library("arrow")
    read_parquet("test.parquet")

    Error message:

    Error: Cannot convert Dictionary Array of type `dictionary<values=string, indices=uint32, ordered=0>` to R
    
  5. added a commit that references this issue on Jun 10, 2026
  6. added this to the 25.0.0 milestone on Jun 10, 2026
  7. thisisnic commented on Jun 10, 2026

    @thisisnic
    Member

    Issue resolved by pull request 49710
    #49710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions