This message was deleted.
# hamilton-help
s
This message was deleted.
e
Ok, that’s definitely odd. Strangely enough, even if you remove
Optional
, it still gets the error — looks like setting the default to
None
makes whatever way we parse it think its optional.
Can probably fix pretty easily, but, taking a step back — do you plan on having multiple parameterizations? Is
optional
cause you want some not to have to have certain inputs?
a
yes, the function would be parametrized with list of column names to rename
I am trying to use the same function where instead of column name, I can only pass a prefix and all columns are renamed. Probably I can split it into two different functions so that existing_names is not optional
e
Yeah, so just thinking of a workaround for you — I think the fix should be easy but wouldn’t want you to be blocked. You might also be able to explicitly pass in
None
and not declare it… OTOH, if you’re hardcoding the parameterizations, the code might be a lot simpler if you make
rename_columns
a helper function.
Copy code
def _rename_columns(...) -> ...:
    ...

def pricing_matrix(pricing_data: pd.DataFrame) -> pd.DataFrame:
    return _rename_columns(
        df=pricing_data,
        existing_names=["Pricing_Custom_UnitPrice"],
        new_names=["BasisOnDemandUnitPrice"],
        prefix="Source")

def other_parameterization(...) -> pd.DataFrame:
    return _rename_columns(
        ...
    )
In this case you don’t need to deal with parameterizations
But also we can fix the parameterization with optionals issue 🙂
👍 1
a
Yeah, I think a workaround for this case is ok. But `group`is kind of restricting use of
Optional
e
Yep, going to fix that
a
Thanx for the quick response BTW.🙂
e
Yeah!
WIP — still need to add unit tests but it works on your case: https://github.com/DAGWorks-Inc/hamilton/pull/133
You can test it out with:
pip install git+<https://github.com/dagworks-inc/hamilton.git@allow-optional-grouping>
if you want
🙌 1
I’ll add unit tests and release a patch release later today!
a
Working for me🫡
🙌 2
Hey, it only solved the validation error, but now I am getting error while creating the driver instance
Driver.driver()
Error message:
Copy code
../hamilton/function_modifiers/expanders.py", line 253, in expand_node
    sequence_component_type = grouped_dependency_spec.resolve_dependency_type(
../hamilton/function_modifiers/dependencies.py", line 68, in resolve_dependency_type
    if origin is None or not issubclass(origin, typing.Sequence):
../typing.py", line 1158, in __subclasscheck__
    return issubclass(cls, self.__origin__)
../abc.py", line 123, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class
Looks like origin is expected be of
typing.Sequence
, but in this case its
typing.Union
s
Do you know what the function signature is that would be causing this?
a
Its the same function above, setting default value to
None
or using
typing.Optional
with
grouped dependencies
👀 1
s
okay I believe I have recreated it
@Ankush Kundaliya okay I just pushed a fix to that branch
if you reinstall it — it should get passed that now.
a
Hey Stefan, just checked it. Looking good. Thanks!
👍 1
s
Yeah we likely have a few other places in the code base that
Optional
isn’t supported. So if you find more, do let us know 🙂
a
Sure.