Skip to content

Add type parameter to remaining Series.astype overloads. #949

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

Merged
merged 3 commits into from
Jun 28, 2024

Conversation

JanEricNitschke
Copy link
Contributor

@JanEricNitschke JanEricNitschke commented Jun 28, 2024

  • Closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added: Please use assert_type() to assert the type of any return value

Closes #948

Verified that some of the test statements here pass pyright strict with this change that do not do so without.

Tested using object instead of Any as that is the runtime behaviour, but that did not work due to the parameter bounds.

Other option (maybe better?) would be to explicitely return as series matching the specified parameter? But i think that does not work either because the bounds of the type parameter for series are more restrictive than the input arguments for astype.

@@ -1320,14 +1320,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
dtype: CategoryDtypeArg,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series: ...
) -> Series[CategoryDtypeArg]: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be CategoryDtype as it is value in S1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the change

Comment on lines 2584 to 2585
assert_type(s.astype(pd.CategoricalDtype()), "pd.Series[CategoryDtypeArg]")
assert_type(s.astype("category"), "pd.Series[CategoryDtypeArg]")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be CategoryDtype

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dr-Irv Dr-Irv merged commit e1ba6ad into pandas-dev:main Jun 28, 2024
13 checks passed
@JanEricNitschke JanEricNitschke deleted the fix-series-astype branch June 28, 2024 20:08
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 this pull request may close these issues.

Series.astype is partially unknown.
2 participants