MCPcopy Index your code
hub / github.com/pydata/xarray / NativeEndiannessArray

Class NativeEndiannessArray

xarray/coding/variables.py:32–74  ·  view source on GitHub ↗

Decode arrays on the fly from non-native to native endianness This is useful for decoding arrays from netCDF3 files (which are all big endian) into native endianness, so they can be used with Cython functions, such as those found in bottleneck and pandas. >>> x = np.arange(5, dtype

Source from the content-addressed store, hash-verified

30
31
32class NativeEndiannessArray(indexing.ExplicitlyIndexedNDArrayMixin):
33 """Decode arrays on the fly from non-native to native endianness
34
35 This is useful for decoding arrays from netCDF3 files (which are all
36 big endian) into native endianness, so they can be used with Cython
37 functions, such as those found in bottleneck and pandas.
38
39 >>> x = np.arange(5, dtype=">i2")
40
41 >>> x.dtype
42 dtype('>i2')
43
44 >>> NativeEndiannessArray(x).dtype
45 dtype('int16')
46
47 >>> indexer = indexing.BasicIndexer((slice(None),))
48 >>> NativeEndiannessArray(x)[indexer].dtype
49 dtype('int16')
50 """
51
52 __slots__ = ("array",)
53
54 def __init__(self, array) -> None:
55 self.array = indexing.as_indexable(array)
56
57 @property
58 def dtype(self) -> np.dtype:
59 return np.dtype(self.array.dtype.kind + str(self.array.dtype.itemsize))
60
61 def _oindex_get(self, key):
62 return type(self)(self.array.oindex[key])
63
64 def _vindex_get(self, key):
65 return type(self)(self.array.vindex[key])
66
67 def __getitem__(self, key) -> Self:
68 return type(self)(self.array[key])
69
70 def get_duck_array(self):
71 return duck_array_ops.astype(self.array.get_duck_array(), dtype=self.dtype)
72
73 def transpose(self, order):
74 return type(self)(self.array.transpose(order))
75
76
77class BoolTypeArray(indexing.ExplicitlyIndexedNDArrayMixin):

Callers 1

decodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…