Skip to content

Commit c1af2a2

Browse files
authored
Merge pull request #205 from ecmwf/feature/revert_to_unsliceable_when_unfeasible
Feature/revert to unsliceable when unfeasible
2 parents a12fdee + bb8bc38 commit c1af2a2

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

polytope_feature/datacube/backends/datacube.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,23 @@ def _create_axes(self, name, values, transformation_type_key, transformation_opt
7979
for axis_name in final_axis_names:
8080
self.fake_axes.append(axis_name)
8181
# if axis does not yet exist, create it
82-
83-
# first need to change the values so that we have right type
84-
values = transformation.change_val_type(axis_name, values)
85-
if self._axes is None or axis_name not in self._axes.keys():
86-
DatacubeAxis.create_standard(axis_name, values, self)
87-
# add transformation tag to axis, as well as transformation options for later
88-
setattr(self._axes[axis_name], has_transform[transformation_type_key.name], True) # where has_transform is
89-
# a factory inside datacube_transformations to set the has_transform, is_cyclic etc axis properties
90-
# add the specific transformation handled here to the relevant axes
91-
# Modify the axis to update with the tag
92-
93-
if transformation not in self._axes[axis_name].transformations: # Avoids duplicates being stored
94-
self._axes[axis_name].transformations.append(transformation)
82+
if transformation.change_val_type(axis_name, values) is not None:
83+
# first need to change the values so that we have right type
84+
values = transformation.change_val_type(axis_name, values)
85+
if self._axes is None or axis_name not in self._axes.keys():
86+
DatacubeAxis.create_standard(axis_name, values, self)
87+
# add transformation tag to axis, as well as transformation options for later
88+
setattr(self._axes[axis_name], has_transform[transformation_type_key.name], True)
89+
# where has_transform is a factory inside datacube_transformations to set the has_transform, is_cyclic
90+
# etc axis properties add the specific transformation handled here to the relevant axes
91+
# Modify the axis to update with the tag
92+
93+
if transformation not in self._axes[axis_name].transformations: # Avoids duplicates being stored
94+
self._axes[axis_name].transformations.append(transformation)
95+
else:
96+
# Means we have an unsliceable axis since we couln't transform values to desired type
97+
if self._axes is None or axis_name not in self._axes.keys():
98+
DatacubeAxis.create_standard(axis_name, values, self)
9599

96100
def _add_all_transformation_axes(self, options, name, values):
97101
for transformation_type_key in options.transformations:

polytope_feature/datacube/transformations/datacube_type_change/datacube_type_change.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def transformation_axes_final(self):
2525

2626
def change_val_type(self, axis_name, values):
2727
return_idx = [self._final_transformation.transform_type(val) for val in values]
28+
if None in return_idx:
29+
return None
2830
return_idx.sort()
2931
return return_idx
3032

@@ -61,7 +63,10 @@ def __init__(self, axis_name, new_type):
6163
self._new_type = new_type
6264

6365
def transform_type(self, value):
64-
return int(value)
66+
try:
67+
return int(value)
68+
except ValueError:
69+
return None
6570

6671
def make_str(self, value):
6772
values = []

0 commit comments

Comments
 (0)