-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complex number support #3564
Comments
Complex numbers are not supported yet by the arrow specification as far as I know: There is an unmerged PR, for complex number support in Arrow: If complex numbers are not in the arrow spec, it is unlikely that it will appear in arrow2 (which is used by polars). |
Ok, thanks. |
You can model the complex number as a StructType, with real and imaginary component. But then you may have to implement custom arithmetic for this type. What do you think? |
For polars to be adopted by the scientific and engineering communities, complex number support is really crucial. Personally, I work around this (in py-polars) by representing complex numbers as a Struct, as @potter420 suggest, and implementing the arithmetic by unnesting the struct and operating on the real and imaginary parts (fields). This makes code distribution much trickier. Would it be an option to implement a data type in Polars that is based on Struct, but with the operators (addition, multiplication, division) defined at the Rust level? No need to wait for Arrow to possibly include complex number specifications. |
@monochromatti I'm not sure if I understand you correctly, but you can do this: pl.select(
pl.struct(x=2, y=3) * pl.struct(x=1.5, y=5)
)
# shape: (1, 1)
# ┌───────────┐
# │ x │
# │ --- │
# │ struct[2] │
# ╞═══════════╡
# │ {3.0,15} │
# └───────────┘ |
@cmdlineluser Unfortunately the arithmetic for complex numbers is different than what Polars assumes when multiplying Structs. For example, the product of two complex numbers is Or in tuple notation
The product of Structs is
An example use: |
I've seen list datatypes and complex numbers are not included.
I know, rust doesn't have support for complex numbers natively,
but num does (which is included in dependence list of polars, version 0.4.0).
I can help for pr although I'm not an expert of rust (I use polars with it's python bind).
The text was updated successfully, but these errors were encountered: