Michael-J-Ward commented on issue #688:
URL: 
https://github.com/apache/datafusion-python/issues/688#issuecomment-2359193796

   I had just verified with a test - if this test is **not** duplicative then 
maybe we should add it.
   
   ```python
   def test_window_frame_defaults_match_postgres(ctx):
       # ref: https://github.com/apache/datafusion-python/issues/688
       
       # create a RecordBatch and a new DataFrame from it
       batch = pa.RecordBatch.from_arrays(
           [pa.array([1.0, 10.0, 20.0])],
           names=["a"],
       )
   
       df = ctx.create_dataframe([[batch]])
   
       window_frame = WindowFrame("rows", None, None)
   
       col_a = column("a")
   
       # Using `f.window` with or without an unbounded window_frame produces 
the same results
       no_frame = f.window("avg", [col_a]).alias('no_frame')
       with_frame = f.window("avg", [col_a], 
window_frame=window_frame).alias('with_frame')
       df_1 = df.select(col_a, no_frame, with_frame)
   
       expected = """DataFrame()
   +------+--------------------+--------------------+
   | a    | no_frame           | with_frame         |
   +------+--------------------+--------------------+
   | 1.0  | 10.333333333333334 | 10.333333333333334 |
   | 10.0 | 10.333333333333334 | 10.333333333333334 |
   | 20.0 | 10.333333333333334 | 10.333333333333334 |
   +------+--------------------+--------------------+
   """.strip()
   
       assert str(df_1) == expected
   
       # When `order_by` is set, the default window should be `unbounded 
preceding` to `current row`
       no_order = f.avg(col_a).over(Window()).alias('over_no_order')
       with_order = 
f.avg(col_a).over(Window(order_by=[col_a])).alias('over_with_order')
       df_2 = df.select(col_a, no_order, with_order)
   
       expected = """DataFrame()
   +------+--------------------+--------------------+
   | a    | over_no_order      | over_with_order    |
   +------+--------------------+--------------------+
   | 1.0  | 10.333333333333334 | 1.0                |
   | 10.0 | 10.333333333333334 | 5.5                |
   | 20.0 | 10.333333333333334 | 10.333333333333334 |
   +------+--------------------+--------------------+
   """.strip()
       assert str(df_2) == expected
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to