MCPcopy Create free account
hub / github.com/quantopian/zipline / __array_finalize__

Method __array_finalize__

zipline/lib/labelarray.py:269–306  ·  view source on GitHub ↗

Called by Numpy after array construction. There are three cases where this can happen: 1. Someone tries to directly construct a new array by doing:: >>> ndarray.__new__(LabelArray, ...) # doctest: +SKIP In this case, obj will be None. We treat th

(self, obj)

Source from the content-addressed store, hash-verified

267 return value in self.reverse_categories
268
269 def __array_finalize__(self, obj):
270 """
271 Called by Numpy after array construction.
272
273 There are three cases where this can happen:
274
275 1. Someone tries to directly construct a new array by doing::
276
277 >>> ndarray.__new__(LabelArray, ...) # doctest: +SKIP
278
279 In this case, obj will be None. We treat this as an error case and
280 fail.
281
282 2. Someone (most likely our own __new__) does::
283
284 >>> other_array.view(type=LabelArray) # doctest: +SKIP
285
286 In this case, `self` will be the new LabelArray instance, and
287 ``obj` will be the array on which ``view`` is being called.
288
289 The caller of ``obj.view`` is responsible for setting category
290 metadata on ``self`` after we exit.
291
292 3. Someone creates a new LabelArray by slicing an existing one.
293
294 In this case, ``obj`` will be the original LabelArray. We're
295 responsible for copying over the parent array's category metadata.
296 """
297 if obj is None:
298 raise TypeError(
299 "Direct construction of LabelArrays is not supported."
300 )
301
302 # See docstring for an explanation of when these will or will not be
303 # set.
304 self._categories = getattr(obj, 'categories', None)
305 self._reverse_categories = getattr(obj, 'reverse_categories', None)
306 self._missing_value = getattr(obj, 'missing_value', None)
307
308 def as_int_array(self):
309 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected