AlenkaF opened a new issue, #55758:
URL: https://github.com/apache/arrow/issues/55758

   While working on compute module stubs in 
https://github.com/apache/arrow/pull/49201 I came across a buggy behavior of 
the top_k_unstable/bottom_k_unstable functions. Both compute functions can be 
called with Array/ChunkedArray or with RecordBatch/Table with different 
handling of the options.
   
   For Array and ChunkedArray `sort_keys` shouldn't be accepted and should 
return `ValueError` with correct message but currently fails due to issues when 
appending to `sort_keys`:
   
   
https://github.com/apache/arrow/blob/4d9a573db144e1bc9e9d6b55b145399313346061/python/pyarrow/compute.py#L614
   
   ```python
   >>> pc.top_k_unstable(arr, k=3, sort_keys="a")
   AttributeError: 'str' object has no attribute 'append'
   
   >>> pc.top_k_unstable(arr, k=3, sort_keys=["a"])
   ValueError: need more than 1 value to unpack
   ```
   
   As for the Table and RecordBatch, the signature suggests `null_placements` 
is optional but that errors with:
   
   ```
   >>> pc.top_k_unstable(table, k=2, sort_keys=["a"])
   ...
   File ~/Repos/arrow/python/pyarrow/compute.py:617, in top_k_unstable(values, 
k, sort_keys, null_placements, memory_pool)
       614     sort_keys.append(("dummy", "descending", "at_end"))
       615 else:
       616     sort_keys = [(sort_key, "descending", null_placement)
   --> 617                  for sort_key, null_placement in zip(sort_keys, 
null_placements)]
       618 options = SelectKOptions(k, sort_keys)
       619 return call_function("select_k_unstable", [values], options, 
memory_pool)
   
   TypeError: 'NoneType' object is not iterable
   ```
   
   because zip does not accept `None`. To match C++, I suggest that 
`null_placements` to default to "at_end". Also, `sort_keys` and 
`null_placements` should be checked for being list-like (at least not str) and 
they should have the same length.
   
   (same for `bottom_k_unstable`)


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to