-
-
Notifications
You must be signed in to change notification settings - Fork 157
feat(index): append #1282
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
Dr-Irv
merged 11 commits into
pandas-dev:main
from
cmp0xff:feature/cmp0xff/index-append
Jul 30, 2025
Merged
feat(index): append #1282
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
390e5d9
feat(index): append
cmp0xff 3a34057
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1282#di…
cmp0xff 45e0ad3
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1282/fi…
cmp0xff 6c8ba76
fix(pyrefly): ignore
cmp0xff 3844062
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1282#di…
cmp0xff ac0857b
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1282#di…
cmp0xff 67e6bde
fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1282#di…
cmp0xff fa3c401
fix: Sequence[Index] instead of Sequence
cmp0xff d7a538d
fix(comment): avoid union types https://github.com/pandas-dev/pandas-…
cmp0xff fe5f1a9
chore: https://github.com/pandas-dev/pandas-stubs/pull/1282#discussio…
cmp0xff 1c75df6
fix: constraint instead of bound to get rid of Any https://github.com…
cmp0xff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(comment): #1282 (comment)
- Loading branch information
commit 3a3405797429eb262949b6b9d3c7e6d6a0d301bd
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
it might be nicer here to have a second S1 here as the resulting Index can contain a mix of different types.
def append(self, other: Index[S2] | Sequence[Index[S2]]) -> Index[S1 | S2]: ...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.
45e0ad3, but this one works less well.
mypyis not happy withIndex[int].append(Index[int | str])and givesIndex[Any]pyrightis not happy withIndex[int | str].append([Index[int], Index[str]])and givesIndex[int | Any]. In particular, the typing for[Index[int], Index[str]]seems to belist[Index[int] | Index[str]], instead oflist[Index[int | 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.
While that is annoying for testing on the CI, I think that is the safer choice for user: rather expect a wider type that includes
Anythan suggesting it is a narrower type. This needs input from @Dr-Irv.If
S1andS2were covariant, it seems to work for at least pyright in a simple toy example (but they are invariant)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.
Hi, I am new to covariance / contravariance, but I read PEP484 (covariance-and-contravariance) and it says
covariantis for classes, not for functions, where the latter case is prohibited. In your example,S1is find, but notS2. Could you help me and explain a bit? Thanks.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.
We can't change
S1to be covariant. While the following is not exactly what we like to have, it is probably the closest we can get (but it doesn't work with mypy, unless the caller casts).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.
Hi, I ran the script myself. In the most complicated case, I see
Index[int | str] | Index[int] | Index[str]. To be honest, as a user I would rather seeIndex[Unknown], because it's simpler, and in both cases I would probably still need a manualcast. Nevertheless, 3844062