Skip to content

CLEAN: Remove some unnecessary types from S1 #520

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
Dr-Irv opened this issue Jan 26, 2023 · 12 comments · Fixed by #522
Closed

CLEAN: Remove some unnecessary types from S1 #520

Dr-Irv opened this issue Jan 26, 2023 · 12 comments · Fixed by #522

Comments

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jan 26, 2023

I think that S1 has types that are not needed, e.g., the datetime types.

As discussed here #519 (review)

we should see which ones we can safely remove without changing any tests or other parts

For things like Timestamp, Timedelta, Period, we may be able to get rid of all references to Series[Timestamp], Series[Timedelta] and Series[Period] because we have TimestampSeries, TimedeltaSeries and PeriodSeries, but we leave the references just in the class definition there from an inheritance perspective.

@ramvikrams to investigate

@ramvikrams
Copy link
Contributor

I think that S1 has types that are not needed, e.g., the datetime types.

As discussed here #519 (review)

we should see which ones we can safely remove without changing any tests or other parts

For things like Timestamp, Timedelta, Period, we may be able to get rid of all references to Series[Timestamp], Series[Timedelta] and Series[Period] because we have TimestampSeries, TimedeltaSeries and PeriodSeries, but we leave the references just in the class definition there from an inheritance perspective.

@ramvikrams to investigate

i'll look into it

@ramvikrams
Copy link
Contributor

ramvikrams commented Jan 26, 2023

1)For Series[Timestamp]

from test_scalars.py we have this TimestampSeries can't be used here

    c_series_dt64: pd.Series[pd.Timestamp] = pd.Series(
        [1, 2, 3], dtype="datetime64[ns]"
    )

We have instances like this, here also we can't replace it

_EdgesTimestamp: TypeAlias = Union[
    Sequence[DatetimeLike],
    npt.NDArray[np.datetime64],
    pd.Series[pd.Timestamp],
    TimestampSeries,
    pd.DatetimeIndex,
]

we also have this I think both these are req.

    def __eq__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ...  # type: ignore[misc]
  1. Series[Timedelta] can be replaced with TimedeltaSeries at most places and similary with Series[Period]
  2. we cannot also remove interval[*] as they are referenced
  3. we can remove datetime.*

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Jan 26, 2023

1)For Series[Timestamp]

from test_scalars.py we have this TimestampSeries can't be used here

    c_series_dt64: pd.Series[pd.Timestamp] = pd.Series(
        [1, 2, 3], dtype="datetime64[ns]"
    )

OK, that's actually a bug in the tests and the types because the correct type should be Series[np.datetime64] but if you make that change, then the operators aren't properly defined and you'll get other errors, so for now, you can leave that test alone and it is something I can look to fix. (It's non-trivial)

We have instances like this, here also we can't replace it

_EdgesTimestamp: TypeAlias = Union[
    Sequence[DatetimeLike],
    npt.NDArray[np.datetime64],
    pd.Series[pd.Timestamp],
    TimestampSeries,
    pd.DatetimeIndex,
]

Are you saying if you remove pd.Series[pd.Timestamp] from that declaration, a test will fail?

we also have this I think both these are req.

    def __eq__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ...  # type: ignore[misc]

Yes, it's related to (1) above. So you have to leave it in for now.

  1. Series[Timedelta] can be replaced with TimedeltaSeries at most places and similary with Series[Period]

That's good.

  1. we cannot also remove interval[*] as they are referenced

Yes, I think that has to stay.

  1. we can remove datetime.*

Good.

@ramvikrams
Copy link
Contributor

ramvikrams commented Jan 26, 2023

We have instances like this, here also we can't replace it

_EdgesTimestamp: TypeAlias = Union[
    Sequence[DatetimeLike],
    npt.NDArray[np.datetime64],
    pd.Series[pd.Timestamp],
    TimestampSeries,
    pd.DatetimeIndex,
]

Are you saying if you remove pd.Series[pd.Timestamp] from that declaration, a test will fail?

No, test do not fail but _EdgeTimestamp is called in a func in that file, So will it be a good option to remove it

@ramvikrams
Copy link
Contributor

    def __eq__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ...  # type: ignore[misc]

Yes, it's related to (1) above. So you have to leave it in for now.

I don't think it's related to 1 as we have more declarations like this in pandas-stubs\_libs\tslibs\timestamps.pyi they are used in Timestamp funcs

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Jan 26, 2023

Are you saying if you remove pd.Series[pd.Timestamp] from that declaration, a test will fail?

No, test do not fail but _EdgeTimestamp is called in a func in that file, So will it be a good option to remove it

So just to clarify you can remove pd.Series[pd.Timestamp] in that TypeAlias

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Jan 26, 2023

    def __eq__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ...  # type: ignore[misc]

Yes, it's related to (1) above. So you have to leave it in for now.

I don't think it's related to 1 as we have more declarations like this in pandas-stubs\_libs\tslibs\timestamps.pyi they are used in Timestamp funcs

Try removing them all and see which tests fail, then put back the minimal number so the current tests pass. It's related because I think if you take Series[Timestamp] out of the def __eq__(), a test will fail, but that's because of (1) above.

@ramvikrams
Copy link
Contributor

ramvikrams commented Jan 26, 2023

Try removing them all and see which tests fail, then put back the minimal number so the current tests pass. It's related because I think if you take Series[Timestamp] out of the def __eq__(), a test will fail, but that's because of (1) above.

Actually there are 5(__eq__ , __ne__ , __gt__ , __ge__ , __le__), from 3(__gt__ , __ge__ , __le__) of them we can remove Series[Timestamp] mypy,pyright pass the test but pytest shows 0 errors some time,1 the other time or 2 sometime. Don't know what is wrong with pytest

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Jan 26, 2023

Actually there are 5(__eq__ , __ne__ , __gt__ , __ge__ , __le__), from 3(__gt__ , __ge__ , __le__) of them we can remove Series[Timestamp] mypy,pyright pass the test but pytest shows 0 errors some time,1 the other time or 2 sometime. Don't know what is wrong with pytest

It might relate to (1). If you want, create a PR with what you have and I can take a look.

@ramvikrams
Copy link
Contributor

Actually there are 5(__eq__ , __ne__ , __gt__ , __ge__ , __le__), from 3(__gt__ , __ge__ , __le__) of them we can remove Series[Timestamp] mypy,pyright pass the test but pytest shows 0 errors some time,1 the other time or 2 sometime. Don't know what is wrong with pytest

It might relate to (1). If you want, create a PR with what you have and I can take a look.

Yes I'll create a pr

@ramvikrams
Copy link
Contributor

@Dr-Irv Sir i'll make the PR tommorow, i am not feeling well today So taking rest.

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Jan 27, 2023

@Dr-Irv Sir i'll make the PR tommorow, i am not feeling well today So taking rest.

No rush!

Dr-Irv pushed a commit that referenced this issue Jan 29, 2023
* Modified S1

* Removed two datetime.*

* req. changes

* typo changes

* removed datetime.* and modified the test likewise

* Reverting changes made in last commit
twoertwein pushed a commit to twoertwein/pandas-stubs that referenced this issue Apr 1, 2023
* Modified S1

* Removed two datetime.*

* req. changes

* typo changes

* removed datetime.* and modified the test likewise

* Reverting changes made in last commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants