Skip to content
Snippets Groups Projects
Commit 4f3855e6 authored by Bert Palm's avatar Bert Palm 🎇
Browse files

started test aloc

parent 30da8d83
No related branches found
No related tags found
No related merge requests found
......@@ -41,5 +41,5 @@ def test__setitem_single(dios_aligned, idxer, exp):
@pytest.mark.parametrize('idxer', BASIC_INDEXER_FAIL)
def test__setitem__fail(dios_aligned, idxer):
with pytest.raises((ValueError, KeyError, IndexError)):
dios_aligned[idxer]
dios_aligned[idxer] = 99
# from .test_setup import *
# from pandas.core.dtypes.common import is_scalar
#
# unal1 = pd.Series(range(10), index=range(10))
# unal2 = pd.Series(range(5, 10), index=range(5, 10))
# unal3 = pd.Series(range(1, 30, 2), index=range(1, 30, 2))
# unal4 = pd.Series(np.linspace(7, 13, 9), index=range(3, 12))
# unal1.name, unal2.name, unal3.name, unal4.name = 'a', 'b', 'c', 'd'
# d1 = DictOfSeries(data=dict(a=unal1.copy(), b=unal2.copy(), c=unal3.copy(), d=unal4.copy()))
#
#
# @pytest.mark.parametrize(('idxer', 'exp'), [('a', unal1), ('c', unal3)])
# def test__getitem_single(idxer, exp):
# a = d1[idxer]
# b = d1.loc[:, idxer]
# assert isinstance(a, pd.Series)
# assert isinstance(b, pd.Series)
# assert (a == exp).all()
# assert (b == exp).all()
#
#
# @pytest.mark.parametrize(('idxer', 'exp'), [((1, 'a'), unal1), ((3, 'c'), unal3)])
# def test__getitem_scalar_loc(idxer, exp):
# a = d1.loc[idxer]
# assert is_scalar(a)
# assert a == exp.loc[idxer[0]]
#
#
# @pytest.mark.parametrize(('idxer', 'exp'), [(0, unal1), (1, unal2), (2, unal3), (3, unal4),
# (-1, unal4), (-2, unal3), (-3, unal2), (-4, unal1)])
# def test__getitem_single_iloc(idxer, exp):
# a = d1.iloc[:, idxer]
# assert isinstance(a, pd.Series)
# assert (a == exp).all()
#
#
# @pytest.mark.parametrize(('idxer', 'exp'), [((1, 0), unal1), ((3, -2), unal3), ((-1, -1), unal4)])
# def test__getitem_scalar_iloc(idxer, exp):
# a = d1.iloc[idxer]
# assert is_scalar(a)
# assert a == exp.iloc[idxer[0]]
#
#
# @pytest.mark.parametrize('idxer', ['x', '2', 1000, None, ])
# def test__getitem_single_fail(idxer):
# with pytest.raises((KeyError, ValueError)):
# a = d1[idxer]
# print(idxer, a)
#
#
# @pytest.mark.parametrize('idxer', ['x', '2', 1, None, ])
# def test__getitem_single_loc_fail(idxer):
# with pytest.raises((KeyError, TypeError)):
# a = d1.loc[:, idxer]
#
#
# @pytest.mark.parametrize('idxer', [-5, 99, 'a', '2', None, ])
# def test__getitem_single_iloc_fail(idxer):
# with pytest.raises((KeyError, IndexError, TypeError)):
# a = d1.iloc[:, idxer]
#
#
# @pytest.mark.parametrize('idxer', INDEXERS_NOBOOL)
# def test__getitem_(idxer):
# d = d1[idxer]
# assert isinstance(d, DictOfSeries)
#
#
# @pytest.mark.parametrize('idxer', FAIL_INDEXERS)
# def test__getitem_fail(idxer):
# with pytest.raises((ValueError, KeyError)):
# d1[idxer]
#
from .test_setup import *
from pandas.core.dtypes.common import is_scalar
@pytest.mark.parametrize(('idxer', 'exp'), [('a', s1), ('c', s3), ('x', pd.Series())])
def test__getitem_aloc_singleCol(dios_aligned, idxer, exp):
di = dios_aligned.aloc[:, idxer]
assert isinstance(di, pd.Series)
assert (di == exp).all()
@pytest.mark.parametrize(('idxer', 'exp'), [((1, 'a'), s1), ((3, 'c'), s3)])
def test__getitem_aloc_singleRow_singleCol(dios_aligned, idxer, exp):
di = dios_aligned.aloc[idxer]
assert is_scalar(di)
assert di == exp.aloc[idxer[0]]
@pytest.mark.parametrize('idxer', ['x', '2', 1, None, ])
def test__getitem_aloc_singleCol_fail(dios_aligned, idxer):
with pytest.raises((KeyError, TypeError)):
di = dios_aligned.aloc[:, idxer]
@pytest.mark.parametrize('idxerL', R_LOC_INDEXER)
@pytest.mark.parametrize('idxerR', C_LOC_INDEXER)
def test__getitem__aloc(dios_aligned, idxerL, idxerR):
di = dios_aligned.copy().aloc[idxerL, idxerR]
exp = dios_aligned.copy().loc[idxerL, idxerR]
assert isinstance(di, DictOfSeries)
assert (di == exp).all(None)
# #############################
# __SETITEM__
@pytest.mark.parametrize(('idxer', 'exp'), [(slice(None), [s1 == s1, s2 == s2, s3 == s3, s4 == s4]),
(C_BLIST, [s1 == s1, s2 != s2, s3 != s3, s4 == s4]),
])
def test__setitem_aloc_singleCol(dios_aligned, idxer, exp):
di = dios_aligned.copy()
di.aloc[:, idxer] = 99
for i, c in enumerate(di):
assert ((di[c] == 99) == exp[i]).all()
VALS = [99,
pd.Series(range(4, 10), index=range(4, 10)),
]
@pytest.mark.parametrize('idxerL', R_LOC_INDEXER)
@pytest.mark.parametrize('idxerR', C_LOC_INDEXER)
@pytest.mark.parametrize('val', VALS)
def test__setitem__aloc(dios_aligned, idxerL, idxerR, val):
di = dios_aligned.copy()
di.aloc[idxerL, idxerR] = val
exp = dios_aligned.copy()
di.loc[idxerL, idxerR] = val
assert isinstance(di, DictOfSeries)
assert (di == exp).all(None)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment