Changelog
Version 2.1.2
Update type-hint for
@Option.namespaceto make namespaces easier to use with type checkersOptimize
Dataset.evaluateto avoid a large number of redundant function calls
Version 2.1.1
Fix bug introduced in 2.1.0 where exceptions raised during
.evaluateare all masked asEvaluationError
Version 2.1.0
Add many helper functions in
labrea.functions:partialAnalog of
functools.partial
intoAnalog of
*unpacking but for an evaluatable that returns an iterable
ensureMake an assertion before continuing to next step
get_attributeGet attribute from an object
call_methodCall a method on an object
flattenFlatten an interable of iterables
flatmapMap then flatten result
map_items,map_keys, andmap_valuesAnalogs of
mapbut for mapping types
filter_items,filter_keys, andfilter_valuesAnalogs of
filterbut for mapping types
concat,appendAdd items to an interable
intersect,union,difference,symmetric_differenceSet operations
mergeMerge two dictionaries
get,get_fromGet a key from an indexable object
lengthadd,subtract,multiply,divide_by,left_multiply,divide_into,negate,moduloBasic math operations
eg,ne,lt,le,gt,geBasic comparison operations
positive,negative,non_positive,non_negativeCommon comparisons
is_none,is_not_noneCheck if an object is None
has_remainder,even,oddChecking modulo of a number
any,allCheck if multiple predicates hold
invertInvert a boolean value
instance_ofCheck if an object is an instance of a class
is_in,is_not_in,one_of,none_of,contains,does_not_contain,intersects,disjoint_fromCheck if a value is another collection
Add optional
typeanddomainarguments to theOptionconstructortypeis a type hint for the value of the optionBy default, not enforced at runtime
An optional
labrea-type-validationpackage is planned to enforce with pydanticCan use
Option[Type]("KEY")syntax instead
domainis one ofA container of valid values
A predicate function
An evaluatable that returns one of the above
Add
@Option.namespacedecorator for creating option namespacesAlso
Option.autohelper method for creating options within a namespace
Add
Option.setmethod for setting the value of an option in a dictionaryAdd
callbackargument to@datasetdecorator for providing a callback function to be called after the dataset is evaluatedThis callback is inherited by all overloads of the dataset
Add the ability to stack the
Dataset.overloaddecorator with the@datasetdecoratorThis allows for a nested overload tree to be defined
Add new
TypeValidationRequestfor validating typesOptions will run this request when evaluated, but by default no handler is provided
Add request types for the core
.evaluate,.validate,.keys, and.explainmethodsBy default these just call the class’ implementation
Can be handled to provide custom behavior, such as mocking
Improved logging for the evaluation traceback
Modify
PartialApplicationtype to work even if multiple arguments are missingAllow
dataset.whereto be used with functions with**kwargsFix a bug that cause caching to be susceptible to hash collisions.
Version 2.0.4
Make the
Datasettype pickleable
Version 2.0.3
Fix bug introduced in 2.0.3 where dispatch is called with no options
Version 2.0.2
Allow
datasetto be used to directly wrap an evaluatableFix bug in
Switch.keysthat didn’t properly handle when the dispatch by default will evaluate to something
Version 2.0.1
Fix bug where pipeline steps are evaluated before their inputs
Version 2.0.0
Breaking Changes
Module structure has been fully changed.
Any imports that look like
from labrea.<module> import <object>will need to be updated
Changes to dataset
To overload a dataset, you now must provide a
dispatch=argument to the decoratorPreviously, a default dispatch of
Option('LABREA.IMPLEMENTATIONS.pkg.module.dataset_name')was usedSimilarly, a dispatch argument is required for the
@interfacedecorator
@my_dataset.overloadnow takesalias=as either an alias or a list of aliasesPreviously,
aliases=was used for a list of aliases
where=argument is now renameddefaults=for clarity@datasetno longer accepts analias=argumentcallbacks=has been renamed toeffects=Now takes functions of a single argument, or
Evaluatableobjects that return such functionsCan also subclass the
labrea.computation.Effectclass to define custom effects
Changes to options
Previously, it was implicitly assumed that options must be a JSON-serializable dictionary
This is now enforced. Providing a non-serializable option will raise an error
e.g. a Pandas DataFrame cannot be provided as an option value
Changes to pipelines
LabreaPipeline.stephas been removed in favor of thepipeline_stepdecoratorDefining pipeline steps looks the same (like a dataset with empty first arg)
Composing pipeline steps is now done with the
+operator rather than the>>operatorThis is because
>>is now used as an alias for the new.applymethod on allEvaluatableobjects
Pipelines can now be invoked in one of two ways
pipeline(options)(value)pipeline.transform(value, options)Here options can be omitted and an empty dictionary will be used
Pipelines now return the plain value, rather than the special
LabreaPipelineDataobject
Changes to Caching
Datasets are cached, but overloads do not have their own cache
This means that if you overload a dataset, it will be cached in the parent dataset’s cache rather than in a separate cache
The
get,set, andexistshooks in theCacheABC have changed signaturesThis only impacts those who were writing custom cache implementations
Evaluatableis now anABCrather than aProtocolThis only impacts those who are extending the labrea framework with custom types
Implementing multiple interfaces at once is now done using the
@implementsdecoratorPreviously done with
@Interface.implementation(Interface1, Interface2, alias='ALIAS')@implements(Interface1, Interface2, alias='ALIAS')
New Features
All
Evaluatableobjects (datasets,Options, etc.) now have a.explain()method that returns a set of option keys that are required to evaluate the objectOption('A').explain() == {'A'}Datasets will return every option key that is required to evaluate the dataset
All
Evaluatableobjects can be called with no argument and an empty options dictionary will be inferredAll
Evaluatableobjects now support the following methods for chaining transformationsapply(aliased as>>)Used to apply a function to the result of an object
e.g.
my_dataset >> (lambda x: x + 1)
bindUsed to apply a function to the result of an object and return a new labrea object based on the result
e.g.
my_dataset.bind(lambda x: my_dataset2 if x > 0 else my_dataset3)
Utility functions for some common operations for chaning together
labrea.functions.maprecreates themapfunction for labrea objectsmy_list_dataset >> labrea.functions.map(lambda x: x + 1)
labrea.functions.filterrecreates thefilterfunction for labrea objectsmy_list_dataset >> labrea.functions.filter(lambda x: x > 0)
labrea.functions.reducerecreates thereducefunction for labrea objectsmy_list_dataset >> labrea.functions.reduce(lambda x, y: x + y)
New
@pipeline_stepdecorator for defining pipeline stepsPipelines are now evaluatable, meaning they act like a dataset the returns a function of one variable
This means a pipeline can be provided as an argument to a dataset definition
New case / when / otherwise syntax for defining conditional logic that can’t be expressed with switches/overloads
case(Option('A')).when(lambda a: a > 0, positive_dataset).otherwise(negative_dataset)
New
Maptype for mapping a dataset over multiple options valuesMap(Option('A'), {'A': [1, 2, 3]}).apply(list)()==[1, 2, 3]
New
WithOptionstype that can be used to provide pre-set options to anEvaluatableobjectmy_dataset_a_1 = WithOptions(my_dataset, {'A': 1})
New
@implementsdecorator for implementing multiple interfaces at once@implements(Interface1, Interface2, alias='ALIAS')
New
Cachedtype that can cache any labrea object (not just datasets)New
Overloadedtype that can provide overloads for any labrea object (not just datasets)New
FunctionApplication,PartialApplication, andEvaluatableArgumentstypes that are the foundational building blocks for datasets and pipeline stepsNew effects system and corresponding
Computationtype that performs side-effects after an evaluation of a labrea objectNew
runtimemodule used for handling managed effects
Version 1.4.0
Release as open source