Skip to content

Commit 69c079f

Browse files
almaleksiajreback
authored andcommittedMar 13, 2018
TST: adding join_types fixture (#20287)
1 parent 53bf291 commit 69c079f

16 files changed

+155
-167
lines changed
 

‎pandas/conftest.py

+8
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,11 @@ def compression_no_zip(request):
8989
def datetime_tz_utc():
9090
from datetime import timezone
9191
return timezone.utc
92+
93+
94+
@pytest.fixture(params=['inner', 'outer', 'left', 'right'])
95+
def join_type(request):
96+
"""
97+
Fixture for trying all types of join operations
98+
"""
99+
return request.param

‎pandas/tests/indexes/common.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -978,11 +978,10 @@ def test_empty(self):
978978
assert not index.empty
979979
assert index[:0].empty
980980

981-
@pytest.mark.parametrize('how', ['outer', 'inner', 'left', 'right'])
982-
def test_join_self_unique(self, how):
981+
def test_join_self_unique(self, join_type):
983982
index = self.create_index()
984983
if index.is_unique:
985-
joined = index.join(index, how=how)
984+
joined = index.join(index, how=join_type)
986985
assert (index == joined).all()
987986

988987
def test_searchsorted_monotonic(self, indices):

‎pandas/tests/indexes/datetimes/test_datetime.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,9 @@ def test_does_not_convert_mixed_integer(self):
250250
assert cols.dtype == joined.dtype
251251
tm.assert_numpy_array_equal(cols.values, joined.values)
252252

253-
@pytest.mark.parametrize('how', ['outer', 'inner', 'left', 'right'])
254-
def test_join_self(self, how):
253+
def test_join_self(self, join_type):
255254
index = date_range('1/1/2000', periods=10)
256-
joined = index.join(index, how=how)
255+
joined = index.join(index, how=join_type)
257256
assert index is joined
258257

259258
def assert_index_parameters(self, index):
@@ -274,8 +273,7 @@ def test_ns_index(self):
274273
freq=index.freq)
275274
self.assert_index_parameters(new_index)
276275

277-
@pytest.mark.parametrize('how', ['left', 'right', 'inner', 'outer'])
278-
def test_join_with_period_index(self, how):
276+
def test_join_with_period_index(self, join_type):
279277
df = tm.makeCustomDataframe(
280278
10, 10, data_gen_f=lambda *args: np.random.randint(2),
281279
c_idx_type='p', r_idx_type='dt')
@@ -284,7 +282,7 @@ def test_join_with_period_index(self, how):
284282
with tm.assert_raises_regex(ValueError,
285283
'can only call with other '
286284
'PeriodIndex-ed objects'):
287-
df.columns.join(s.index, how=how)
285+
df.columns.join(s.index, how=join_type)
288286

289287
def test_factorize(self):
290288
idx1 = DatetimeIndex(['2014-01', '2014-01', '2014-02', '2014-02',

‎pandas/tests/indexes/datetimes/test_timezones.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -700,18 +700,17 @@ def test_dti_tz_constructors(self, tzstr):
700700
# -------------------------------------------------------------
701701
# Unsorted
702702

703-
@pytest.mark.parametrize('how', ['inner', 'outer', 'left', 'right'])
704-
def test_join_utc_convert(self, how):
703+
def test_join_utc_convert(self, join_type):
705704
rng = date_range('1/1/2011', periods=100, freq='H', tz='utc')
706705

707706
left = rng.tz_convert('US/Eastern')
708707
right = rng.tz_convert('Europe/Berlin')
709708

710-
result = left.join(left[:-5], how=how)
709+
result = left.join(left[:-5], how=join_type)
711710
assert isinstance(result, DatetimeIndex)
712711
assert result.tz == left.tz
713712

714-
result = left.join(right[:-5], how=how)
713+
result = left.join(right[:-5], how=join_type)
715714
assert isinstance(result, DatetimeIndex)
716715
assert result.tz.zone == 'UTC'
717716

‎pandas/tests/indexes/period/test_period.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,9 @@ def test_map(self):
532532
exp = Index([x.ordinal for x in index])
533533
tm.assert_index_equal(result, exp)
534534

535-
@pytest.mark.parametrize('how', ['outer', 'inner', 'left', 'right'])
536-
def test_join_self(self, how):
535+
def test_join_self(self, join_type):
537536
index = period_range('1/1/2000', periods=10)
538-
joined = index.join(index, how=how)
537+
joined = index.join(index, how=join_type)
539538
assert index is joined
540539

541540
def test_insert(self):

‎pandas/tests/indexes/period/test_setops.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,18 @@ def _permute(obj):
1414

1515
class TestPeriodIndex(object):
1616

17-
@pytest.mark.parametrize('kind', ['inner', 'outer', 'left', 'right'])
18-
def test_joins(self, kind):
17+
def test_joins(self, join_type):
1918
index = period_range('1/1/2000', '1/20/2000', freq='D')
2019

21-
joined = index.join(index[:-5], how=kind)
20+
joined = index.join(index[:-5], how=join_type)
2221

2322
assert isinstance(joined, PeriodIndex)
2423
assert joined.freq == index.freq
2524

26-
@pytest.mark.parametrize('kind', ['inner', 'outer', 'left', 'right'])
27-
def test_join_self(self, kind):
25+
def test_join_self(self, join_type):
2826
index = period_range('1/1/2000', '1/20/2000', freq='D')
2927

30-
res = index.join(index, how=kind)
28+
res = index.join(index, how=join_type)
3129
assert index is res
3230

3331
def test_join_does_not_recur(self):

‎pandas/tests/indexes/test_base.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -1599,16 +1599,15 @@ def test_slice_keep_name(self):
15991599
idx = Index(['a', 'b'], name='asdf')
16001600
assert idx.name == idx[1:].name
16011601

1602-
def test_join_self(self):
1603-
# instance attributes of the form self.<name>Index
1604-
indices = 'unicode', 'str', 'date', 'int', 'float'
1605-
kinds = 'outer', 'inner', 'left', 'right'
1606-
for index_kind in indices:
1607-
res = getattr(self, '{0}Index'.format(index_kind))
1608-
1609-
for kind in kinds:
1610-
joined = res.join(res, how=kind)
1611-
assert res is joined
1602+
# instance attributes of the form self.<name>Index
1603+
@pytest.mark.parametrize('index_kind',
1604+
['unicode', 'str', 'date', 'int', 'float'])
1605+
def test_join_self(self, join_type, index_kind):
1606+
1607+
res = getattr(self, '{0}Index'.format(index_kind))
1608+
1609+
joined = res.join(res, how=join_type)
1610+
assert res is joined
16121611

16131612
def test_str_attribute(self):
16141613
# GH9068

0 commit comments

Comments
 (0)