Skip to content

Commit

Permalink
adjust exception handling for tranforms.batch
Browse files Browse the repository at this point in the history
  • Loading branch information
cblades-tc committed Oct 7, 2024
1 parent b18e0b8 commit cb01b27
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
6 changes: 3 additions & 3 deletions tcex/api/tc/ti_transform/ti_predefined_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def _is_function(obj):
getattr(fn, '_tcex_function_definition', {})
or {
'name': fn.__name__,
'label': self._snake_to_tile_case(fn.__name__),
'label': self._snake_to_tilecase(fn.__name__),
'params': self._get_params_defs(fn),
'help': getattr(fn, '__doc__', ''),
}
Expand All @@ -279,7 +279,7 @@ def _is_function(obj):
return specs # type: ignore

@staticmethod
def _snake_to_tile_case(name):
def _snake_to_titlecase(name):
return name.replace('_', ' ').title()

@staticmethod
Expand All @@ -300,7 +300,7 @@ def _get_params_defs(fn) -> list[ParamDefinition]:
sig.parameters[p].default if sig.parameters[p].default != _empty else None
),
'name': p,
'label': ProcessingFunctions._snake_to_tile_case(p),
'label': ProcessingFunctions._snake_to_tilecase(p),
'type': (
sig.parameters[p].annotation.__name__ if sig.parameters[p].annotation else 'str'
),
Expand Down
20 changes: 19 additions & 1 deletion tcex/api/tc/ti_transform/ti_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
from datetime import datetime

# first-party
from build.lib.build.lib.build.lib.build.lib.build.lib.build.lib.build.lib.build.lib.build.lib.build.lib.build.lib.build.lib.build.lib.build.lib.build.lib.build.lib.build.lib.tcex.api.tc.ti_transform.transform_abc import (
TransformException,
)
from tcex.api.tc.ti_transform.model import GroupTransformModel, IndicatorTransformModel
from tcex.api.tc.ti_transform.transform_abc import TransformABC, TransformsABC
from tcex.api.tc.ti_transform.transform_abc import (
NoValidTransformException,
TransformABC,
TransformsABC,
)


class TiTransforms(TransformsABC):
Expand Down Expand Up @@ -34,6 +41,17 @@ def batch(self) -> dict:
# batch must be called so that the transform type is selected
try:
data = t.batch
except NoValidTransformException:
self.log.exception('feature=ti-transforms, event=runtime-error')
continue
except TransformException as e:
self.log.warning(
f'feature=ti-transforms, event=transform-error, field="{e.field}", '
f'cause="{e.cause}", context="{e.context}"'
)
if self.raise_exceptions:
raise
continue
except Exception:
self.log.exception('feature=ti-transforms, event=transform-error')
if self.raise_exceptions:
Expand Down
8 changes: 6 additions & 2 deletions tcex/api/tc/ti_transform/transform_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def __str__(self) -> str:
return f'Error transforming {self.field}: {self.cause}'


class NoValidTransformException(Exception):
"""Exception for when no valid transform is found."""


class TransformsABC(ABC):
"""Transform Abstract Base Class"""

Expand All @@ -76,7 +80,7 @@ def _validate_transforms(self):
"""Validate the transform model."""
if len(self.transforms) > 1:
for transform in self.transforms:
if transform.applies is None:
if not callable(transform.applies):
raise ValueError(
'If more than one transform is provided, each '
'provided transform must provide an apply field.',
Expand Down Expand Up @@ -477,7 +481,7 @@ def _select_transform(self):
self.transform = transform
break
else:
raise RuntimeError('No transform found for TI data')
raise NoValidTransformException('No transform found for TI data')

def _transform_value(self, metadata: MetadataTransformModel | None) -> str | None:
"""Pass value to series transforms."""
Expand Down

0 comments on commit cb01b27

Please sign in to comment.