MCPcopy Create free account
hub / github.com/dask/dask / auto_chunks

Function auto_chunks

dask/array/core.py:3252–3419  ·  view source on GitHub ↗

Determine automatic chunks This takes in a chunks value that contains ``"auto"`` values in certain dimensions and replaces those values with concrete dimension sizes that try to get chunks to be of a certain size in bytes, provided by the ``limit=`` keyword. If multiple dimensions

(chunks, shape, limit, dtype, previous_chunks=None)

Source from the content-addressed store, hash-verified

3250
3251
3252def auto_chunks(chunks, shape, limit, dtype, previous_chunks=None):
3253 """Determine automatic chunks
3254
3255 This takes in a chunks value that contains ``"auto"`` values in certain
3256 dimensions and replaces those values with concrete dimension sizes that try
3257 to get chunks to be of a certain size in bytes, provided by the ``limit=``
3258 keyword. If multiple dimensions are marked as ``"auto"`` then they will
3259 all respond to meet the desired byte limit, trying to respect the aspect
3260 ratio of their dimensions in ``previous_chunks=``, if given.
3261
3262 Parameters
3263 ----------
3264 chunks: Tuple
3265 A tuple of either dimensions or tuples of explicit chunk dimensions
3266 Some entries should be "auto"
3267 shape: Tuple[int]
3268 limit: int, str
3269 The maximum allowable size of a chunk in bytes
3270 previous_chunks: Tuple[Tuple[int]]
3271
3272 See also
3273 --------
3274 normalize_chunks: for full docstring and parameters
3275 """
3276 if previous_chunks is not None:
3277 # rioxarray is passing ((1, ), (x,)) for shapes like (100, 5x),
3278 # so add this compat code for now
3279 # https://github.com/corteva/rioxarray/pull/820
3280 previous_chunks = (
3281 c[0] if isinstance(c, tuple) and len(c) == 1 else c for c in previous_chunks
3282 )
3283 previous_chunks = _convert_int_chunk_to_tuple(shape, previous_chunks)
3284 chunks = list(chunks)
3285
3286 autos = {i for i, c in enumerate(chunks) if c == "auto"}
3287 if not autos:
3288 return tuple(chunks)
3289
3290 if limit is None:
3291 limit = config.get("array.chunk-size")
3292 if isinstance(limit, str):
3293 limit = parse_bytes(limit)
3294
3295 if dtype is None:
3296 raise TypeError("dtype must be known for auto-chunking")
3297
3298 if dtype.hasobject:
3299 raise NotImplementedError(
3300 "Can not use auto rechunking with object dtype. "
3301 "We are unable to estimate the size in bytes of object data"
3302 )
3303
3304 for x in tuple(chunks) + tuple(shape):
3305 if (
3306 isinstance(x, Number)
3307 and np.isnan(x)
3308 or isinstance(x, tuple)
3309 and np.isnan(x).any()

Callers 1

normalize_chunksFunction · 0.85

Calls 12

parse_bytesFunction · 0.90
maxFunction · 0.90
_compute_multiplierFunction · 0.85
setClass · 0.85
_trivial_aggregateFunction · 0.85
round_toFunction · 0.85
getMethod · 0.45
anyMethod · 0.45
prodMethod · 0.45
medianMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected