Skip to content
This repository has been archived by the owner on Aug 18, 2022. It is now read-only.

Commit

Permalink
Fix bug: After adding extra dimensions, some fields were not copied
Browse files Browse the repository at this point in the history
Resulting in a loss of the values not copied
  • Loading branch information
tmontaigu committed Dec 9, 2020
1 parent 738f04a commit 54d412e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pylas/point/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,27 @@ def from_point_record(cls, other_point_record, new_point_format):
new_record.copy_fields_from(other_point_record)
return new_record

def copy_fields_from(self, other_record):
def copy_fields_from(self, other_record: 'PointRecord'):
"""Tries to copy the values of the current dimensions from other_record"""
for dim_name in self.dimensions_names:
try:
self[dim_name] = np.array(other_record[dim_name])
except ValueError:
pass

def copy_fields_from_numpy_array(self, array: np.ndarray):
for dim_name in self.array.dtype.names:
try:
self[dim_name] = array[dim_name]
except ValueError:
pass

def add_extra_dims(self, dim_tuples: List[Tuple[str, str]]):
for name, type_str in dim_tuples:
self.point_format.add_extra_dimension(name, type_str)
old_array = self.array
self._array = np.zeros_like(old_array, dtype=self.point_format.dtype())
self.copy_fields_from(old_array)
self.copy_fields_from_numpy_array(old_array)

def add_extra_dim(self, name, type_str):
self.add_extra_dims([(name, type_str)])
Expand Down

0 comments on commit 54d412e

Please sign in to comment.