Skip to content

Commit 8f59cd8

Browse files
jbrockmendelroberthdevries
authored andcommitted
REF/TST: collect Index join tests (pandas-dev#32171)
1 parent dbdd349 commit 8f59cd8

16 files changed

+778
-762
lines changed

pandas/tests/indexes/datetimes/test_date_range.py

-11
Original file line numberDiff line numberDiff line change
@@ -759,17 +759,6 @@ def test_constructor(self):
759759
with pytest.raises(TypeError, match=msg):
760760
bdate_range(START, END, periods=10, freq=None)
761761

762-
def test_naive_aware_conflicts(self):
763-
naive = bdate_range(START, END, freq=BDay(), tz=None)
764-
aware = bdate_range(START, END, freq=BDay(), tz="Asia/Hong_Kong")
765-
766-
msg = "tz-naive.*tz-aware"
767-
with pytest.raises(TypeError, match=msg):
768-
naive.join(aware)
769-
770-
with pytest.raises(TypeError, match=msg):
771-
aware.join(naive)
772-
773762
def test_misc(self):
774763
end = datetime(2009, 5, 13)
775764
dr = bdate_range(end=end, periods=20)

pandas/tests/indexes/datetimes/test_datetime.py

+1-37
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,13 @@ def test_stringified_slice_with_tz(self):
100100
df = DataFrame(np.arange(10), index=idx)
101101
df["2013-01-14 23:44:34.437768-05:00":] # no exception here
102102

103-
def test_append_join_nondatetimeindex(self):
103+
def test_append_nondatetimeindex(self):
104104
rng = date_range("1/1/2000", periods=10)
105105
idx = Index(["a", "b", "c", "d"])
106106

107107
result = rng.append(idx)
108108
assert isinstance(result[0], Timestamp)
109109

110-
# it works
111-
rng.join(idx, how="outer")
112-
113110
def test_map(self):
114111
rng = date_range("1/1/2000", periods=10)
115112

@@ -246,25 +243,6 @@ def test_isin(self):
246243
index.isin([index[2], 5]), np.array([False, False, True, False])
247244
)
248245

249-
def test_does_not_convert_mixed_integer(self):
250-
df = tm.makeCustomDataframe(
251-
10,
252-
10,
253-
data_gen_f=lambda *args, **kwargs: randn(),
254-
r_idx_type="i",
255-
c_idx_type="dt",
256-
)
257-
cols = df.columns.join(df.index, how="outer")
258-
joined = cols.join(df.columns)
259-
assert cols.dtype == np.dtype("O")
260-
assert cols.dtype == joined.dtype
261-
tm.assert_numpy_array_equal(cols.values, joined.values)
262-
263-
def test_join_self(self, join_type):
264-
index = date_range("1/1/2000", periods=10)
265-
joined = index.join(index, how=join_type)
266-
assert index is joined
267-
268246
def assert_index_parameters(self, index):
269247
assert index.freq == "40960N"
270248
assert index.inferred_freq == "40960N"
@@ -282,20 +260,6 @@ def test_ns_index(self):
282260
new_index = pd.date_range(start=index[0], end=index[-1], freq=index.freq)
283261
self.assert_index_parameters(new_index)
284262

