MCPcopy Create free account
hub / github.com/PyTables/PyTables / _g_fix_byteorder_data

Method _g_fix_byteorder_data

tables/leaf.py:631–655  ·  view source on GitHub ↗

Fix the byteorder of data passed in constructors.

(
        self, data: np.ndarray, dbyteorder: str
    )

Source from the content-addressed store, hash-verified

629 return new_node
630
631 def _g_fix_byteorder_data(
632 self, data: np.ndarray, dbyteorder: str
633 ) -> np.ndarray:
634 """Fix the byteorder of data passed in constructors."""
635 dbyteorder = byteorders[dbyteorder]
636 # If self.byteorder has not been passed as an argument of
637 # the constructor, then set it to the same value of data.
638 if self.byteorder is None:
639 self.byteorder = dbyteorder
640 # Do an additional in-place byteswap of data if the in-memory
641 # byteorder doesn't match that of the on-disk. This is the only
642 # place that we have to do the conversion manually. In all the
643 # other cases, it will be HDF5 the responsible for doing the
644 # byteswap properly.
645 if dbyteorder in ["little", "big"]:
646 if dbyteorder != self.byteorder:
647 # if data is not writeable, do a copy first
648 if not data.flags.writeable:
649 data = data.copy()
650 data.byteswap(True)
651 else:
652 # Fix the byteorder again, no matter which byteorder have
653 # specified the user in the constructor.
654 self.byteorder = "irrelevant"
655 return data
656
657 def _point_selection(self, key: list | tuple | np.ndarray) -> np.ndarray:
658 """Perform a point-wise selection.

Callers 2

_g_createMethod · 0.80
_g_createMethod · 0.80

Calls 1

copyMethod · 0.45

Tested by

no test coverage detected