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

list[str] type broken #1348

Closed
2 of 3 tasks
janrito opened this issue Sep 25, 2023 · 3 comments
Closed
2 of 3 tasks

list[str] type broken #1348

janrito opened this issue Sep 25, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@janrito
Copy link

janrito commented Sep 25, 2023

Describe the bug
A fix for #1342 , might have broken support for list[str] dtype

  • 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 master 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

import pandas as pd
import pandera as pa
from pandera.typing import DataFrame, Index, Series

class DFModel(pa.DataFrameModel):
    idx: Index[int]
    col_float: Series[float] = pa.Field(coerce=True, nullable=True)
    col_str: Series[str] = pa.Field(coerce=True, nullable=True)
    col_lst: Series[list[str]] = pa.Field(coerce=True, nullable=True)


df = (
    pd.DataFrame(
        [
            {"idx": 1, "col_float": 1.0, "col_str": "one", "col_lst": ["one"]},
            {"idx": 2, "col_float": None, "col_str": None, "col_lst": []},
            {"idx": 3, "col_float": None, "col_str": None, "col_lst": None},
        ]
    )
    .convert_dtypes(infer_objects=False, dtype_backend="numpy_nullable")
    .pipe(DataFrame[DFModel])
)
...
python3.10/site-packages/pandas/core/dtypes/common.py:1636, in pandas_dtype(dtype)
   1631     with warnings.catch_warnings():
   1632         # GH#51523 - Series.astype(np.integer) doesn't show
   1633         # numpy deprecation warning of np.integer
   1634         # Hence enabling DeprecationWarning
   1635         warnings.simplefilter("always", DeprecationWarning)
-> 1636         npdtype = np.dtype(dtype)
   1637 except SyntaxError as err:
   1638     # np.dtype uses `eval` which can raise SyntaxError
   1639     raise TypeError(f"data type '{dtype}' not understood") from err

TypeError: Cannot interpret 'list[str]' as a data type

Expected behavior

A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

@janrito janrito added the bug Something isn't working label Sep 25, 2023
@cosmicBboy
Copy link
Collaborator

I encountered this error as well when creating the PR, have you tried this on the latest main branch yet? Which version are you using?

@janrito
Copy link
Author

janrito commented Sep 25, 2023

Ah, i assumed the version released yesterday included this fix.

@janrito
Copy link
Author

janrito commented Sep 25, 2023

I just tested this. It works fine on main, soz!

@janrito janrito closed this as completed Sep 25, 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
Projects
None yet
Development

No branches or pull requests

2 participants