0

I tried pl.col('foo').cast(np.uint32) and I got a NotImplementedError.

I ask because col.str.lengths() returns a column of type UInt32 and columns need to be the same type for joins.

1 Answers1

3

Polars is not numpy, so you need a polars dtype when casting.

>>> s = pl.Series("a", [-1, 0, 1, 2, 3])
>>> s
shape: (5,)
Series: 'a' [i64]
[
    -1
    0
    1
    2
    3
]
>>> s.cast(pl.UInt32, strict=False)
shape: (5,)
Series: 'a' [u32]
[
    null
    0
    1
    2
    3
]

The default casting behaviour is strict. This would raise an error in this case, because we cannot cast negative integers to unsigned integers.

ritchie46
  • 10,405
  • 1
  • 24
  • 43