GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TYP: reject complex ordering for Series and Index by cmp0xff · Pull Request #2016 · pandas-dev/pandas-stubs

Conversation

@cmp0xff

@cmp0xff cmp0xff commented Oct 21, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • 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.

All reactions
Dr-Irv
Dr-Irv reviewed Oct 21, 2026
View reviewed changes

@Dr-Irv Dr-Irv left a comment

Copy link
Copy Markdown
Collaborator

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.

All reactions
@cmp0xff cmp0xff changed the title TST: remove invalid complex ordering tests TYP: reject complex ordering for Series and Index Oct 21, 2026
@cmp0xff

cmp0xff commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@Dr-Irv thank you, this one may take some time to finish.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cmp0xff cmp0xff mentioned this pull request Oct 21, 2026
TYP: comparison operand precision after rejecting complex ordering #2024
Open
@cmp0xff
cmp0xff force-pushed the remove-complex-ordering-tests branch 4 times, most recently from dbb0603 to eea0ac7 Compare October 21, 2026 21:32
@cmp0xff DeepSeek V4.1 Flash 1017
TYP: reject complex ordering for Series and Index
5ffe079
Co-authored-by: DeepSeek V4.1 Flash 1017 <[email protected]>
@cmp0xff
cmp0xff force-pushed the remove-complex-ordering-tests branch from eea0ac7 to 5ffe079 Compare October 21, 2026 21:47
@cmp0xff
cmp0xff marked this pull request as ready for review October 21, 2026 21:51
@cmp0xff
cmp0xff requested a review from Dr-Irv October 21, 2026 21:51
Dr-Irv
Dr-Irv requested changes Oct 22, 2026
View reviewed changes

@Dr-Irv Dr-Irv left a comment

Copy link
Copy Markdown
Collaborator

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.

All reactions
Comment thread pandas-stubs/core/indexes/interval.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/indexes/datetimeindex/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/indexes/int/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/indexes/interval/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/bool/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/object/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/str/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/str/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/timedelta/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/timestamp/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

cmp0xff and others added 2 commits October 22, 2026 21:18
@cmp0xff @codex
TYP: constrain Series comparison methods and expand tests
a5181c1
Co-Authored-By: Codex <[email protected]>
@cmp0xff @codex
TYP: align Series ordering operators and methods
b6ab27f
Co-Authored-By: gpt-6 <[email protected]>
cmp0xff
cmp0xff commented Oct 23, 2026
View reviewed changes

@cmp0xff cmp0xff left a comment

Copy link
Copy Markdown
Contributor Author

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.

All reactions
Comment thread pandas-stubs/core/indexes/interval.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/indexes/datetimeindex/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/indexes/int/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/int/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/str/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/bytes/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/float/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/str/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/timedelta/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/timestamp/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Dr-Irv

Dr-Irv commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

ping me when you want me to review again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cmp0xff
cmp0xff requested a review from Dr-Irv October 23, 2026 13:53
@cmp0xff

cmp0xff commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Yep it is ready, sorry I forgot to ping

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Dr-Irv
Dr-Irv requested changes Oct 23, 2026
View reviewed changes

@Dr-Irv Dr-Irv left a comment

Copy link
Copy Markdown
Collaborator

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:

  1. 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.
  2. 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.

All reactions
Comment thread tests/indexes/categoricalindex/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/indexes/complex/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/str/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/str/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/timedelta/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/timestamp/test_relops.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/series/test_series.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

cmp0xff and others added 2 commits October 27, 2026 15:37
@cmp0xff @codex
TST: cover string-Series Index rejection and inferred inputs
7e20050
Co-authored-by: Codex <[email protected]>
@cmp0xff @claude
TST: drop redundant input assert_type calls
8d369bf
Co-authored-by: claude-sonnet-5-5 <[email protected]>
@cmp0xff
cmp0xff requested a review from Dr-Irv October 27, 2026 22:16
@cmp0xff cmp0xff mentioned this pull request Oct 28, 2026
BLD: update to pandas 3.1.0 and adapt stubs and tests #2036
Merged
2 tasks done
Dr-Irv
Dr-Irv approved these changes Oct 28, 2026
View reviewed changes

@Dr-Irv Dr-Irv left a comment

Copy link
Copy Markdown
Collaborator

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.

thanks @cmp0xff

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cmp0xff reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@Dr-Irv
Dr-Irv merged commit 0bdb355 into pandas-dev:main Oct 28, 2026
17 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@cmp0xff
cmp0xff deleted the remove-complex-ordering-tests branch October 28, 2026 19:44
@cmp0xff cmp0xff mentioned this pull request Nov 9, 2026
TYP: Accept scalar operands in DataFrame comparisons #2090
Merged
4 tasks done
This was referenced Nov 9, 2026
TYP: Accept real ordering operands for Index[float] #2092
Merged
TYP: Align DataFrame comparison operator operands with named methods #2095
Closed
@hector2394 hector2394 mentioned this pull request Nov 12, 2026
TYP: Restrict DataFrame ordering operator operands #2106
Merged
4 tasks done
This was referenced Nov 17, 2026
TYP: generalize comparison operators via SupportsS2* protocols cmp0xff/pandas-stubs#32
Closed
TYP: precise comparison operands and dtype-split relop tests for Series and Index cmp0xff/pandas-stubs#33
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Dr-Irv Dr-Irv Dr-Irv approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@cmp0xff @Dr-Irv
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.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.