-
-
Notifications
You must be signed in to change notification settings - Fork 154
GH1409 Improve Series.to_numpy typing #1476
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
base: main
Are you sure you want to change the base?
Conversation
|
Seems like I should be able to restrict some of the types. |
cmp0xff
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment to fix the warning on Windows. Others are just ideas.
| copy: bool = False, | ||
| na_value: Scalar = ..., | ||
| **kwargs: Any, | ||
| ) -> np_1darray[np.integer]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #1462 we are introducing np_1darray_anyint etc., which will be enforced in the stubs in the future. But I think this #1476 will be merged before #1462, and I can make the necessary changes in #1462.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prob let's make a change after, or hold on this one and I will make the changes once you merge the other ones, up to you, fine with both options!
tests/series/test_series.py
Outdated
| ], | ||
| dtype="datetime64[ns]", | ||
| ) | ||
| s7 = pd.Series(pd.PeriodIndex(dates, freq="M")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a conversion function
| s7 = pd.Series(pd.PeriodIndex(dates, freq="M")) | |
| s7 = pd.PeriodIndex(dates, freq="M").to_series() |
tests/series/test_series.py
Outdated
|
|
||
| def test_to_numpy() -> None: | ||
| """Test Series.to_numpy for different types.""" | ||
| s1 = pd.Series(["a", "b", "c"], dtype=str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s1 does not give a hint to the intention of the test. Maybe s_str can help more. Just an idea 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have remained all the variables, clearer indeed.
tests/series/test_series.py
Outdated
| s9 = ( | ||
| pd.Series(pd.period_range(start="2017-01-01", end="2017-02-01", freq="1D")) | ||
| .diff() | ||
| .iloc[1:] | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
| s9 = ( | |
| pd.Series(pd.period_range(start="2017-01-01", end="2017-02-01", freq="1D")) | |
| .diff() | |
| .iloc[1:] | |
| ) | |
| s9 = pd.Series([Day(1)]).to_numpy() |
tests/series/test_series.py
Outdated
| ) | ||
|
|
||
| s11 = pd.Series( | ||
| [datetime.datetime.now().date(), datetime.datetime.now().date()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
datetime.now will eventually be caught by DTZ005 in the future. But it is fine for now.
to_numpydoes not reflectS1inpd.Series[S1]#1409assert_type()to assert the type of any return valueShould address the most general case for each type, happy to improve with the dtype parameter, from experience this is not used a lot but let me know, good to restrict some of those types.