Dask-version of bottleneck.push .. note:: Requires bottleneck to be installed.
(array, n, axis)
| 893 | |
| 894 | |
| 895 | def push(array, n, axis): |
| 896 | """ |
| 897 | Dask-version of bottleneck.push |
| 898 | |
| 899 | .. note:: |
| 900 | |
| 901 | Requires bottleneck to be installed. |
| 902 | """ |
| 903 | import_optional_dependency("bottleneck", min_version="1.3.7") |
| 904 | |
| 905 | if n is not None and 0 < n < array.shape[axis] - 1: |
| 906 | arr = broadcast_to( |
| 907 | arange( |
| 908 | array.shape[axis], chunks=array.chunks[axis], dtype=array.dtype |
| 909 | ).reshape( |
| 910 | tuple(size if i == axis else 1 for i, size in enumerate(array.shape)) |
| 911 | ), |
| 912 | array.shape, |
| 913 | array.chunks, |
| 914 | ) |
| 915 | valid_arange = where(notnull(array), arr, np.nan) |
| 916 | valid_limits = (arr - push(valid_arange, None, axis)) <= n |
| 917 | # omit the forward fill that violate the limit |
| 918 | return where(valid_limits, push(array, None, axis), np.nan) |
| 919 | |
| 920 | # The method parameter makes that the tests for python 3.7 fails. |
| 921 | return cumreduction( |
| 922 | func=_push, |
| 923 | binop=_fill_with_last_one, |
| 924 | ident=np.nan, |
| 925 | x=array, |
| 926 | axis=axis, |
| 927 | dtype=array.dtype, |
| 928 | ) |
| 929 | |
| 930 | |
| 931 | def _fill_with_last_one(a, b): |
searching dependent graphs…