Sort or "shuffle" the underlying object. "Shuffle" means the object is sorted so that all group members occur sequentially, in the same chunk. Multiple groups may occur in the same chunk. This method is particularly useful for chunked arrays (e.g. dask, cubed).
(self, chunks: T_Chunks = None)
| 63 | return result |
| 64 | |
| 65 | def shuffle_to_chunks(self, chunks: T_Chunks = None): |
| 66 | """ |
| 67 | Sort or "shuffle" the underlying object. |
| 68 | |
| 69 | "Shuffle" means the object is sorted so that all group members occur sequentially, |
| 70 | in the same chunk. Multiple groups may occur in the same chunk. |
| 71 | This method is particularly useful for chunked arrays (e.g. dask, cubed). |
| 72 | particularly when you need to map a function that requires all members of a group |
| 73 | to be present in a single chunk. For chunked array types, the order of appearance |
| 74 | is not guaranteed, but will depend on the input chunking. |
| 75 | |
| 76 | Parameters |
| 77 | ---------- |
| 78 | chunks : int, tuple of int, "auto" or mapping of hashable to int or tuple of int, optional |
| 79 | How to adjust chunks along dimensions not present in the array being grouped by. |
| 80 | |
| 81 | Returns |
| 82 | ------- |
| 83 | DataArrayGroupBy or DatasetGroupBy |
| 84 | |
| 85 | Examples |
| 86 | -------- |
| 87 | >>> import dask.array |
| 88 | >>> da = xr.DataArray( |
| 89 | ... dims="time", |
| 90 | ... data=dask.array.arange(10, chunks=1), |
| 91 | ... coords={"time": xr.date_range("2001-01-01", freq="12h", periods=10)}, |
| 92 | ... name="a", |
| 93 | ... ) |
| 94 | >>> shuffled = da.resample(time="2D").shuffle_to_chunks() |
| 95 | >>> shuffled |
| 96 | <xarray.DataArray 'a' (time: 10)> Size: 80B |
| 97 | dask.array<shuffle, shape=(10,), dtype=int64, chunksize=(4,), chunktype=numpy.ndarray> |
| 98 | Coordinates: |
| 99 | * time (time) datetime64[ns] 80B 2001-01-01 ... 2001-01-05T12:00:00 |
| 100 | |
| 101 | See Also |
| 102 | -------- |
| 103 | dask.dataframe.DataFrame.shuffle |
| 104 | dask.array.shuffle |
| 105 | """ |
| 106 | (_grouper,) = self.groupers |
| 107 | return self._shuffle_obj(chunks).drop_vars(RESAMPLE_DIM) |
| 108 | |
| 109 | def _first_or_last( |
| 110 | self, op: Literal["first", "last"], skipna: bool | None, keep_attrs: bool | None |
nothing calls this directly
no test coverage detected