Skip to content

Add check assert_type to tests for frame.py and add __new__ method for DatetimeIndex #1313

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

loicdiridollou
Copy link
Member

Cleaned up tests in tests/test_frame.py as there was no check assert_type in many places.
Added a new method for DatetimeIndex since it would not instantiate to DatetimeIndex but to Series[int].

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

pd.DatetimeIndex(data=df["A"], tz=None, ambiguous="NaT", copy=True),

check(
assert_type(
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the reason I added the __new__ to datetimes.pyi, prob worth putting a test in the relevant test file, please let me know if so.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, actually we should probably move that test there.

Actually, looking at this function test_types_regressions(), I think the various tests in there should be moved to the appropriate files. That function was created before we took over the repo, so splitting the tests here to the right files would be the right thing to do.

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.

thanks for doing this. Caught a few things that we should clean up as a result.

Comment on lines +60 to +72
@classmethod
def __new__(
cls,
data: AxesData | Series,
freq: Frequency = ...,
tz: TimeZones = ...,
ambiguous: str = ...,
dayfirst: bool = ...,
yearfirst: bool = ...,
dtype: Dtype = ...,
copy: bool = ...,
name: Hashable = ...,
) -> Self: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can just do this by making this the __init__() method, (returning None).

So in line 50, just modify data to be data: AxesData | Series

Comment on lines +302 to 304
# TODO the below should pass
# check(assert_type(df.iat[0, 0], Scalar), np.integer)
df.iat[0, 0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you fix the declaration of iat in frame.pyi ?

Comment on lines +312 to 314
# TODO the below should pass
# check(assert_type(df.at[0, "col1"], Scalar), np.integer)
df.at[0, "col1"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

same comment - can you fix the declaration of at() in frame.pyi ?

df.cumsum()
df.sum(axis=0)
check(assert_type(df.cumsum(), pd.DataFrame), pd.DataFrame)
check(assert_type(df.sum(axis=0), pd.Series), pd.Series)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is an odd test. I wonder if it should be df.cumsum(axis=0), since the name of the function is test_types_cumsum()

Comment on lines +1038 to +1039
check(assert_type(df.idxmin(), pd.Series), pd.Series)
check(assert_type(df.idxmin(axis=0), pd.Series), pd.Series)
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should be Series[int]. Can you fix the declaration in frame.pyi ?

Comment on lines +1044 to +1045
check(assert_type(df.idxmax(), pd.Series), pd.Series)
check(assert_type(df.idxmax(axis=0), pd.Series), pd.Series)
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 Series[int]

pd.DatetimeIndex(data=df["A"], tz=None, ambiguous="NaT", copy=True),

check(
assert_type(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, actually we should probably move that test there.

Actually, looking at this function test_types_regressions(), I think the various tests in there should be moved to the appropriate files. That function was created before we took over the repo, so splitting the tests here to the right files would be the right thing to do.

Comment on lines +2980 to 2981
result: int = 10
result = df["x"].max()
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can delete these 2 lines.

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.

2 participants