Skip to content

test: deduplication #1460

@cmp0xff

Description

@cmp0xff

After #1456, there is an issue that can be improved in the tests.

The following two parts are duplicated, because data, idx and dt_idx are all DatetimeIndexes. The second part can be removed. Also see the link in TODO.

idx = check(
assert_type(pd.Index(data, name="date"), pd.DatetimeIndex), pd.DatetimeIndex
)
check(assert_type(data[x <= idx], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[x < idx], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[x >= idx], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[x > idx], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[idx <= x], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[idx < x], pd.DatetimeIndex), pd.DatetimeIndex)
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
# Can this be de-duplicated?
dt_idx = pd.DatetimeIndex(data, name="date")
check(assert_type(data[x <= dt_idx], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[x < dt_idx], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[x >= dt_idx], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[x > dt_idx], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[dt_idx <= x], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[dt_idx < x], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[dt_idx >= x], pd.DatetimeIndex), pd.DatetimeIndex)
check(assert_type(data[dt_idx > x], pd.DatetimeIndex), pd.DatetimeIndex)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Testingpandas testing functions or related to the test suitegood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions