Skip to content

Seris and DataFrame creation typing #230

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
Aug 29, 2022

Conversation

amotzop
Copy link
Contributor

@amotzop amotzop commented Aug 26, 2022

  • Cleaned up typing on Series.__new__, DataFrame.__new__.
  • Allowed DataFrame to be created from a scalar and index/columns.

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.

I'm a bit hesitant on these changes, because the type Iterable[Hashable] for index and columns might be too wide and include types that are not acceptable as an index or columns. An example is a set, which will soon be deprecated. There may be others as well.
In addition, the type used in frame.pyi for those arguments in the pandas source is Axes.

Having said that, if you just want to make a change for allowing a Scalar argument to the DataFrame.__new__(), please add a test for that case.

@@ -42,6 +42,7 @@ def test_types_init() -> None:
dtype=np.int8,
copy=True,
)
pd.DataFrame(0, index=[0, 1], columns=[0, 1])
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 do check(assert_type(pd.DataFrame(0, index=[0, 1], columns=[0, 1]), pd.DataFrame), pd.DataFrame) here?

I know we don't have it above, but we're putting this in with all new tests.

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 @amotzop

@Dr-Irv Dr-Irv merged commit 80f561f into pandas-dev:main Aug 29, 2022
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