Skip to content

Support for additional binary operations and/or in polars expressions #15242

@MMesch

Description

@MMesch

Related problem

Unless I have overlooked something (in which case additional documentation may be nice), there currently is no way to combine polars binary expressions with logical_and and logical_or. A workaround is using masks and combining filters but that seems overly complex. There is already a command for expr-not https://github.com/nushell/nushell/blob/main/crates/nu_plugin_polars/src/dataframe/command/boolean/expr_not.rs on the other hand.

Describe the solution you'd like

I propose wrapping logical_and and logical_or in the same way as expr-not but before doing so wanted to get feedback and thoughts on how polars expressions are handled in nushell polars. For example,

➜ [[a, b]; [1., 2.], [4., 6.]] | polars into-df | polars filter ((polars col a) > 1)

works but

➜ [[a, b]; [1., 2.], [4., 6.]] | polars into-df | polars filter (((polars col a) > 1) and ((polars col b) > 1))
Error: nu::shell::type_mismatch

  × Type mismatch.
   ╭─[entry #100:1:65]
 1 │ [[a, b]; [1., 2.], [4., 6.]] | polars into-df | polars filter (((polars col a) > 1) and ((polars col b) > 1))
   ·                                                                 ─────────┬────────
   ·                                                                          ╰── expected bool
   ╰────

doesn't work. It may be nicer to somehow get and and or to overload similar to > but thus far I'm unsure how to do that and I didn't dig too deep until now. But why not not as well in that case? Opinions?

Describe alternatives you've considered

The other option is to simply wrap the polars functions logical_and, logical_or etc to do this and apply them via the nushell pipe symbol.

Additional context and details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:plugin-polarsWork related to the polars dataframe implementationcategory:enhancementNew feature or requeststatus:needs-triageAn issue that hasn't had any proper look

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions