You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I run into the below typeerror when trying to use a generic type with pandera DataFrameModel:
(ihme_cc_liaison_service_py3.9) elias1-N9JTWKGPN2:ihme_cc_liaison_service elias1$ python -m bug_report.py
Traceback (most recent call last):
File "/Users/elias1/miniconda3/envs/ihme_cc_liaison_service_py3.9/lib/python3.9/runpy.py", line 188, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/Users/elias1/miniconda3/envs/ihme_cc_liaison_service_py3.9/lib/python3.9/runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "/Users/elias1/projects/ihme_cc_liaison_service/bug_report.py", line 19, in<module>
def get_envelope() -> LiaisonAPIResponse[Envelope]:
File "/Users/elias1/miniconda3/envs/ihme_cc_liaison_service_py3.9/lib/python3.9/site-packages/pydantic/generics.py", line 166, in __class_getitem__
_prepare_model_fields(created_model, fields, instance_type_hints, typevars_map)
File "/Users/elias1/miniconda3/envs/ihme_cc_liaison_service_py3.9/lib/python3.9/site-packages/pydantic/generics.py", line 396, in _prepare_model_fields
concrete_type = replace_types(field_type_hint, typevars_map)
File "/Users/elias1/miniconda3/envs/ihme_cc_liaison_service_py3.9/lib/python3.9/site-packages/pydantic/generics.py", line 298, in replace_types
return origin_type[resolved_type_args]
File "/Users/elias1/miniconda3/envs/ihme_cc_liaison_service_py3.9/lib/python3.9/site-packages/pandera/typing/pandas.py", line 92, in __class_getitem__
_type_check(item, "Parameters to generic types must be types.")
File "/Users/elias1/miniconda3/envs/ihme_cc_liaison_service_py3.9/lib/python3.9/typing.py", line 166, in _type_check
raise TypeError(f"{msg} Got {arg!r:.100}.")
TypeError: Parameters to generic types must be types. Got (Envelope,).
Originally raised in pydantic (pydantic/pydantic#10116) but it seems like the issue is in pandera type checking something that is a tuple without accessing the type variable first. The answer there includes a possible solution: pydantic/pydantic#10116 (comment)
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandera.
(optional) I have confirmed this bug exists on the main branch of pandera.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
fromtypingimportAny, Generic, List, Optional, TypeVarimportpanderaaspafrompydantic.genericsimportGenericModelDF=TypeVar("DF", bound=pa.DataFrameModel)
classLiaisonAPIResponse(GenericModel, Generic[DF]):
"""Response model returned by Liaison routes."""items: pa.typing.DataFrame[DF]
classEnvelope(pa.DataFrameModel):
"""Model for dataframe returned by db_queries.get_envelope."""age_group_id: pa.typing.Series[int]
defget_envelope() ->LiaisonAPIResponse[Envelope]:
returnLiaisonAPIResponse(items=pd.DataFrame({"age_group_id": [1]}))
if__name__=="__main__":
get_envelope()
Expected behavior
Not raise in this case, since the tuple is added to the generic type by pydantic not by my code.
Desktop (please complete the following information):
OS: macOS 14.6
Browser: n/a
Version: 0.20.3
The text was updated successfully, but these errors were encountered:
Describe the bug
I run into the below typeerror when trying to use a generic type with pandera DataFrameModel:
Originally raised in pydantic (pydantic/pydantic#10116) but it seems like the issue is in pandera type checking something that is a tuple without accessing the type variable first. The answer there includes a possible solution: pydantic/pydantic#10116 (comment)
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Expected behavior
Not raise in this case, since the tuple is added to the generic type by pydantic not by my code.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: