From 0b88abc8d61dc1eaa23e52f0cd804222845977dc Mon Sep 17 00:00:00 2001 From: mathleur Date: Mon, 9 Sep 2024 13:32:33 +0200 Subject: [PATCH 1/2] revert to unsliceable axis if we can't perform a type change --- polytope/datacube/backends/datacube.py | 35 ++++++++++++------- .../datacube_type_change.py | 12 ++++++- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/polytope/datacube/backends/datacube.py b/polytope/datacube/backends/datacube.py index a1dfbfb30..e5d9aa7a7 100644 --- a/polytope/datacube/backends/datacube.py +++ b/polytope/datacube/backends/datacube.py @@ -77,19 +77,28 @@ def _create_axes(self, name, values, transformation_type_key, transformation_opt for axis_name in final_axis_names: self.fake_axes.append(axis_name) # if axis does not yet exist, create it - - # first need to change the values so that we have right type - values = transformation.change_val_type(axis_name, values) - if self._axes is None or axis_name not in self._axes.keys(): - DatacubeAxis.create_standard(axis_name, values, self) - # add transformation tag to axis, as well as transformation options for later - setattr(self._axes[axis_name], has_transform[transformation_type_key.name], True) # where has_transform is - # a factory inside datacube_transformations to set the has_transform, is_cyclic etc axis properties - # add the specific transformation handled here to the relevant axes - # Modify the axis to update with the tag - - if transformation not in self._axes[axis_name].transformations: # Avoids duplicates being stored - self._axes[axis_name].transformations.append(transformation) + print("FIRST") + print(axis_name) + print(transformation.change_val_type(axis_name, values)) + if transformation.change_val_type(axis_name, values) is not None: + print("HERE?") + print(axis_name) + # first need to change the values so that we have right type + values = transformation.change_val_type(axis_name, values) + if self._axes is None or axis_name not in self._axes.keys(): + DatacubeAxis.create_standard(axis_name, values, self) + # add transformation tag to axis, as well as transformation options for later + setattr(self._axes[axis_name], has_transform[transformation_type_key.name], True) + # where has_transform is a factory inside datacube_transformations to set the has_transform, is_cyclic + # etc axis properties add the specific transformation handled here to the relevant axes + # Modify the axis to update with the tag + + if transformation not in self._axes[axis_name].transformations: # Avoids duplicates being stored + self._axes[axis_name].transformations.append(transformation) + else: + # Means we have an unsliceable axis since we couln't transform values to desired type + if self._axes is None or axis_name not in self._axes.keys(): + DatacubeAxis.create_standard(axis_name, values, self) def _add_all_transformation_axes(self, options, name, values): for transformation_type_key in options.transformations: diff --git a/polytope/datacube/transformations/datacube_type_change/datacube_type_change.py b/polytope/datacube/transformations/datacube_type_change/datacube_type_change.py index 8cbf2c44e..ffeafbe6c 100644 --- a/polytope/datacube/transformations/datacube_type_change/datacube_type_change.py +++ b/polytope/datacube/transformations/datacube_type_change/datacube_type_change.py @@ -25,6 +25,13 @@ def transformation_axes_final(self): def change_val_type(self, axis_name, values): return_idx = [self._final_transformation.transform_type(val) for val in values] + if None in return_idx: + print("NOW") + print(axis_name) + print(return_idx) + print("NOW NOW") + print(any(return_idx)) + return None return_idx.sort() return return_idx @@ -61,7 +68,10 @@ def __init__(self, axis_name, new_type): self._new_type = new_type def transform_type(self, value): - return int(value) + try: + return int(value) + except ValueError: + return None def make_str(self, value): values = [] From a04776b95568254a1c93e7d2e98b3cd7e3ab92a8 Mon Sep 17 00:00:00 2001 From: mathleur Date: Mon, 9 Sep 2024 13:34:52 +0200 Subject: [PATCH 2/2] clean up --- polytope/datacube/backends/datacube.py | 5 ----- .../datacube_type_change/datacube_type_change.py | 5 ----- polytope/options.py | 1 - 3 files changed, 11 deletions(-) diff --git a/polytope/datacube/backends/datacube.py b/polytope/datacube/backends/datacube.py index e5d9aa7a7..524bb5298 100644 --- a/polytope/datacube/backends/datacube.py +++ b/polytope/datacube/backends/datacube.py @@ -77,12 +77,7 @@ def _create_axes(self, name, values, transformation_type_key, transformation_opt for axis_name in final_axis_names: self.fake_axes.append(axis_name) # if axis does not yet exist, create it - print("FIRST") - print(axis_name) - print(transformation.change_val_type(axis_name, values)) if transformation.change_val_type(axis_name, values) is not None: - print("HERE?") - print(axis_name) # first need to change the values so that we have right type values = transformation.change_val_type(axis_name, values) if self._axes is None or axis_name not in self._axes.keys(): diff --git a/polytope/datacube/transformations/datacube_type_change/datacube_type_change.py b/polytope/datacube/transformations/datacube_type_change/datacube_type_change.py index ffeafbe6c..5fb88ece1 100644 --- a/polytope/datacube/transformations/datacube_type_change/datacube_type_change.py +++ b/polytope/datacube/transformations/datacube_type_change/datacube_type_change.py @@ -26,11 +26,6 @@ def transformation_axes_final(self): def change_val_type(self, axis_name, values): return_idx = [self._final_transformation.transform_type(val) for val in values] if None in return_idx: - print("NOW") - print(axis_name) - print(return_idx) - print("NOW NOW") - print(any(return_idx)) return None return_idx.sort() return return_idx diff --git a/polytope/options.py b/polytope/options.py index 78c7a20da..6baf8bc73 100644 --- a/polytope/options.py +++ b/polytope/options.py @@ -66,7 +66,6 @@ class Config(ConfigModel): class PolytopeOptions(ABC): @staticmethod def get_polytope_options(options): - parser = argparse.ArgumentParser(allow_abbrev=False) conflator = Conflator(app_name="polytope", model=Config, cli=False, argparser=parser, **options) config_options = conflator.load()