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

Method __new__

dask/array/core.py:1333–1391  ·  view source on GitHub ↗
(cls, dask, name, chunks, dtype=None, meta=None, shape=None)

Source from the content-addressed store, hash-verified

1331 __slots__ = "dask", "__name", "_cached_keys", "__chunks", "_meta", "__dict__"
1332
1333 def __new__(cls, dask, name, chunks, dtype=None, meta=None, shape=None):
1334 self = super().__new__(cls)
1335 assert isinstance(dask, Mapping)
1336 if not isinstance(dask, HighLevelGraph):
1337 dask = HighLevelGraph.from_collections(name, dask, dependencies=())
1338 self.dask = dask
1339 self._name = str(name)
1340 meta = meta_from_array(meta, dtype=dtype)
1341
1342 if (
1343 isinstance(chunks, str)
1344 or isinstance(chunks, tuple)
1345 and chunks
1346 and any(isinstance(c, str) for c in chunks)
1347 ):
1348 dt = meta.dtype
1349 else:
1350 dt = None
1351 self._chunks = normalize_chunks(chunks, shape, dtype=dt)
1352 if self.chunks is None:
1353 raise ValueError(CHUNKS_NONE_ERROR_MESSAGE)
1354 self._meta = meta_from_array(meta, ndim=self.ndim, dtype=dtype)
1355
1356 for plugin in config.get("array_plugins", ()):
1357 result = plugin(self)
1358 if result is not None:
1359 self = result
1360
1361 try:
1362 layer = self.dask.layers[name]
1363 except (AttributeError, KeyError):
1364 # self is no longer an Array after applying the plugins, OR
1365 # a plugin replaced the HighLevelGraph with a plain dict, OR
1366 # name is not the top layer's name (this can happen after the layer is
1367 # manipulated, to avoid a collision)
1368 pass
1369 else:
1370 if layer.collection_annotations is None:
1371 layer.collection_annotations = {
1372 "shape": self.shape,
1373 "dtype": self.dtype,
1374 "chunksize": self.chunksize,
1375 "chunks": self.chunks,
1376 "type": typename(type(self)),
1377 "chunk_type": typename(type(self._meta)),
1378 }
1379 else:
1380 layer.collection_annotations.update(
1381 {
1382 "shape": self.shape,
1383 "dtype": self.dtype,
1384 "chunksize": self.chunksize,
1385 "chunks": self.chunks,
1386 "type": typename(type(self)),
1387 "chunk_type": typename(type(self._meta)),
1388 }
1389 )
1390

Callers

nothing calls this directly

Calls 6

meta_from_arrayFunction · 0.90
anyFunction · 0.90
typenameFunction · 0.90
normalize_chunksFunction · 0.85
from_collectionsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected