-
-
Notifications
You must be signed in to change notification settings - Fork 157
ENH: Make DataFrame generic
#1566
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,6 +117,8 @@ from pandas._typing import ( | |
| IndexingInt, | ||
| IndexKeyFunc, | ||
| IndexLabel, | ||
| IndexStrT0, | ||
| IndexT0, | ||
| IndexType, | ||
| InterpolateOptions, | ||
| IntervalClosedType, | ||
|
|
@@ -378,10 +380,19 @@ _AstypeArgExt: TypeAlias = ( | |
| ) | ||
| _AstypeArgExtList: TypeAlias = _AstypeArgExt | list[_AstypeArgExt] | ||
|
|
||
| class DataFrame(NDFrame, OpsMixin, _GetItemHack): | ||
| class DataFrame(NDFrame, OpsMixin, _GetItemHack, Generic[IndexT0, IndexStrT0]): | ||
|
|
||
| __hash__: ClassVar[None] # type: ignore[assignment] # pyright: ignore[reportIncompatibleMethodOverride] | ||
|
|
||
| @overload | ||
| def __new__( | ||
| cls, | ||
| data: DataFrame[IndexT0, IndexStrT0], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not totally sure if this is gonna break a lot of things, by default DataFrame will have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is copying another DataFrame, I suppose, so nothing is changed. Will add tests later.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you create a As for now I just want to show a prototype of what can happen. |
||
| index: None = None, | ||
| columns: None = None, | ||
| dtype: Dtype | None = None, | ||
| copy: _bool | None = None, | ||
| ) -> DataFrame[IndexT0, IndexStrT0]: ... | ||
| @overload | ||
| def __new__( | ||
| cls, | ||
|
|
@@ -398,6 +409,15 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): | |
| copy: _bool | None = None, | ||
| ) -> Self: ... | ||
| @overload | ||
| def __new__( | ||
| cls, | ||
| data: Scalar, | ||
| index: IndexT0, | ||
| columns: IndexStrT0, | ||
| dtype: Dtype | None = None, | ||
| copy: _bool | None = None, | ||
| ) -> DataFrame[IndexT0, IndexStrT0]: ... | ||
| @overload | ||
| def __new__( | ||
| cls, | ||
| data: Scalar, | ||
|
|
@@ -1898,7 +1918,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): | |
| @property | ||
| def at(self) -> _AtIndexerFrame: ... | ||
| @property | ||
| def columns(self) -> Index[str]: ... | ||
| def columns(self) -> IndexStrT0: ... | ||
| @columns.setter # setter needs to be right next to getter; otherwise mypy complains | ||
| def columns( | ||
| self, cols: AnyArrayLike | SequenceNotStr[Hashable] | tuple[Hashable, ...] | ||
|
|
@@ -1912,7 +1932,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): | |
| @property | ||
| def iloc(self) -> _iLocIndexerFrame[Self]: ... | ||
| @property | ||
| def index(self) -> Index: ... | ||
| def index(self) -> IndexT0: ... | ||
| @index.setter | ||
| def index( | ||
| self, idx: AnyArrayLike | SequenceNotStr[Hashable] | tuple[Hashable, ...] | ||
|
|
@@ -2289,7 +2309,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): | |
| inplace: Literal[False] = False, | ||
| **kwargs: Any, | ||
| ) -> Self: ... | ||
| def keys(self) -> Index: ... | ||
| def keys(self) -> IndexStrT0: ... | ||
| def kurt( | ||
| self, | ||
| axis: Axis | None = ..., | ||
|
|
||
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.
Shouldn't the default be RangeIndex here?
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.
For
df.columnswe somehow have a preference for it beingIndex[str], seedef columns(self) -> Index[str]: ...in the old code. That's the reason.