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

Method __new__

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

Source from the content-addressed store, hash-verified

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

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