Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] unhashable type error for list of Annotated #3959

Closed
2 tasks done
hududed opened this issue Aug 14, 2023 · 2 comments
Closed
2 tasks done

[BUG] unhashable type error for list of Annotated #3959

hududed opened this issue Aug 14, 2023 · 2 comments
Labels
bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers

Comments

@hududed
Copy link

hududed commented Aug 14, 2023

Describe the bug

Attempted to update house_price_prediction/multiregion_house_price_predictor.py, when appending Annotated[...] into a list, e.g. list[Annotated[StructuredDataset, <..>]] or list[Annotated[pd.DataFrame, <..>]] do not work for me - whatever type I put in <..> gives me unhashable error for that type.

Expected behavior

I expected the type check to pass, as is done originally with typing.List[pd.DataFrame]

Additional context to reproduce

  1. With the imported modules from house_price_predictor.py as-is, change L64-L69 to:
dataset = typing.NamedTuple(
    "GenerateSplitDataOutputs",
    train_data=typing.List[Annotated[pd.DataFrame, COLUMNS]],
    val_data=typing.List[Annotated[pd.DataFrame, COLUMNS]],
    test_data=typing.List[Annotated[pd.DataFrame, COLUMNS]],
)
  1. Run the notebook several times (this occured to me from second run onwards)

Screenshots

╭─────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────╮
│ in <module>:3                                                                                                   │
│                                                                                                                 │
│ /Users/hud/venvs/house_price_prediction/lib/python3.9/site-packages/flytekit/core/task.py:260 in wrapper        │
│                                                                                                                 │
│ ❱ 260 │   │   task_instance = TaskPlugins.find_pythontask_plugin(type(task_config))(                            │
│                                                                                                                 │
│ /Users/hud/venvs/house_price_prediction/lib/python3.9/site-packages/flytekit/core/tracker.py:35 in __call__     │
│                                                                                                                 │
│ ❱  35 │   │   o = super(InstanceTrackingMeta, cls).__call__(*args, **kwargs)                                    │
│                                                                                                                 │
│ /Users/hud/venvs/house_price_prediction/lib/python3.9/site-packages/flytekit/core/python_function_task.py:121   │
│ in __init__                                                                                                     │
│                                                                                                                 │
│ ❱ 121 │   │   super().__init__(                                                                                 │
│                                                                                                                 │
│ /Users/hud/venvs/house_price_prediction/lib/python3.9/site-packages/flytekit/core/python_auto_container.py:85   │
│ in __init__                                                                                                     │
│                                                                                                                 │
│ ❱  85 │   │   super().__init__(                                                                                 │
│                                                                                                                 │
│ /Users/hud/venvs/house_price_prediction/lib/python3.9/site-packages/flytekit/core/base_task.py:420 in __init__  │
│                                                                                                                 │
│ ❱ 420 │   │   │   interface=transform_interface_to_typed_interface(interface),                                  │
│                                                                                                                 │
│ /Users/hud/venvs/house_price_prediction/lib/python3.9/site-packages/flytekit/core/interface.py:248 in           │
│ transform_interface_to_typed_interface                                                                          │
│                                                                                                                 │
│ ❱ 248 │   outputs_map = transform_variable_map(interface.outputs, output_descriptions)                          │
│                                                                                                                 │
│ /Users/hud/venvs/house_price_prediction/lib/python3.9/site-packages/flytekit/core/interface.py:345 in           │
│ transform_variable_map                                                                                          │
│                                                                                                                 │
│ ❱ 345 │   │   │   res[k] = transform_type(v, descriptions.get(k, k))                                            │
│                                                                                                                 │
│ /Users/hud/venvs/house_price_prediction/lib/python3.9/site-packages/flytekit/core/interface.py:350 in           │
│ transform_type                                                                                                  │
│                                                                                                                 │
│ ❱ 350 │   return _interface_models.Variable(type=TypeEngine.to_literal_type(x), description=de                  │
│                                                                                                                 │
│ /Users/hud/venvs/house_price_prediction/lib/python3.9/site-packages/flytekit/core/type_engine.py:826 in         │
│ to_literal_type                                                                                                 │
│                                                                                                                 │
│ ❱  826 │   │   transformer = cls.get_transformer(python_type)                                                   │
│                                                                                                                 │
│ /Users/hud/venvs/house_price_prediction/lib/python3.9/site-packages/flytekit/core/type_engine.py:747 in         │
│ get_transformer                                                                                                 │
│                                                                                                                 │
│ ❱  747 │   │   if python_type in cls._REGISTRY:                                                                 │
│                                                                                                                 │
│ /Users/hud/.pyenv/versions/3.9.17/lib/python3.9/typing.py:757 in __hash__                                       │
│                                                                                                                 │
│ ❱  757 │   │   return hash((self.__origin__, self.__args__))                                                    │
│                                                                                                                 │
│ /Users/hud/.pyenv/versions/3.9.17/lib/python3.9/typing.py:1294 in __hash__                                      │
│                                                                                                                 │
│ ❱ 1294 │   │   return hash((self.__origin__, self.__metadata__))                                                │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: unhashable type: 'list'

Are you sure this issue hasn't been raised already?

  • Yes

Have you read the Code of Conduct?

  • Yes
@hududed hududed added bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers labels Aug 14, 2023
@pingsutw
Copy link
Member

pingsutw commented Aug 15, 2023

Are you able to use dataclass instead? ordered dict (COLUMNS) cannot be hashed in python

@hududed
Copy link
Author

hududed commented Aug 15, 2023

@pingsutw seems like it worked!

@dataclass
class Columns:
    PRICE: int
    YEAR_BUILT: int
    SQUARE_FEET: int
    NUM_BEDROOMS: int
    NUM_BATHROOMS: float
    LOT_ACRES: float
    GARAGE_SPACES: int

closing this.

@hududed hududed closed this as completed Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers
Projects
None yet
Development

No branches or pull requests

2 participants