GeezerVison is showing github.com — TYP: reject complex ordering for Series and Index by cmp0xff · Pull Request #2016 · pandas-dev/pandas-stubs
Conversation
cmp0xff
commented
Oct 21, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
-
Reject complex ordering and align Series ordering operators with lt/le/gt/ge.
-
Organize comparison tests by dtype, add string-Series/Index rejection, and verify inferred test inputs.
-
Document cross-container test ownership; track the remaining matrix in TYP: comparison operand precision after rejecting complex ordering #2024.
-
Tests added using assert_type() and TYPE_CHECKING_INVALID_USAGE.
-
AI development followed AGENTS.md.
-
Focused runtime tests (29) and all four checker runs passed.
-
poetry run poe test_all passed.
AI Implementation Plan
Motivation
Complex ordering is deprecated in pandas and should be rejected at type-check time. The existing comparison tests were concentrated in tests/series/test_series.py and tests/indexes/test_datetime_index.py, which did not follow the dtype-grouped arithmetic test layout.
Implementation
- Constrain
self through Iterable[SupportsDunderLT[...]] and the corresponding LE/GT/GE protocols for Index and Series ordering operators.
- Use
S1 as the protocol operand for Series; use Any for Index because IntervalIndex overrides compare generic IntervalT values that checkers cannot prove compatible with S1.
- Apply the same constraints to the
Series.lt, Series.le, Series.gt, and Series.ge overloads.
- Keep
self: Iterable[float] for the real-number Series comparison overloads; it covers bool/int/float and preserves mixed numeric comparisons.
- Add
OrderableArrayLike and ScalarArrayIndexSeriesComparison in pandas-stubs/_stubs_only/__init__.pyi.
- Move the existing scalar comparison coverage into
tests/series/<dtype>/test_relops.py.
- Move the existing index comparison coverage into
tests/indexes/int/test_relops.py and tests/indexes/datetimeindex/test_relops.py.
- Add focused complex rejection tests in
tests/series/complex/test_relops.py and tests/indexes/complex/test_relops.py.
- Leave
tests/series/test_agg.py and the pytest_warns_complex_pandas4 helper unchanged, preserving the median coverage from TST: handle complex-ordering warnings in Series tests #1998.
Review follow-up
- Use
np_ndarray aliases instead of npt.NDArray in the stubs and tests.
- Remove the redundant
date member from ScalarArrayIndexSeriesComparison; S2 already covers date when appropriate.
- Remove the
pd.Series ordering overloads from IntervalIndex; Series-side comparison signatures already accept Index[S1].
- Rename negative-test variables to describe the operator and operand, e.g.
_lt_f and _idx_lt.
- Keep
IndexReal and SeriesReal unchanged; Iterable[float] is used only for the comparison receiver, where structural iteration is intended.
- Trim the test changes to migrated coverage plus complex rejection; the expanded matrix belongs in TYP: comparison operand precision after rejecting complex ordering #2024.
Verification
poetry run poe test_all passed: mypy, pyright, pyrefly, ty, pytest, pre-commit, built stubs, and installed-stub checks.
- Current runtime suite: 3496 passed, 6 skipped.
Latest review follow-up
- Add string-Series/float-Index rejection for all four operators in both directions and all four named methods.
- Take the Series from a DataFrame column (
left = df["x"]) and build temporal ndarrays with typed NumPy constructors; retain ns/day units.
- Drop five redundant bare
assert_type calls on inputs (they failed mypy on Python 3.11, where older NumPy infers ndarray[datetime64[Any]]); the unused np_ndarray_dt/np_ndarray_td imports go with them.
- Document higher-tier test ownership; keep fixture and deliberate base-Index annotations and omit redundant complex-Index reversals.
- Expand TYP: comparison operand precision after rejecting complex ordering #2024 into a matrix for all 23 dtype directories with valid/invalid families, direction/method coverage and evidence.
- No public API or stub-signature changes in this follow-up.
- Focused runtime tests (29) and all four checker runs passed. The final full run passed.
Caveats and follow-up
- NumPy's reflected operators still allow some complex ndarray comparisons; direct pandas methods are tested for those cases.
- Extension arrays and
np.object_ arrays remain opaque to the complex check.
- Cross-kind operand precision, ordered categorical
Series, Series[object] / Index[object] ordering, and the removed full matrix are tracked in TYP: comparison operand precision after rejecting complex ordering #2024.
- DataFrame comparisons remain out of scope.
Co-authored-by: Codex [email protected]
Co-authored-by: claude-sonnet-5-5 [email protected]
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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'm good with this. Let me know when you change it from draft status and I'll approve and merge
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
cmp0xff
changed the title
TST: remove invalid complex ordering tests
TYP: reject complex ordering for Series and Index
Oct 21, 2026
|
@Dr-Irv thank you, this one may take some time to finish.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 started adding comments for specific tests, but there is a general issue here.
In the relops tests for complex, you are "complete" in the sense that you compare the Series[complex] against various scalar types, but also against various sequence types (lists, numpy arrays, index, series (maybe)). So I think for the other tests for relops of Series[some-scalar-type] and Index[some-scalar-type], you need to be more complete in the tests.
This might then change the approach in the stubs.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
My idea was to cover existing tested cases before, and reject some comparisons with complex. New tests would be postponed to #2024 , so that the PR will not be gigantic.
Now I also added a few tests proposed in your comments.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
ping me when you want me to review again
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Yep it is ready, sorry I forgot to ping
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
A couple of global notes:
- In #2024 I think there should be a more detailed list of what tests (and possible overloads) need to be added. I think we are missing a number of negative tests, and maybe even positive ones. It seems to me that for each type, we want to test relops against valid AND invalid scalars, sequences, numpy arrays, Index, Series. So each
test_relops.py file should eventually have 10 functions in it. It would be useful to have a tracker in #2024 to indicate which tests need to be added for completeness.
- Consider something like the tests for comparing a
Series to Index. I think the way you have things structured is that those would be in tests/series/* . That means we have to remember the hierarchy. But if I just look at one test file for indexes, it is natural to ask "why aren't there comparisons to Series here"? So I think it would be best if we don't depend on the hierarchy for the tests. In other words, we test Series to Index comparisons in both tests/series/* and tests/index/* . This is just more complete to make sure we haven't missed anything.
Don't have to do (2) in this PR. Could track it in #2024 or in another issue. It relates to my comment in (1) about having 10 functions in each test_relops.py file.
And when you start adding those tests/overloads, do it more incrementally, e.g., one subtype at a time, so it becomes easier to review.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
cmp0xff reacted with rocket emoji
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 9, 2026
This was referenced Nov 17, 2026
Reviewers
Dr-Irv
Dr-Irv approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|