285-
def test_join_with_period_index(self, join_type):
286-
df = tm.makeCustomDataframe(
287-
10,
288-
10,
289-
data_gen_f=lambda *args: np.random.randint(2),
290-
c_idx_type="p",
291-
r_idx_type="dt",
292-
)
293-
s = df.iloc[:5, 0]
294-
295-
expected = df.columns.astype("O").join(s.index, how=join_type)
296-
result = df.columns.join(s.index, how=join_type)
297-
tm.assert_index_equal(expected, result)
298-
299263
def test_factorize(self):
300264
idx1 = DatetimeIndex(
301265
["2014-01", "2014-01", "2014-02", "2014-02", "2014-03", "2014-03"]
+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
from datetime import datetime
2+
3+
import numpy as np
4+
import pytest
5+
6+
from pandas import DatetimeIndex, Index, Timestamp, date_range, to_datetime
7+
import pandas._testing as tm
8+
9+
from pandas.tseries.offsets import BDay, BMonthEnd
10+
11+
12+
class TestJoin:
13+
def test_does_not_convert_mixed_integer(self):
14+
df = tm.makeCustomDataframe(
15+
10,
16+
10,
17+
data_gen_f=lambda *args, **kwargs: np.random.randn(),
18+
r_idx_type="i",
19+
c_idx_type="dt",
20+
)
21+
cols = df.columns.join(df.index, how="outer")
22+
joined = cols.join(df.columns)
23+
assert cols.dtype == np.dtype("O")
24+
assert cols.dtype == joined.dtype
25+
tm.assert_numpy_array_equal(cols.values, joined.values)
26+
27+
def test_join_self(self, join_type):
28+
index = date_range("1/1/2000", periods=10)
29+
joined = index.join(index, how=join_type)
30+
assert index is joined
31+
32+
def test_join_with_period_index(self, join_type):
33+
df = tm.makeCustomDataframe(
34+
10,
35+
10,
36+
data_gen_f=lambda *args: np.random.randint(2),
37+
c_idx_type="p",
38+
r_idx_type="dt",
39+
)
40+
s = df.iloc[:5, 0]
41+
42+
expected = df.columns.astype("O").join(s.index, how=join_type)
43+
result = df.columns.join(s.index, how=join_type)
44+
tm.assert_index_equal(expected, result)
45+
46+
def test_join_object_index(self):
47+
rng = date_range("1/1/2000", periods=10)
48+
idx = Index(["a", "b", "c", "d"])
49+
50+
result = rng.join(idx, how="outer")
51+
assert isinstance(result[0], Timestamp)
52+
53+
def test_join_utc_convert(self, join_type):
54+
rng = date_range("1/1/2011", periods=100, freq="H", tz="utc")
55+
56+
left = rng.tz_convert("US/Eastern")
57+
right = rng.tz_convert("Europe/Berlin")
58+
59+
result = left.join(left[:-5], how=join_type)
60+
assert isinstance(result, DatetimeIndex)
61+
assert result.tz == left.tz
62+
63+
result = left.join(right[:-5], how=join_type)
64+
assert isinstance(result, DatetimeIndex)
65+
assert result.tz.zone == "UTC"
66+
67+
@pytest.mark.parametrize("sort", [None, False])
68+
def test_datetimeindex_union_join_empty(self, sort):
69+
dti = date_range(start="1/1/2001", end="2/1/2001", freq="D")
70+
empty = Index([])
71+
72+
result = dti.union(empty, sort=sort)
73+
expected = dti.astype("O")
74+
tm.assert_index_equal(result, expected)
75+
76+
result = dti.join(empty)
77+
assert isinstance(result, DatetimeIndex)
78+
tm.assert_index_equal(result, dti)
79+
80+
def test_join_nonunique(self):
81+
idx1 = to_datetime(["2012-11-06 16:00:11.477563", "2012-11-06 16:00:11.477563"])
82+
idx2 = to_datetime(["2012-11-06 15:11:09.006507", "2012-11-06 15:11:09.006507"])
83+
rs = idx1.join(idx2, how="outer")
84+
assert rs.is_monotonic
85+
86+
@pytest.mark.parametrize("freq", ["B", "C"])
87+
def test_outer_join(self, freq):
88+
# should just behave as union
89+
start, end = datetime(2009, 1, 1), datetime(2010, 1, 1)
90+
rng = date_range(start=start, end=end, freq=freq)
91+
92+
# overlapping
93+
left = rng[:10]
94+
right = rng[5:10]
95+
96+
the_join = left.join(right, how="outer")
97+
assert isinstance(the_join, DatetimeIndex)
98+
99+
# non-overlapping, gap in middle
100+
left = rng[:5]
101+
right = rng[10:]
102+
103+
the_join = left.join(right, how="outer")
104+
assert isinstance(the_join, DatetimeIndex)
105+
assert the_join.freq is None
106+
107+
# non-overlapping, no gap
108+
left = rng[:5]
109+
right = rng[5:10]
110+
111+
the_join = left.join(right, how="outer")
112+
assert isinstance(the_join, DatetimeIndex)
113+
114+
# overlapping, but different offset
115+
other = date_range(start, end, freq=BMonthEnd())
116+
117+
the_join = rng.join(other, how="outer")
118+
assert isinstance(the_join, DatetimeIndex)
119+
assert the_join.freq is None
120+
121+
def test_naive_aware_conflicts(self):
122+
start, end = datetime(2009, 1, 1), datetime(2010, 1, 1)
123+
naive = date_range(start, end, freq=BDay(), tz=None)
124+
aware = date_range(start, end, freq=BDay(), tz="Asia/Hong_Kong")
125+
126+
msg = "tz-naive.*tz-aware"
127+
with pytest.raises(TypeError, match=msg):
128+
naive.join(aware)
129+
130+
with pytest.raises(TypeError, match=msg):
131+
aware.join(naive)

pandas/tests/indexes/datetimes/test_setops.py

-84
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
Series,
1515
bdate_range,
1616
date_range,
17-
to_datetime,
1817
)
1918
import pandas._testing as tm
2019

@@ -348,25 +347,6 @@ def test_datetimeindex_diff(self, sort):
348347
dti2 = date_range(freq="Q-JAN", start=datetime(1997, 12, 31), periods=98)
349348
assert len(dti1.difference(dti2, sort)) == 2
350349

