You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/04/19 16:30:01 UTC

[GitHub] [arrow] amol- commented on a change in pull request #10101: ARROW-9594: [Python] Preserve null indexes in DictionaryArray.to_numpy as it's done in DictionaryArray.to_pandas

amol- commented on a change in pull request #10101:
URL: https://github.com/apache/arrow/pull/10101#discussion_r616000507



##########
File path: python/pyarrow/array.pxi
##########
@@ -1170,7 +1170,9 @@ cdef class Array(_PandasConvertible):
         array = PyObject_to_object(out)
 
         if isinstance(array, dict):
+            missings = array["indices"] < 0
             array = np.take(array['dictionary'], array['indices'])
+            array[missings] = np.NaN

Review comment:
       I thought about adding a `if missings.any():` here, but it didn't change performances at all, so not much benefit.
   
   ```
   def withoutcheck():
       arr[mask] = np.NaN
   
   def withcheck():
       if mask.any():
           arr[mask] = np.NaN
   
   >>> timeit.timeit(withoutcheck, number=10000)
   5.555068847000001
   >>> timeit.timeit(withcheck, number=10000)
   5.6257486310000075
   ```




-- 
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.

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