Example #1
0
    def test_convert_all(self):
        for cuba in CUBA:
            # given
            original_value = dummy_cuba_value(cuba)

            # when
            file_value = convert_to_file_type(original_value, cuba)

            # then
            assert_array_equal(original_value,
                               convert_from_file_type(file_value, cuba))
    def test_convert_all(self):
        for cuba in CUBA:
            # given
            original_value = dummy_cuba_value(cuba)

            # when
            file_value = convert_to_file_type(original_value, cuba)

            # then
            assert_array_equal(original_value,
                               convert_from_file_type(file_value, cuba))
    def _populate(self, row, value):
        """ Populate the row from the DataContainer.

        """
        positions = self._cuba_to_position
        mask = numpy.zeros(
            shape=self._table.coldtypes['mask'].shape, dtype=numpy.bool)
        data = list(row['data'])
        for key in value:
            if key in positions:
                data[positions[key]] = convert_to_file_type(value[key], key)
                mask[positions[key]] = True

        row['mask'] = mask
        row['data'] = tuple(data)
    def _create_rec_array(self, value):
        """ Create a rec_array row from a DataContainer

        """
        positions = self._cuba_to_position
        rec_array = numpy.zeros(shape=1, dtype=self._table._v_dtype)[0]
        data = rec_array['data']
        mask = rec_array['mask']
        for key in value:
            if key in positions:
                position = positions[key]
                # special case array valued cuba keys
                # see numpy issue https://github.com/numpy/numpy/issues/3126
                if numpy.isscalar(data[position]):
                    data[position] = convert_to_file_type(value[key], key)
                else:
                    data[position][:] = convert_from_file_type(value[key], key)
                mask[position] = True
        return rec_array