Skip to content

TST: adding join_types fixture #20287

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
Mar 13, 2018
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,11 @@ def compression_no_zip(request):
def datetime_tz_utc():
from datetime import timezone
return timezone.utc


@pytest.fixture(params=['inner', 'outer', 'left', 'right'])
def join_type(request):
"""
Fixture for trying all types of join operations
"""
return request.param
5 changes: 2 additions & 3 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,11 +978,10 @@ def test_empty(self):
assert not index.empty
assert index[:0].empty

@pytest.mark.parametrize('how', ['outer', 'inner', 'left', 'right'])
def test_join_self_unique(self, how):
def test_join_self_unique(self, join_type):
index = self.create_index()
if index.is_unique:
joined = index.join(index, how=how)
joined = index.join(index, how=join_type)
assert (index == joined).all()

def test_searchsorted_monotonic(self, indices):
Expand Down
10 changes: 4 additions & 6 deletions pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,9 @@ def test_does_not_convert_mixed_integer(self):
assert cols.dtype == joined.dtype
tm.assert_numpy_array_equal(cols.values, joined.values)

@pytest.mark.parametrize('how', ['outer', 'inner', 'left', 'right'])
def test_join_self(self, how):
def test_join_self(self, join_type):
index = date_range('1/1/2000', periods=10)
joined = index.join(index, how=how)
joined = index.join(index, how=join_type)
assert index is joined

def assert_index_parameters(self, index):
Expand All @@ -274,8 +273,7 @@ def test_ns_index(self):
freq=index.freq)
self.assert_index_parameters(new_index)

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

def test_factorize(self):
idx1 = DatetimeIndex(['2014-01', '2014-01', '2014-02', '2014-02',
Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/indexes/datetimes/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,18 +700,17 @@ def test_dti_tz_constructors(self, tzstr):
# -------------------------------------------------------------
# Unsorted

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

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

result = left.join(left[:-5], how=how)
result = left.join(left[:-5], how=join_type)
assert isinstance(result, DatetimeIndex)
assert result.tz == left.tz

result = left.join(right[:-5], how=how)
result = left.join(right[:-5], how=join_type)
assert isinstance(result, DatetimeIndex)
assert result.tz.zone == 'UTC'

Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/indexes/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,9 @@ def test_map(self):
exp = Index([x.ordinal for x in index])
tm.assert_index_equal(result, exp)

@pytest.mark.parametrize('how', ['outer', 'inner', 'left', 'right'])
def test_join_self(self, how):
def test_join_self(self, join_type):
index = period_range('1/1/2000', periods=10)
joined = index.join(index, how=how)
joined = index.join(index, how=join_type)
assert index is joined

def test_insert(self):
Expand Down
10 changes: 4 additions & 6 deletions pandas/tests/indexes/period/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ def _permute(obj):

class TestPeriodIndex(object):

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

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

assert isinstance(joined, PeriodIndex)
assert joined.freq == index.freq

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

res = index.join(index, how=kind)
res = index.join(index, how=join_type)
assert index is res

def test_join_does_not_recur(self):
Expand Down
19 changes: 9 additions & 10 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1599,16 +1599,15 @@ def test_slice_keep_name(self):
idx = Index(['a', 'b'], name='asdf')
assert idx.name == idx[1:].name

def test_join_self(self):
# instance attributes of the form self.<name>Index
indices = 'unicode', 'str', 'date', 'int', 'float'
kinds = 'outer', 'inner', 'left', 'right'
for index_kind in indices:
res = getattr(self, '{0}Index'.format(index_kind))

for kind in kinds:
joined = res.join(res, how=kind)
assert res is joined
# instance attributes of the form self.<name>Index
@pytest.mark.parametrize('index_kind',
['unicode', 'str', 'date', 'int', 'float'])
def test_join_self(self, join_type, index_kind):

res = getattr(self, '{0}Index'.format(index_kind))

joined = res.join(res, how=join_type)
assert res is joined

def test_str_attribute(self):
# GH9068
Expand Down
Loading