Skip to content

PeriodIndex element start_time and end_time attributes raise error #536

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
eito-fis opened this issue Feb 14, 2023 · 1 comment · Fixed by #537
Closed

PeriodIndex element start_time and end_time attributes raise error #536

eito-fis opened this issue Feb 14, 2023 · 1 comment · Fixed by #537
Labels
Index Related to the Index class or subclasses

Comments

@eito-fis
Copy link

Describe the bug
Accessing start_time or end_time on a PeriodIndex raises a Member <> is unknown error.

To Reproduce
Code:

import pandas as pd
index = pd.period_range(start = "2000", end="2023", freq="y")
index[0].start_time

Error:

/home/l05/code/opensource/reproduce/pandas_start_end_time.py
  /home/l05/code/opensource/reproduce/pandas_start_end_time.py:4:10 - error: Cannot access member "start_time" for type "str"
    Member "start_time" is unknown (reportGeneralTypeIssues)
  /home/l05/code/opensource/reproduce/pandas_start_end_time.py:4:10 - error: Cannot access member "start_time" for type "bytes"
    Member "start_time" is unknown (reportGeneralTypeIssues)
  /home/l05/code/opensource/reproduce/pandas_start_end_time.py:4:10 - error: Cannot access member "start_time" for type "date"
    Member "start_time" is unknown (reportGeneralTypeIssues)
  /home/l05/code/opensource/reproduce/pandas_start_end_time.py:4:10 - error: Cannot access member "start_time" for type "datetime"
    Member "start_time" is unknown (reportGeneralTypeIssues)
  /home/l05/code/opensource/reproduce/pandas_start_end_time.py:4:10 - error: Cannot access member "start_time" for type "timedelta"
    Member "start_time" is unknown (reportGeneralTypeIssues)
  /home/l05/code/opensource/reproduce/pandas_start_end_time.py:4:10 - error: Cannot access member "start_time" for type "bool"
    Member "start_time" is unknown (reportGeneralTypeIssues)
  /home/l05/code/opensource/reproduce/pandas_start_end_time.py:4:10 - error: Cannot access member "start_time" for type "int"
    Member "start_time" is unknown (reportGeneralTypeIssues)
  /home/l05/code/opensource/reproduce/pandas_start_end_time.py:4:10 - error: Cannot access member "start_time" for type "float"
    Member "start_time" is unknown (reportGeneralTypeIssues)
  /home/l05/code/opensource/reproduce/pandas_start_end_time.py:4:10 - error: Cannot access member "start_time" for type "Timestamp"
    Member "start_time" is unknown (reportGeneralTypeIssues)
  /home/l05/code/opensource/reproduce/pandas_start_end_time.py:4:10 - error: Cannot access member "start_time" for type "Timedelta"
    Member "start_time" is unknown (reportGeneralTypeIssues)
  /home/l05/code/opensource/reproduce/pandas_start_end_time.py:4:10 - error: Cannot access member "start_time" for type "complex"
    Member "start_time" is unknown (reportGeneralTypeIssues)

Please complete the following information:

  • OS: Ubuntu 20.04
  • python version: 3.10.7
  • version of type checker: pyright 1.1.293
  • version of installed pandas-stubs: 1.5.3.230203

Additional context
Would this be as simple as updating the IndexIterScaler type? I would be happy to open a PR.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Feb 14, 2023

Thanks for this report. There are a few issues here

We need to define __getitem__() in core/indexes/period.pyi as follows:

    def __getitem__(self, idx: int ) -> Period: ...

But we also need to fix __getitem__() in core/indexes/base.py and change

def __getitem__(self, idx: int | tuple[np_ndarray_anyint, ...]) -> Scalar: ...

to not have the tuple argument.

We also need to look at the other subclasses of Index in core/indexes and add appropriate __getitem__() definitions so that the right type is returned. This might be better done with a new mixin class that is generic and returns the appropriate type, and just had __getitem__() defined.

Also, need to add appropriate tests for doing a __getitem__() on each of those different subclasses.

@Dr-Irv Dr-Irv added the Index Related to the Index class or subclasses label Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Index Related to the Index class or subclasses
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants