Skip to content

adds And and Or operators to polars plugin nu_expressions#15248

Merged
ayax79 merged 2 commits intonushell:mainfrom
MMesch:mmesch/polars-add-And-and-Xor
Mar 5, 2025
Merged

adds And and Or operators to polars plugin nu_expressions#15248
ayax79 merged 2 commits intonushell:mainfrom
MMesch:mmesch/polars-add-And-and-Xor

Conversation

@MMesch
Copy link
Copy Markdown
Contributor

@MMesch MMesch commented Mar 5, 2025

solution for #15242

adds "And"

~/Projects/nushell> [[a, b]; [1., 2.], [3.,3.], [4., 6.]] | polars into-df | polars filter (((polars col a) > 2) and ((polars col b) < 5))
╭───┬──────┬──────╮
│ # │  a   │  b   │
├───┼──────┼──────┤
│ 0 │ 3.00 │ 3.00 │
╰───┴──────┴──────╯

adds "Or"

~/Projects/nushell> [[a, b]; [1., 2.], [3.,3.], [4., 6.]] | polars into-df | polars filter (((polars col a) > 7) or ((polars col b) > 5))
╭───┬──────┬──────╮
│ # │  a   │  b   │
├───┼──────┼──────┤
│ 0 │ 4.00 │ 6.00 │
╰───┴──────┴──────╯

but not (yet) xor because polars doesn't have a direct expression for logical_xor

~/Projects/nushell> [[a, b]; [1., 2.], [3.,3.], [4., 6.]] | polars into-df | polars filter (((polars col a) > 7) xor ((polars col b) > 5))
Error: nu::shell::operator_unsupported_type

  × The 'xor' operator does not work on values of type 'NuExpression'.
   ╭─[entry #5:1:94]
 1 │ [[a, b]; [1., 2.], [3.,3.], [4., 6.]] | polars into-df | polars filter (((polars col a) > 7) xor ((polars col b) > 5))
   ·                                                                                              ─┬─┬
   ·                                                                                               │ ╰── NuExpression
   ·                                                                                               ╰── does not support 'NuExpression'
   ╰────

@MMesch MMesch changed the title adds And and Xor operators to expressions adds And and Or operators to expressions Mar 5, 2025
@MMesch MMesch force-pushed the mmesch/polars-add-And-and-Xor branch from b2e461e to c24e47b Compare March 5, 2025 09:49
@MMesch MMesch changed the title adds And and Or operators to expressions adds And and Or operators to polars nu_expressions Mar 5, 2025
@MMesch MMesch force-pushed the mmesch/polars-add-And-and-Xor branch from c24e47b to e7e3b30 Compare March 5, 2025 10:14
@MMesch MMesch force-pushed the mmesch/polars-add-And-and-Xor branch from e7e3b30 to 5597257 Compare March 5, 2025 10:17
@MMesch MMesch changed the title adds And and Or operators to polars nu_expressions adds And and Or operators to polars plugin nu_expressions Mar 5, 2025
@fdncred fdncred added A:plugin-polars Work related to the polars dataframe implementation deprecated:pr-plugins Deprecated: use the A:plugins label instead labels Mar 5, 2025
@ayax79
Copy link
Copy Markdown
Contributor

ayax79 commented Mar 5, 2025

Looks good, thanks!

ayax79 pushed a commit that referenced this pull request Mar 5, 2025
solution for #15242 ,  based on PR #15248 .

Allows doing this:

```
~/Projects/nushell> [[a, b]; [1., 2.], [3.,3.], [4., 6.]] | polars into-df | polars filter (((polars col a) < 2) xor ((polars col b) > 5))
╭───┬──────┬──────╮
│ # │  a   │  b   │
├───┼──────┼──────┤
│ 0 │ 1.00 │ 2.00 │
│ 1 │ 4.00 │ 6.00 │
╰───┴──────┴──────╯
```
@ayax79 ayax79 merged commit 551fecd into nushell:main Mar 5, 2025
15 checks passed
@github-actions github-actions bot added this to the v0.103.0 milestone Mar 5, 2025
ayax79 pushed a commit that referenced this pull request Mar 5, 2025
This PR (based on #15249 and #15248 because it mentions them) adds extra
documentation to the main polars command outlining the main datatypes
that are used by the plugin. The lack of a description of the types
involved in `polars xxx` commands was quite confusing to me when I
started using the plugin and this is a first try improving it.

I didn't find a better place but please let me know what you think.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:plugin-polars Work related to the polars dataframe implementation deprecated:pr-plugins Deprecated: use the A:plugins label instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants