- 
                Notifications
    
You must be signed in to change notification settings  - Fork 170
 
          feat(RFC): A richer Expr IR
          #2572
        
          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
          
     Draft
      
      
            dangotbanned
  wants to merge
  452
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
oh-nodes
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +13,604
        
        
          −2
        
        
          
        
      
    
  
  
     Draft
                    Changes from 118 commits
      Commits
    
    
            Show all changes
          
          
            452 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      cfdacf2
              
                feat: Impl `expand_columns`
              
              
                dangotbanned 04427db
              
                feat: Impl `expand_indices`, `replace_dtype_or_index_with_column`
              
              
                dangotbanned 7b3641b
              
                feat: Impl `replace_wildcard`, `replace_wildcard_with_column`
              
              
                dangotbanned f76c9dd
              
                docs(DRAFT): Add more notes on selectors todo
              
              
                dangotbanned f42e202
              
                feat: Impl `replace_selector`
              
              
                dangotbanned 9a627a7
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned cfe3229
              
                revert: Remove unplanned dtypes stuff and comments
              
              
                dangotbanned 804ac3d
              
                chore: Remove factored-out `Inplace` 🥳
              
              
                dangotbanned 353ef59
              
                chore: use `Version.dtypes`
              
              
                dangotbanned 1d63326
              
                feat: Impl `ExprIR.map_ir` for most nodes
              
              
                dangotbanned 0df2be6
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned d3ea987
              
                fix: typo
              
              
                dangotbanned 4604d9a
              
                test: add `assert_expr_ir_equal`
              
              
                dangotbanned 360caec
              
                test: Add `test_replace_selector`
              
              
                dangotbanned 2550103
              
                feat: Impl `WindowExpr.map_ir`
              
              
                dangotbanned 7dd7092
              
                feat: Impl `FunctionExpr.map_ir`
              
              
                dangotbanned a3b96ee
              
                chore: Tidy up notes
              
              
                dangotbanned b569b57
              
                test: Add `test_prepare_projection`
              
              
                dangotbanned 534c902
              
                test: Add repro for horizontal alias bug
              
              
                dangotbanned 23045dc
              
                fix: Add missing `Exclude` iterators
              
              
                dangotbanned 4e65ebc
              
                refactor(DRAFT): Start splitting out `WindowExpr`
              
              
                dangotbanned 99cb01a
              
                refactor: Use a single `Over` with two builder methods
              
              
                dangotbanned 422bbc7
              
                fix: Expand exprs/selectors in `over(order_by=...)`
              
              
                dangotbanned ee1bdb8
              
                chore: Update comments
              
              
                dangotbanned 41f4070
              
                refactor: Simplify `with_order_by`
              
              
                dangotbanned 7d4543e
              
                refactor: Factor out tuple boilerplate
              
              
                dangotbanned 9303338
              
                perf: Prepare `FrozenSchema` for caching
              
              
                dangotbanned 090330c
              
                feat: Validate expressions with schema
              
              
                dangotbanned d8dcfa4
              
                revert: Remove superseded `_ColumnSelection.expand_columns`
              
              
                dangotbanned 49a6fc9
              
                refactor: Repurpose `col`
              
              
                dangotbanned b244b34
              
                refactor: Make `expr` a dependency of `expr_expansion`
              
              
                dangotbanned 09c01fe
              
                revert: Remove unused `regex` expansion stuff
              
              
                dangotbanned bd58867
              
                refactor: Remove/rename things inherited from `rust`
              
              
                dangotbanned cfcbbda
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 00c2cc1
              
                fix: Add some missing `is_scalar` props
              
              
                dangotbanned 48e9f25
              
                feat: Add `functions.Log`
              
              
                dangotbanned fb3f407
              
                feat: Add `Expr.filter`
              
              
                dangotbanned 52f7975
              
                ci: Update `name-tests-test` exclude pattern
              
              
                dangotbanned ba0271e
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 0ff24fe
              
                refactor: Move types from `common` to `typing`
              
              
                dangotbanned 13caf8d
              
                feat: Utilize `IntoDType`
              
              
                dangotbanned 8c86fea
              
                perf: Add a two-level cache for selectors expansion
              
              
                dangotbanned 6414142
              
                refactor: Replace 3x `replace_*`  functions with 1
              
              
                dangotbanned 80cc1c0
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 0d0d6a2
              
                feat: Support `*args, **kwds` in `when`
              
              
                dangotbanned 534cf16
              
                feat: Add `expr`, `sqrt`, `kurtosis`
              
              
                dangotbanned c9cb596
              
                feat: Ensure mutability stays within function boundaries
              
              
                dangotbanned 03af47e
              
                feat: more consistent index error
              
              
                dangotbanned 446c082
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 43a1ee2
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 708d6ac
              
                refactor: Reduce schema to columns where possible
              
              
                dangotbanned 7dbc380
              
                typo
              
              
                dangotbanned e7e17a7
              
                feat: Add `_repr_html_`
              
              
                dangotbanned 579f9bd
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 12d7c96
              
                chore(ruff): Update for `3.9` typing
              
              
                dangotbanned 1de65d2
              
                fix: More consistent `__str__`
              
              
                dangotbanned 11f1e1b
              
                refactor: Move, document `GroupByKeys`
              
              
                dangotbanned 1134e10
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned e17ab21
              
                refactor: Add some `is_*_expr` guards
              
              
                dangotbanned 12ebe0c
              
                docs: lil note on `prepare_projection`
              
              
                dangotbanned 44f7602
              
                feat(DRAFT): Add `rewrite_elementwise_over`
              
              
                dangotbanned 67451b1
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned b3af144
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 576afa9
              
                feat: Add a basic rewrite composer
              
              
                dangotbanned 2ceadc4
              
                test: `test_rewrite_elementwise_over_(simple|multiple)`
              
              
                dangotbanned 357d419
              
                perf: Add safe caching to `meta.output_name`
              
              
                dangotbanned 2b8aea5
              
                prep for `NamedIR`
              
              
                dangotbanned bcc071a
              
                refactor: Update to rewrite w/ `NamedIR`
              
              
                dangotbanned d973b83
              
                fix: Make sure to call `function` on result
              
              
                dangotbanned 5ae792d
              
                refactor: Add `map_ir` function, un special-case `NamedIR`
              
              
                dangotbanned ed9d769
              
                docs(typing): `IntoFrozenSchema` alias
              
              
                dangotbanned 7dcdf86
              
                test: Move `meta.output_name` doctests, add failing one
              
              
                dangotbanned 54d0781
              
                fix: Get the right name from `FunctionExpr`
              
              
                dangotbanned e8106c4
              
                test: Lots of `output_name` coverage
              
              
                dangotbanned b79181a
              
                test: Backcompat `len`, `nth`
              
              
                dangotbanned 26716c5
              
                refactor: Handle `SortBy`, `WindowExpr` internally
              
              
                dangotbanned 3a1c375
              
                refactor: Simplify `FunctionExpr` version
              
              
                dangotbanned bd5c33f
              
                fix: Ensure `output_name` matches upstream
              
              
                dangotbanned f0d9ddc
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned a84ae05
              
                feat: Add `NamedIR.(__repr__|_repr_html_)`
              
              
                dangotbanned a46b3e5
              
                test: Add `test_rewrite_elementwise_over_complex`
              
              
                dangotbanned 83e2b58
              
                fix: Handle `*args` in `rewrite_elementwise_over`
              
              
                dangotbanned ac2b1ff
              
                feat: Add `int_range`
              
              
                dangotbanned cb8234e
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 7324753
              
                feat: Add `NamedIR.is_elementwise_top_level`
              
              
                dangotbanned 5114d32
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned afd0bc7
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 1f6e1da
              
                feat: Initial `rewrite_binary_agg_over` impl
              
              
                dangotbanned f2f6141
              
                Merge branch 'oh-nodes' of https://github.com/narwhals-dev/narwhals i…
              
              
                dangotbanned f2ac1c6
              
                fix: undo `TypeIs` import
              
              
                dangotbanned 46831ea
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned e726865
              
                fix: Ensure lhs gets leaf name used
              
              
                dangotbanned 6edc52c
              
                test: Add some `rewrite_binary_agg_over`
              
              
                dangotbanned 5c80033
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 4076d4d
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 463d75a
              
                feat: `FrozenSchema` repr#
              
              
                dangotbanned 08dcfca
              
                refactor: Split out `FrozenSchema`
              
              
                dangotbanned 17822e8
              
                planning schema projection
              
              
                dangotbanned 8243433
              
                revert: Drop unplanned `impl_arrow` bits
              
              
                dangotbanned 984c07b
              
                fix(typing): `*Series` generic
              
              
                dangotbanned 1468662
              
                ci: Ignore dtypes import
              
              
                dangotbanned 2985bd5
              
                feat: Reimpl `pyarrow`, start on `select`
              
              
                dangotbanned a85fc7e
              
                feat(pyarrow): Impl `Cast`, `Sort`, `Filter`, `Len`
              
              
                dangotbanned faa91ec
              
                feat(pyarrow): Impl `SortBy`
              
              
                dangotbanned e6fab3f
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 25ba870
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 925d601
              
                feat(pyarrow): Impl `First`, `Last`
              
              
                dangotbanned c823d78
              
                feat(pyarrow): Impl all aggregations
              
              
                dangotbanned b069348
              
                docs: Note on broacasting
              
              
                dangotbanned a4d90d8
              
                feat(DRAFT): Prepare new broadcasting layer
              
              
                dangotbanned 0ba05eb
              
                refactor: Move `flatten_hash_safe`
              
              
                dangotbanned 3a4776f
              
                more giant refactors 😅
              
              
                dangotbanned 5ca704f
              
                ignore-banned-import
              
              
                dangotbanned 8e40fea
              
                fix: alias removed exception types
              
              
                dangotbanned 34355dc
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned e45118d
              
                refactor: Handle expansion, projection at narwhals-level
              
              
                dangotbanned 86d56ad
              
                feat: Add `NamedIR.from_name`
              
              
                dangotbanned a193af0
              
                test: Add `test_lit_series_roundtrip`
              
              
                dangotbanned 8e47788
              
                fix(typing): Propagate `NativeSeriesT`
              
              
                dangotbanned 9e2e2b9
              
                chore(typing): Link to pyright explainer
              
              
                dangotbanned 154a3a0
              
                test: Update tests that shouldn't broadcast
              
              
                dangotbanned 6bf86d8
              
                keep on iterating
              
              
                dangotbanned f2c6566
              
                fix: Fill in missing type params
              
              
                dangotbanned 423ea9a
              
                refactor: Move `native` out of higher protocol
              
              
                dangotbanned f47fed2
              
                refactor: Impl dispatch only once?
              
              
                dangotbanned a4b1a02
              
                chore: planning `CompliantNamespace`
              
              
                dangotbanned 1aaca2a
              
                feat: `col`, `lit` classmethods?
              
              
                dangotbanned 1060f0e
              
                feat(DRAFT): Dispatch take ✌
              
              
                dangotbanned d6ebf9b
              
                Update narwhals/_plan/dummy.py
              
              
                dangotbanned 33ddb8d
              
                maybe `pyarrow` backcompat?
              
              
                dangotbanned 7aa7d1d
              
                is `len` the issue?
              
              
                dangotbanned eebef7a
              
                plz
              
              
                dangotbanned acdbf5e
              
                revert: remove typing check
              
              
                dangotbanned 4437861
              
                fix: Unwrap scalar on old pyarrow
              
              
                dangotbanned 5b6e644
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned bcdca6e
              
                fix: Use new `Interval` helper in `truncate`
              
              
                dangotbanned 96b0c9c
              
                feat(pyarrow): Impl `len`
              
              
                dangotbanned 9583383
              
                feat(pyarrow): More impls
              
              
                dangotbanned 5457b30
              
                test(pyarrow): Coverage for most of the current impl
              
              
                dangotbanned c0c6b7d
              
                refactor(pyarrow): Migrate most of `evaluate` into `ArrowExpr`
              
              
                dangotbanned 5039a09
              
                feat(pyarrow): Add `ArrowDataFrame.sort`
              
              
                dangotbanned c26c862
              
                feat(pyarrow): Impl `Expr.sort_by`
              
              
                dangotbanned c720749
              
                fix: unused-ignore
              
              
                dangotbanned 017aa57
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 8dcc57b
              
                refactor: Move `lit`, `col`, `len` to namespace
              
              
                dangotbanned 4d54ff4
              
                refactor: Move `len` impl to `EagerNamespace`
              
              
                dangotbanned 25a248b
              
                revert: remove unused
              
              
                dangotbanned d682390
              
                feat: Add the remaining top-level nodes
              
              
                dangotbanned 6fdbd34
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 14033ae
              
                refactor: Use `Protocol`s, move to `protocols`
              
              
                dangotbanned d72b200
              
                feat(pyarrow): Impl `BinaryExpr`
              
              
                dangotbanned d5ccd31
              
                🧹🧹🧹
              
              
                dangotbanned a40b044
              
                fix: Align all binary ops with `polars`
              
              
                dangotbanned 1880cef
              
                fix: Fill in some `DType` holes
              
              
                dangotbanned 4b5b9ab
              
                test: use `assert_equal_data`
              
              
                dangotbanned 2c0c067
              
                refactor: tighten up protocols
              
              
                dangotbanned 97b84fd
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned cb2e247
              
                refactor: rename `Agg` -> `AggExpr`
              
              
                dangotbanned 4947ec4
              
                fix: Check for scalars in `int_range`
              
              
                dangotbanned 5c33fce
              
                feat: Identify n-ary functions
              
              
                dangotbanned 3c5663a
              
                feat(DRAFT): Stub out namespace functions
              
              
                dangotbanned f48d868
              
                fix(typing): Oops they return expr
              
              
                dangotbanned 08e2bd2
              
                feat(pyarrow): Impl `int_range`
              
              
                dangotbanned 5635be2
              
                fix: typo in error message
              
              
                dangotbanned 98fe85a
              
                feat(pyarrow): Impl `pow`
              
              
                dangotbanned 63b63c8
              
                feat(pyarrow): Impl `fill_null`, `is_between`
              
              
                dangotbanned cccc323
              
                feat(pyarrow): Impl 6x boolean unary functions
              
              
                dangotbanned 1ad79a1
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 638b585
              
                chore: remove `to_compliant`/`_to_compliant`
              
              
                dangotbanned ccfa7da
              
                rename `to_compliant_test` -> `compliant_test`
              
              
                dangotbanned df52814
              
                test: Add failing `when` tests
              
              
                dangotbanned 3140a48
              
                feat(pyarrow): Impl complex `when-then-otherwise`
              
              
                dangotbanned d9d8e64
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned b5550b4
              
                refactor: Remove `pyarrow<13` compat
              
              
                dangotbanned 97453bb
              
                refactor: Moving around
              
              
                dangotbanned fbb463b
              
                feat(pyarrow): Impl `all_horizontal`
              
              
                dangotbanned 21bf3db
              
                feat(pyarrow): Impl `{any,sum,min,max}_horizontal`
              
              
                dangotbanned 0ae9f5f
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned ec06a5e
              
                test: Shorten some test ids
              
              
                dangotbanned 031d547
              
                test(pyarrow): Add `any_horizontal` tests
              
              
                dangotbanned 51ed0fb
              
                test: Add equiv to `test_sumh_broadcasting`
              
              
                dangotbanned b065573
              
                feat(pyarrow): Impl `mean_horizontal`
              
              
                dangotbanned 3732e5a
              
                fix: fill nulls in `sum_horizontal`
              
              
                dangotbanned 2b44d63
              
                test: Add detail to xfail message
              
              
                dangotbanned 17634cd
              
                refactor: Split out `functions`, `typing`
              
              
                dangotbanned 02092b4
              
                feat(pyarrow): Impl `concat_str`
              
              
                dangotbanned 5d57676
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 3db1e65
              
                prep for complex nodes
              
              
                dangotbanned a5f110f
              
                feat(pyarrow): Impl `map_batches`
              
              
                dangotbanned 747a5ae
              
                test: Add `map_batches` tests
              
              
                dangotbanned e85af02
              
                refactor(pyarrow): Split out `int_range`
              
              
                dangotbanned 088a48a
              
                feat(DRAFT): Add `with_columns`
              
              
                dangotbanned 168e930
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned cf2f96c
              
                fix: Extend exprs in `Schema._with_columns`
              
              
                dangotbanned cd6ade0
              
                wip: add `concat`
              
              
                dangotbanned 76b9b9a
              
                refactor: Split out eager, remove `from_series`
              
              
                dangotbanned 37d7709
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 250922f
              
                revert: Leave out unused `schema_projected` for now
              
              
                dangotbanned 8729ebe
              
                refactor(typing): Relax `_concat_horizontal`
              
              
                dangotbanned 6ef9375
              
                feat(pyarrow): Impl `over_ordered`
              
              
                dangotbanned d3bed76
              
                oop
              
              
                dangotbanned cf38656
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 2c85701
              
                add `_with_columns`
              
              
                dangotbanned 4de8579
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 94d533d
              
                perf: Add early return path for `over_ordered`
              
              
                dangotbanned c893b2f
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned b03d31f
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 25549de
              
                style(ruff): re-run updated config
              
              
                dangotbanned 3ec5f7b
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned a12a985
              
                chore(ruff): re-run updated config x2
              
              
                dangotbanned 62030ae
              
                refactor(expr-ir): Rename `Dummy*` everything (#3014)
              
              
                dangotbanned 25b744d
              
                refactor(expr-ir): Heavily sugar `Function` defs (#3017)
              
              
                dangotbanned fcfcabf
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned de884c5
              
                refactor(typing): Align `NativeDataFrame`
              
              
                dangotbanned dbe2a45
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned f5ecc6e
              
                refactor(expr-ir): Add more builder sugar (#3040)
              
              
                dangotbanned 69eede5
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned c934d25
              
                refactor(expr-ir): Clearing out the cobwebs (#3053)
              
              
                dangotbanned dc3b9ea
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 607ea5a
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 631d3a3
              
                refactor(expr-ir): `copy.replace` most `with_*` methods (#3063)
              
              
                dangotbanned 192de64
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 215386f
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 973824c
              
                refactor(expr-ir): Shrinking `ExprIR` (main) (#3066)
              
              
                dangotbanned 70744e0
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 6bc5ff5
              
                fix(typing): Make pyright mostly happy
              
              
                dangotbanned 2aa8a2e
              
                chore(typing): Ignore the other one for now
              
              
                dangotbanned 53d314d
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 967a150
              
                refactor(expr-ir): Organize `_plan` package (#3122)
              
              
                dangotbanned 318261e
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 7599fc4
              
                revert(ruff): ignore (`RUF043`)
              
              
                dangotbanned e502dcc
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 65f9738
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 8208d32
              
                feat(expr-ir): Support `group_by`, utilize `pyarrow.acero` (#3143)
              
              
                dangotbanned 53f4041
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 2b9dbf0
              
                refactor(expr-ir): Split up and refine `protocols.py` (#3166)
              
              
                dangotbanned 2403f1b
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned bde22ac
              
                feat(expr-ir): Acero `order_by`, `hashjoin` , `DataFrame.{filter,join…
              
              
                dangotbanned cce4289
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 1a433a9
              
                fix: Update alias import
              
              
                dangotbanned bf544d4
              
                fix(expr-ir): Ensure only `__slots__`, and not `__dict__` too (#3201)
              
              
                dangotbanned 63c85c8
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned fa0899a
              
                perf(expr-ir): Optimize `ExpansionFlags.from_ir` (#3206)
              
              
                dangotbanned 1ab1599
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned 34a1fd0
              
                refactor(expr-ir): Improve function dispatch (#3215)
              
              
                dangotbanned dbca5a5
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 9acce69
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 46abfe6
              
                chore: re-sync imports following (#3086)
              
              
                dangotbanned 1ba04b1
              
                Merge remote-tracking branch 'upstream/main' into oh-nodes
              
              
                dangotbanned 089bfb5
              
                Merge branch 'main' into oh-nodes
              
              
                dangotbanned File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """Brainstorming an `Expr` internal representation. | ||
| 
     | 
||
| Notes: | ||
| - Each `Expr` method should be representable by a single node | ||
| - But the node does not need to be unique to the method | ||
| - A chain of `Expr` methods should form a plan of operations | ||
| - We must be able to enforce rules on what plans are permitted: | ||
| - Must be flexible to both eager/lazy and individual backends | ||
| - Must be flexible to a given context (select, with_columns, filter, group_by) | ||
| - Nodes & plans are: | ||
| - Immutable, but | ||
| - Can be extended/re-written at both the Narwhals & Compliant levels | ||
| - Introspectable, but | ||
| - Store as little-as-needed for the common case | ||
| - Provide properties/methods for computing the less frequent metadata | ||
| 
     | 
||
| References: | ||
| - https://github.com/pola-rs/polars/blob/dafd0a2d0e32b52bcfa4273bffdd6071a0d5977a/crates/polars-python/src/lazyframe/visitor/expr_nodes.rs | ||
| - https://github.com/pola-rs/polars/blob/dafd0a2d0e32b52bcfa4273bffdd6071a0d5977a/crates/polars-plan/src/dsl/expr.rs | ||
| - https://github.com/pola-rs/polars/blob/dafd0a2d0e32b52bcfa4273bffdd6071a0d5977a/crates/polars-plan/src/dsl/function_expr/mod.rs | ||
| - https://github.com/pola-rs/polars/blob/dafd0a2d0e32b52bcfa4273bffdd6071a0d5977a/crates/polars-plan/src/dsl/options/mod.rs#L137-L172 | ||
| - https://github.com/pola-rs/polars/blob/3fd7ecc5f9de95f62b70ea718e7e5dbf951b6d1c/crates/polars-plan/src/plans/options.rs#L35-L106 | ||
| - https://github.com/pola-rs/polars/blob/3fd7ecc5f9de95f62b70ea718e7e5dbf951b6d1c/crates/polars-plan/src/plans/options.rs#L131-L236 | ||
| - https://github.com/pola-rs/polars/blob/3fd7ecc5f9de95f62b70ea718e7e5dbf951b6d1c/crates/polars-plan/src/plans/options.rs#L240-L267 | ||
| - https://github.com/pola-rs/polars/blob/6df23a09a81c640c21788607611e09d9f43b1abc/crates/polars-plan/src/plans/aexpr/mod.rs | ||
| 
     | 
||
| Related: | ||
| - https://github.com/narwhals-dev/narwhals/pull/2483#issuecomment-2866902903 | ||
| - https://github.com/narwhals-dev/narwhals/pull/2483#issuecomment-2867331343 | ||
| - https://github.com/narwhals-dev/narwhals/pull/2483#issuecomment-2867446959 | ||
| - https://github.com/narwhals-dev/narwhals/pull/2483#issuecomment-2869070157 | ||
| - (https://github.com/narwhals-dev/narwhals/pull/2538/commits/a7eeb0d23e67cb70e7cfa73cec2c7b69a15c8bef#r2083562677) | ||
| - https://github.com/narwhals-dev/narwhals/issues/2225 | ||
| - https://github.com/narwhals-dev/narwhals/issues/1848 | ||
| - https://github.com/narwhals-dev/narwhals/issues/2534#issuecomment-2875676729 | ||
| - https://github.com/narwhals-dev/narwhals/issues/2291 | ||
| - https://github.com/narwhals-dev/narwhals/issues/2522 | ||
| - https://github.com/narwhals-dev/narwhals/pull/2555 | ||
| """ | ||
| 
     | 
||
| from __future__ import annotations | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| from __future__ import annotations | ||
| 
     | 
||
| from typing import TYPE_CHECKING | ||
| 
     | 
||
| from narwhals._plan.common import ExprIR | ||
| 
     | 
||
| if TYPE_CHECKING: | ||
| from typing import Iterator | ||
| 
     | 
||
| from narwhals.typing import RollingInterpolationMethod | ||
| 
     | 
||
| 
     | 
||
| class Agg(ExprIR): | ||
| __slots__ = ("expr",) | ||
| 
     | 
||
| expr: ExprIR | ||
| 
     | 
||
| @property | ||
| def is_scalar(self) -> bool: | ||
| return True | ||
| 
     | 
||
| def __repr__(self) -> str: | ||
| tp = type(self) | ||
| if tp in {Agg, OrderableAgg}: | ||
| return tp.__name__ | ||
| m = {ArgMin: "arg_min", ArgMax: "arg_max", NUnique: "n_unique"} | ||
| name = m.get(tp, tp.__name__.lower()) | ||
| return f"{self.expr!r}.{name}()" | ||
| 
     | 
||
| def iter_left(self) -> Iterator[ExprIR]: | ||
| yield from self.expr.iter_left() | ||
| yield self | ||
| 
     | 
||
| def iter_right(self) -> Iterator[ExprIR]: | ||
| yield self | ||
| yield from self.expr.iter_right() | ||
| 
     | 
||
| 
     | 
||
| class Count(Agg): ... | ||
| 
     | 
||
| 
     | 
||
| class Max(Agg): ... | ||
| 
     | 
||
| 
     | 
||
| class Mean(Agg): ... | ||
| 
     | 
||
| 
     | 
||
| class Median(Agg): ... | ||
| 
     | 
||
| 
     | 
||
| class Min(Agg): ... | ||
| 
     | 
||
| 
     | 
||
| class NUnique(Agg): ... | ||
| 
     | 
||
| 
     | 
||
| class Quantile(Agg): | ||
| __slots__ = (*Agg.__slots__, "interpolation", "quantile") | ||
| 
     | 
||
| quantile: float | ||
| interpolation: RollingInterpolationMethod | ||
| 
     | 
||
| 
     | 
||
| class Std(Agg): | ||
| __slots__ = (*Agg.__slots__, "ddof") | ||
| 
     | 
||
| ddof: int | ||
| """https://github.com/narwhals-dev/narwhals/pull/2555""" | ||
| 
     | 
||
| 
     | 
||
| class Sum(Agg): ... | ||
| 
     | 
||
| 
     | 
||
| class Var(Agg): | ||
| __slots__ = (*Agg.__slots__, "ddof") | ||
| 
     | 
||
| ddof: int | ||
| """https://github.com/narwhals-dev/narwhals/pull/2555""" | ||
| 
     | 
||
| 
     | 
||
| class OrderableAgg(Agg): ... | ||
| 
     | 
||
| 
     | 
||
| class First(OrderableAgg): | ||
| """https://github.com/narwhals-dev/narwhals/issues/2526.""" | ||
| 
     | 
||
| 
     | 
||
| class Last(OrderableAgg): | ||
| """https://github.com/narwhals-dev/narwhals/issues/2526.""" | ||
| 
     | 
||
| 
     | 
||
| class ArgMin(OrderableAgg): ... | ||
| 
     | 
||
| 
     | 
||
| class ArgMax(OrderableAgg): ... | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| from __future__ import annotations | ||
| 
     | 
||
| # NOTE: Needed to avoid naming collisions | ||
| # - Any | ||
| import typing as t | ||
| 
     | 
||
| from narwhals._plan.common import Function | ||
| from narwhals._plan.options import FunctionFlags, FunctionOptions | ||
| 
     | 
||
| if t.TYPE_CHECKING: | ||
| from narwhals.typing import ClosedInterval | ||
| 
     | 
||
| 
     | 
||
| class BooleanFunction(Function): | ||
| def __repr__(self) -> str: | ||
| tp = type(self) | ||
| if tp is BooleanFunction: | ||
| return tp.__name__ | ||
| m: dict[type[BooleanFunction], str] = { | ||
| All: "all", | ||
| Any: "any", | ||
| AllHorizontal: "all_horizontal", | ||
| AnyHorizontal: "any_horizontal", | ||
| IsBetween: "is_between", | ||
| IsDuplicated: "is_duplicated", | ||
| IsFinite: "is_finite", | ||
| IsNan: "is_nan", | ||
| IsNull: "is_null", | ||
| IsFirstDistinct: "is_first_distinct", | ||
| IsLastDistinct: "is_last_distinct", | ||
| IsUnique: "is_unique", | ||
| IsIn: "is_in", | ||
| Not: "not", | ||
| } | ||
| return m[tp] | ||
| 
     | 
||
| 
     | 
||
| class All(BooleanFunction): | ||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.aggregation() | ||
| 
     | 
||
| 
     | 
||
| class AllHorizontal(BooleanFunction): | ||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.elementwise().with_flags( | ||
| FunctionFlags.INPUT_WILDCARD_EXPANSION | ||
| ) | ||
| 
     | 
||
| 
     | 
||
| class Any(BooleanFunction): | ||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.aggregation() | ||
| 
     | 
||
| 
     | 
||
| class AnyHorizontal(BooleanFunction): | ||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.elementwise().with_flags( | ||
| FunctionFlags.INPUT_WILDCARD_EXPANSION | ||
| ) | ||
| 
     | 
||
| 
     | 
||
| class IsBetween(BooleanFunction): | ||
| """`lower_bound`, `upper_bound` aren't spec'd in the function enum. | ||
| 
     | 
||
| Assuming the `FunctionExpr.input` becomes `s` in the impl | ||
| 
     | 
||
| https://github.com/pola-rs/polars/blob/62257860a43ec44a638e8492ed2cf98a49c05f2e/crates/polars-plan/src/dsl/function_expr/boolean.rs#L225-L237 | ||
| """ | ||
| 
     | 
||
| __slots__ = ("closed",) | ||
| 
     | 
||
| closed: ClosedInterval | ||
| 
     | 
||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.elementwise() | ||
| 
     | 
||
| 
     | 
||
| class IsDuplicated(BooleanFunction): | ||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.length_preserving() | ||
| 
     | 
||
| 
     | 
||
| class IsFinite(BooleanFunction): | ||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.elementwise() | ||
| 
     | 
||
| 
     | 
||
| class IsFirstDistinct(BooleanFunction): | ||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.length_preserving() | ||
| 
     | 
||
| 
     | 
||
| class IsIn(BooleanFunction): | ||
| """``other` isn't spec'd in the function enum. | ||
| 
     | 
||
| See `IsBetween` comment. | ||
| """ | ||
| 
     | 
||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.elementwise() | ||
| 
     | 
||
| 
     | 
||
| class IsLastDistinct(BooleanFunction): | ||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.length_preserving() | ||
| 
     | 
||
| 
     | 
||
| class IsNan(BooleanFunction): | ||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.elementwise() | ||
| 
     | 
||
| 
     | 
||
| class IsNull(BooleanFunction): | ||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.elementwise() | ||
| 
     | 
||
| 
     | 
||
| class IsUnique(BooleanFunction): | ||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.length_preserving() | ||
| 
     | 
||
| 
     | 
||
| class Not(BooleanFunction): | ||
| """`__invert__`.""" | ||
| 
     | 
||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| return FunctionOptions.elementwise() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from __future__ import annotations | ||
| 
     | 
||
| from narwhals._plan.common import Function | ||
| from narwhals._plan.options import FunctionOptions | ||
| 
     | 
||
| 
     | 
||
| class CategoricalFunction(Function): ... | ||
| 
     | 
||
| 
     | 
||
| class GetCategories(CategoricalFunction): | ||
| """https://github.com/pola-rs/polars/blob/62257860a43ec44a638e8492ed2cf98a49c05f2e/crates/polars-plan/src/dsl/function_expr/cat.rs#L7.""" | ||
| 
     | 
||
| @property | ||
| def function_options(self) -> FunctionOptions: | ||
| """https://github.com/pola-rs/polars/blob/62257860a43ec44a638e8492ed2cf98a49c05f2e/crates/polars-plan/src/dsl/function_expr/cat.rs#L41.""" | ||
| return FunctionOptions.groupwise() | ||
| 
     | 
||
| def __repr__(self) -> str: | ||
| return "cat.get_categories" | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.