I sometimes apply numpy.finfo
to a Pandas or a NumPy dtype
– to determine the maximum support value (max
) or the minimum meaningful increment (eps
), say. Is there an equivalent for Polars dtype
s? Or an easy way to convert a Polars dtype
to a NumPy one (without casting the whole array)?
You can use min()
and max()
on the polars type. On my machine, running the following script:
import polars as pl
print("Unsigned integers")
for t in [pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64]:
print(t.__name__, t.min(), t.max())
print("nSigned integers")
for t in [pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64]:
print(t.__name__, t.min(), t.max())
print("nFloats")
for t in [pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64]:
print(t.__name__, t.min(), t.max())
produces the following output:
Unsigned integers
UInt8 0 255
UInt16 0 65535
UInt32 0 4294967295
UInt64 0 18446744073709551615
Signed integers
UInt8 0 255
UInt16 0 65535
UInt32 0 4294967295
UInt64 0 18446744073709551615
Floats
UInt8 0 255
UInt16 0 65535
UInt32 0 4294967295
UInt64 0 18446744073709551615