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

Method __new__

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

Source from the content-addressed store, hash-verified

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

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