MCPcopy
hub / github.com/dask/dask / __new__

Method __new__

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

Source from the content-addressed store, hash-verified

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

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