Skip to content

Conversation

@harshasiddartha
Copy link

@harshasiddartha harshasiddartha commented Oct 30, 2025

Description

This PR removes duplicate test code in test_datetime_index.py for DatetimeIndex relational operations.

Changes

  • Removed duplicate test code that was testing the same functionality with dt_idx when idx already covered the same cases
  • Removed the TODO comment referencing the deduplication opportunity

Issue

Fixes #1460

Rationale

The idx variable is created from pd.Index(data, name="date") where data is a DatetimeIndex. Since data is already a DatetimeIndex, pd.Index(data, name="date") returns a DatetimeIndex. Similarly, dt_idx is created from pd.DatetimeIndex(data, name="date"), which also returns a DatetimeIndex. Both variables are equivalent DatetimeIndex objects, making the duplicate tests redundant.

Test Coverage

Remaining tests (lines 29-36): All relational operations are still fully covered:

  • data[x <= idx] - line 29
  • data[x < idx] - line 30
  • data[x >= idx] - line 31
  • data[x > idx] - line 32
  • data[idx <= x] - line 33
  • data[idx < x] - line 34
  • data[idx >= x] - line 35
  • data[idx > x] - line 36

The removed tests (previously lines 40-48) were identical duplicates using dt_idx instead of idx. Since both idx and dt_idx are DatetimeIndex objects with the same data, all 8 relational operation combinations remain fully tested.

Testing

  • Verified syntax check passes: python3 -m py_compile tests/indexes/test_datetime_index.py
  • The removed tests were already covered by the tests using idx
  • All existing test cases remain intact

Checklist

  • Code follows the project's style guidelines
  • Tests pass (syntax verified)
  • Changes are focused on the issue at hand
  • Commit message follows conventional format
  • Test coverage maintained (all operations still tested)

Remove duplicate test code for DatetimeIndex relational operations.
The tests with dt_idx were duplicating the same tests already performed
with idx, since both are DatetimeIndex objects.

Fixes pandas-dev#1460
check(assert_type(data[idx >= x], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[idx > x], pd.DatetimeIndex), pd.DatetimeIndex)

# TODO: https://github.com/pandas-dev/pandas-stubs/pull/1438#discussion_r2451864012
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @harshasiddartha, since you are deleting some tests can you point out where the other tests are so we make sure that we maintain a good test coverage on the project? Thanks!

@harshasiddartha
Copy link
Author

Hi @loicdiridollou, thank you for the review!

The test coverage is maintained because the removed tests were duplicating the exact same test cases that remain in the file. Here's where the equivalent tests are:

Remaining tests (lines 29-36):
These tests cover all the relational operations using idx which is created from pd.Index(data, name="date"):

  • data[x <= idx] - line 29
  • data[x < idx] - line 30
  • data[x >= idx] - line 31
  • data[x > idx] - line 32
  • data[idx <= x] - line 33
  • data[idx < x] - line 34
  • data[idx >= x] - line 35
  • data[idx > x] - line 36

Why these tests are equivalent:

  • data is a DatetimeIndex (created from pd.date_range() on line 21)
  • idx = pd.Index(data, name="date") returns a DatetimeIndex (type checked on line 27)
  • dt_idx = pd.DatetimeIndex(data, name="date") would also return a DatetimeIndex
  • Since both idx and dt_idx are DatetimeIndex objects, the relational operations produce identical results

The removed tests (previously lines 40-48) were testing the exact same operations with dt_idx instead of idx, so they were redundant duplicates. All 8 relational operation combinations are still covered by the tests on lines 29-36.

Let me know if you'd like me to add any additional clarification or tests!

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.

test: deduplication

2 participants