MCPcopy Index your code
hub / github.com/numpy/numpy / __getattribute__

Method __getattribute__

numpy/_core/records.py:415–443  ·  view source on GitHub ↗
(self, attr)

Source from the content-addressed store, hash-verified

413 ndarray._set_dtype(self, sb.dtype((record, self.dtype)))
414
415 def __getattribute__(self, attr):
416 # See if ndarray has this attr, and return it if so. (note that this
417 # means a field with the same name as an ndarray attr cannot be
418 # accessed by attribute).
419 try:
420 return object.__getattribute__(self, attr)
421 except AttributeError: # attr must be a fieldname
422 pass
423
424 # look for a field with this name
425 fielddict = ndarray.__getattribute__(self, 'dtype').fields
426 try:
427 res = fielddict[attr][:2]
428 except (TypeError, KeyError) as e:
429 raise AttributeError(f"recarray has no attribute {attr}") from e
430 obj = self.getfield(*res)
431
432 # At this point obj will always be a recarray, since (see
433 # PyArray_GetField) the type of obj is inherited. Next, if obj.dtype is
434 # non-structured, convert it to an ndarray. Then if obj is structured
435 # with void type convert it to the same dtype.type (eg to preserve
436 # numpy.record type if present), since nested structured fields do not
437 # inherit type. Don't do this for non-void structures though.
438 if obj.dtype.names is not None:
439 if issubclass(obj.dtype.type, nt.void):
440 return obj.view(dtype=(self.dtype.type, obj.dtype))
441 return obj
442 else:
443 return obj.view(ndarray)
444
445 # Save the dictionary.
446 # If the attr is a field name and not in the saved dictionary

Callers

nothing calls this directly

Calls 2

__getattribute__Method · 0.45
viewMethod · 0.45

Tested by

no test coverage detected