Skip to content

TST: Adds test for date_range index comparison #53406

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
merged 1 commit into from
May 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pandas/tests/indexes/datetimes/test_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

import pandas as pd
from pandas import (
DataFrame,
DatetimeIndex,
Series,
Timedelta,
Timestamp,
bdate_range,
Expand Down Expand Up @@ -355,6 +357,34 @@ def test_date_range_convenience_periods(self):
)
tm.assert_index_equal(result, expected)

def test_date_range_index_comparison(self):
rng = date_range("2011-01-01", periods=3, tz="US/Eastern")
df = Series(rng).to_frame()
arr = np.array([rng.to_list()]).T
arr2 = np.array([rng]).T

with pytest.raises(ValueError, match="Unable to coerce to Series"):
rng == df

with pytest.raises(ValueError, match="Unable to coerce to Series"):
df == rng

expected = DataFrame([True, True, True])

results = df == arr2
tm.assert_frame_equal(results, expected)

expected = Series([True, True, True], name=0)

results = df[0] == arr2[:, 0]
tm.assert_series_equal(results, expected)

expected = np.array(
[[True, False, False], [False, True, False], [False, False, True]]
)
results = rng == arr
tm.assert_numpy_array_equal(results, expected)

@pytest.mark.parametrize(
"start,end,result_tz",
[
Expand Down