351-
@pytest.mark.parametrize("sort", [None, False])
352-
def test_datetimeindex_union_join_empty(self, sort):
353-
dti = date_range(start="1/1/2001", end="2/1/2001", freq="D")
354-
empty = Index([])
355-
356-
result = dti.union(empty, sort=sort)
357-
expected = dti.astype("O")
358-
tm.assert_index_equal(result, expected)
359-
360-
result = dti.join(empty)
361-
assert isinstance(result, DatetimeIndex)
362-
tm.assert_index_equal(result, dti)
363-
364-
def test_join_nonunique(self):
365-
idx1 = to_datetime(["2012-11-06 16:00:11.477563", "2012-11-06 16:00:11.477563"])
366-
idx2 = to_datetime(["2012-11-06 15:11:09.006507", "2012-11-06 15:11:09.006507"])
367-
rs = idx1.join(idx2, how="outer")
368-
assert rs.is_monotonic
369-
370350

371351
class TestBusinessDatetimeIndex:
372352
def setup_method(self, method):
@@ -408,38 +388,6 @@ def test_union(self, sort):
408388
the_union = self.rng.union(rng, sort=sort)
409389
assert isinstance(the_union, DatetimeIndex)
410390

411-
def test_outer_join(self):
412-
# should just behave as union
413-
414-
# overlapping
415-
left = self.rng[:10]
416-
right = self.rng[5:10]
417-
418-
the_join = left.join(right, how="outer")
419-
assert isinstance(the_join, DatetimeIndex)
420-
421-
# non-overlapping, gap in middle
422-
left = self.rng[:5]
423-
right = self.rng[10:]
424-
425-
the_join = left.join(right, how="outer")
426-
assert isinstance(the_join, DatetimeIndex)
427-
assert the_join.freq is None
428-
429-
# non-overlapping, no gap
430-
left = self.rng[:5]
431-
right = self.rng[5:10]
432-
433-
the_join = left.join(right, how="outer")
434-
assert isinstance(the_join, DatetimeIndex)
435-
436-
# overlapping, but different offset
437-
rng = date_range(START, END, freq=BMonthEnd())
438-
439-
the_join = self.rng.join(rng, how="outer")
440-
assert isinstance(the_join, DatetimeIndex)
441-
assert the_join.freq is None
442-
443391
@pytest.mark.parametrize("sort", [None, False])
444392
def test_union_not_cacheable(self, sort):
445393
rng = date_range("1/1/2000", periods=50, freq=Minute())
@@ -556,38 +504,6 @@ def test_union(self, sort):
556504
the_union = self.rng.union(rng, sort=sort)
557505
assert isinstance(the_union, DatetimeIndex)
558506

559-
def test_outer_join(self):
560-
# should just behave as union
561-
562-
# overlapping
563-
left = self.rng[:10]
564-
right = self.rng[5:10]
565-
566-
the_join = left.join(right, how="outer")
567-
assert isinstance(the_join, DatetimeIndex)
568-
569-
# non-overlapping, gap in middle
570-
left = self.rng[:5]
571-
right = self.rng[10:]
572-
573-
the_join = left.join(right, how="outer")
574-
assert isinstance(the_join, DatetimeIndex)
575-
assert the_join.freq is None
576-
577-
# non-overlapping, no gap
578-
left = self.rng[:5]
579-
right = self.rng[5:10]
580-
581-
the_join = left.join(right, how="outer")
582-
assert isinstance(the_join, DatetimeIndex)
583-
584-
# overlapping, but different offset
585-
rng = date_range(START, END, freq=BMonthEnd())
586-
587-
the_join = self.rng.join(rng, how="outer")
588-
assert isinstance(the_join, DatetimeIndex)
589-
assert the_join.freq is None
590-
591507
def test_intersection_bug(self):
592508
# GH #771
593509
a = bdate_range("11/30/2011", "12/31/2011", freq="C")

pandas/tests/indexes/datetimes/test_timezones.py

-14
Original file line numberDiff line numberDiff line change
@@ -804,20 +804,6 @@ def test_dti_tz_constructors(self, tzstr):
804804
# -------------------------------------------------------------
805805
# Unsorted
806806

807-
def test_join_utc_convert(self, join_type):
808-
rng = date_range("1/1/2011", periods=100, freq="H", tz="utc")
809-
810-
left = rng.tz_convert("US/Eastern")
811-
right = rng.tz_convert("Europe/Berlin")
812-
813-
result = left.join(left[:-5], how=join_type)
814-
assert isinstance(result, DatetimeIndex)
815-
assert result.tz == left.tz
816-
817-
result = left.join(right[:-5], how=join_type)
818-
assert isinstance(result, DatetimeIndex)
819-
assert result.tz.zone == "UTC"
820-
821807
@pytest.mark.parametrize(
822808
"dtype",
823809
[None, "datetime64[ns, CET]", "datetime64[ns, EST]", "datetime64[ns, UTC]"],

pandas/tests/indexes/numeric/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)