Skip to content

Commit e186d7c

Browse files
mcgeestocksim-vinicius
authored and
im-vinicius
committed
TST: Adds test for date_range index comparison (pandas-dev#53406)
TST: adds test for range_range index comparison
1 parent 19801b8 commit e186d7c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pandas/tests/indexes/datetimes/test_date_range.py

+30
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
import pandas as pd
2828
from pandas import (
29+
DataFrame,
2930
DatetimeIndex,
31+
Series,
3032
Timedelta,
3133
Timestamp,
3234
bdate_range,
@@ -355,6 +357,34 @@ def test_date_range_convenience_periods(self):
355357
)
356358
tm.assert_index_equal(result, expected)
357359

360+
def test_date_range_index_comparison(self):
361+
rng = date_range("2011-01-01", periods=3, tz="US/Eastern")
362+
df = Series(rng).to_frame()
363+
arr = np.array([rng.to_list()]).T
364+
arr2 = np.array([rng]).T
365+
366+
with pytest.raises(ValueError, match="Unable to coerce to Series"):
367+
rng == df
368+
369+
with pytest.raises(ValueError, match="Unable to coerce to Series"):
370+
df == rng
371+
372+
expected = DataFrame([True, True, True])
373+
374+
results = df == arr2
375+
tm.assert_frame_equal(results, expected)
376+
377+
expected = Series([True, True, True], name=0)
378+
379+
results = df[0] == arr2[:, 0]
380+
tm.assert_series_equal(results, expected)
381+
382+
expected = np.array(
383+
[[True, False, False], [False, True, False], [False, False, True]]
384+
)
385+
results = rng == arr
386+
tm.assert_numpy_array_equal(results, expected)
387+
358388
@pytest.mark.parametrize(
359389
"start,end,result_tz",
360390
[

0 commit comments

Comments
 (0)