Skip to content

Cannot access member "contains" for type "ExtensionArray" #664

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

Closed
davetapley opened this issue Apr 28, 2023 · 2 comments · Fixed by #667
Closed

Cannot access member "contains" for type "ExtensionArray" #664

davetapley opened this issue Apr 28, 2023 · 2 comments · Fixed by #667
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Interval Interval data type

Comments

@davetapley
Copy link
Contributor

Describe the bug

Cannot access member "contains" for type "ExtensionArray"
  Member "contains" is unknownPylance[reportGeneralTypeIssues](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportGeneralTypeIssues)
(function) contains: Unknown

To Reproduce

from pandas-dev/pandas#52616 (comment):

df = pd.DataFrame({'A': range(1, 10)})
obj = pd.Interval(1,4)
ser = pd.Series(obj, index=df.index)
arr = ser.array
arr.contains(df["A"])

Please complete the following information:

  • OS: Linux
  • OS Version Ubuntu 20.04.4 LTS
  • python version 3.10.9
  • version of type checker Pylance v2023.4.40
  • version of installed pandas-stubs 2.0.0.230412-py3-none-any
@twoertwein
Copy link
Member

ExtensionArray does not have contains. arr is in your example of type IntervalArray which has contains (in pandas and pandas-stubs).

We might be able to have overloads for def array based on the generic type: return specific subclasses and fallback to ExtensionArray.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Apr 30, 2023

There are a couple of issues here:

  1. We are not recognizing that pd.Series(pd.Interval(1,4)) produces pd.Series[Interval[int]]
  2. If we have a Series[Interval[int]] or Series[Interval[float]], then Series.array should return IntervalArray rather than ExtensionArray

To solve the latter, need to create an overload for Series.array(), but I'm not sure that will work with mypy, so may need to have a type called IntervalSeries that takes care of that.

@Dr-Irv Dr-Irv added ExtensionArray Extending pandas with custom dtypes or arrays. Interval Interval data type labels Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Interval Interval data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants