Skip to content

Commit

Permalink
Merge remote-tracking branch 'pgajdos/0.10' into 0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
smathot committed Jul 5, 2020
2 parents 38c0667 + 4ab5243 commit 0d5c44c
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 194 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ virtualenv:
system_site_packages: true
before_install:
- pip install openpyxl fastnumbers json_tricks nilearn nibabel scipy numpy pandas scikit-learn
script: nosetests testcases/*.py
script: pytest

2 changes: 1 addition & 1 deletion run_unittests.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
nosetests testcases/*.py --with-coverage --verbose --cover-package=datamatrix
pytest --cov=datamatrix testcases/
82 changes: 41 additions & 41 deletions testcases/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
from datamatrix._datamatrix._seriescolumn import _SeriesColumn
from testcases.test_tools import check_col, check_series, check_integrity
from nose.tools import ok_, raises, eq_
import pytest
import numpy as np


Expand Down Expand Up @@ -66,7 +66,7 @@ def _test_numericcolumn(cls):
dm.length = 4
# Check uniqueness
dm.col = 1, 2, 1, 2
ok_(sorted(dm.col.unique) == [1,2])
assert sorted(dm.col.unique) == [1,2]
dm.col[dm.col == 2] = 0, 0
check_col(dm.col, [1, 0, 1, 0])
check_integrity(dm)
Expand All @@ -76,22 +76,22 @@ def _test_numericcolumn(cls):
dm.col = 1, 2, 3, 4, 5
# int -> float
val = dm.col[2]
ok_(isinstance(val, (int, float)))
eq_(val, 3)
assert isinstance(val, (int, float))
assert val == 3
# (int, int) -> FloatColumn
val = dm.col[1, 3]
ok_(isinstance(val, cls))
assert isinstance(val, cls)
check_col(val, [2, 4])
# slice -> FloatColumn
val = dm.col[1:-1]
ok_(isinstance(val, cls))
assert isinstance(val, cls)
check_col(val, [2, 3, 4])
# Check array setting and getting
if cls != MixedColumn:
a = dm.col.array
ok_(isinstance(a, np.ndarray))
eq_(a.shape, (5,))
ok_(all(a == [1, 2, 3, 4, 5]))
assert isinstance(a, np.ndarray)
assert a.shape == (5,)
assert all(a == [1, 2, 3, 4, 5])


def _test_copying(cls):
Expand All @@ -101,17 +101,17 @@ def _test_copying(cls):
dm2 = dm[:]
dm2.e = dm.d
dm2.f = dm2.d
ok_(dm2 is not dm)
ok_(dm2.d is not dm.d)
ok_(dm2.e is not dm.d)
ok_(dm2.f is dm2.d)
ok_(dm2.d._seq is not dm.d._seq)
assert dm2 is not dm
assert dm2.d is not dm.d
assert dm2.e is not dm.d
assert dm2.f is dm2.d
assert dm2.d._seq is not dm.d._seq
dm.c = dm.d
ok_(dm.c is dm.d)
ok_(dm.c._seq is dm.d._seq)
assert dm.c is dm.d
assert dm.c._seq is dm.d._seq
dm.e = dm.d[:]
ok_(dm.e is not dm.d)
ok_(dm.e._seq is not dm.d._seq)
assert dm.e is not dm.d
assert dm.e._seq is not dm.d._seq
check_integrity(dm)
check_integrity(dm2)

Expand All @@ -137,20 +137,20 @@ def test_intcolumn():
dm.col = 1.9, '2.9'
check_col(dm.col, [1, 2])
# Test setting invalid values
@raises(TypeError)
def _():
dm.col[0] = 'x'
with pytest.raises(TypeError):
dm.col[0] = 'x'
_()
@raises(TypeError)
def _():
dm.col = 'x'
with pytest.raises(TypeError):
dm.col = 'x'
_()
@raises(TypeError)
def _():
dm.col[:-1] = 'x'
with pytest.raises(TypeError):
dm.col[:-1] = 'x'
_()
# Check dtype
ok_(dm.col._seq.dtype == np.int64)
assert dm.col._seq.dtype == np.int64
check_integrity(dm)


Expand Down Expand Up @@ -185,7 +185,7 @@ def test_floatcolumn():
dm.col = 'x', None
check_col(dm.col, [np.nan, np.nan])
# Check dtype
ok_(dm.col._seq.dtype == np.float64)
assert dm.col._seq.dtype == np.float64
check_integrity(dm)


Expand Down Expand Up @@ -251,20 +251,20 @@ def test_seriescolumn():
]
# (int, int) -> float
val = dm.col[2, 2]
eq_(val, 13)
eq_(type(val), float)
assert val == 13
assert type(val) == float
# (int) -> array
val = dm.col[2]
ok_(all(val == np.array([11,12,13,14,15])))
eq_(type(val), np.ndarray)
assert all(val == np.array([11,12,13,14,15]))
assert type(val) == np.ndarray
# (int, slice) -> array
val = dm.col[2, 1:-1]
ok_(all(val == np.array([12,13,14])))
eq_(type(val), np.ndarray)
assert all(val == np.array([12,13,14]))
assert type(val) == np.ndarray
# (int, (int, int)) -> array
val = dm.col[2, (1, 3)]
ok_(all(val == np.array([12,14])))
eq_(type(val), np.ndarray)
assert all(val == np.array([12,14]))
assert type(val) == np.ndarray
# (slice) -> SeriesColumn
val = dm.col[1:-1]
check_series(val, [
Expand All @@ -273,29 +273,29 @@ def test_seriescolumn():
])
# (slice, int) -> FloatColumn
val = dm.col[1:-1, 2]
ok_(isinstance(val, FloatColumn))
assert isinstance(val, FloatColumn)
check_col(val, [8, 13])
# ((int, int), int) -> FloatColumn
val = dm.col[(1, 3), 2]
ok_(isinstance(val, FloatColumn))
assert isinstance(val, FloatColumn)
check_col(val, [8, 18])
# (slice, slice) -> SeriesColumn
val = dm.col[1:-1, 1:-1]
ok_(isinstance(val, _SeriesColumn))
assert isinstance(val, _SeriesColumn)
check_series(val, [
[7, 8, 9],
[12, 13, 14],
])
# ((int, int), slice) -> SeriesColumn
val = dm.col[(1, 3), 1:-1]
ok_(isinstance(val, _SeriesColumn))
assert isinstance(val, _SeriesColumn)
check_series(val, [
[7, 8, 9],
[17, 18, 19],
])
# ((int, int), (int int)) -> SeriesColumn
val = dm.col[(1, 3), (1, 3)]
ok_(isinstance(val, _SeriesColumn))
assert isinstance(val, _SeriesColumn)
check_series(val, [
[7, 9],
[17, 19],
Expand All @@ -309,10 +309,10 @@ def test_resize():
dm.length += 1
for x, y in zip(dm._rowid, range(l)):
print(x, y)
ok_(x == y)
assert x == y
for l in range(10, 0, -1):
print('shrinking to %d' % l)
dm.length -= 1
for x, y in zip(dm._rowid, range(l)):
print(x, y)
ok_(x == y)
assert x == y
53 changes: 26 additions & 27 deletions testcases/test_desc_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,26 @@
from datamatrix import DataMatrix, MixedColumn, FloatColumn, IntColumn, \
SeriesColumn
import numpy as np
from nose.tools import eq_, ok_
from nose.tools import assert_almost_equal as aeq
import pytest

def check_odd(dm):

aeq(dm.col.mean, 13./3)
eq_(dm.col.median, 2)
aeq(dm.col.std, np.std( [1,2,10], ddof=1 ))
eq_(dm.col.min, 1)
eq_(dm.col.max, 10)
eq_(dm.col.sum, 13)
assert dm.col.mean == pytest.approx(13./3)
assert dm.col.median == 2
assert dm.col.std == pytest.approx(np.std( [1,2,10], ddof=1))
assert dm.col.min == 1
assert dm.col.max == 10
assert dm.col.sum == 13


def check_even(dm):

aeq(dm.col.mean, 4)
eq_(dm.col.median, 2.5)
aeq(dm.col.std, np.std( [1,2,3,10], ddof=1 ))
eq_(dm.col.min, 1)
eq_(dm.col.max, 10)
eq_(dm.col.sum, 16)
assert dm.col.mean == pytest.approx(4)
assert dm.col.median == 2.5
assert dm.col.std == pytest.approx(np.std( [1,2,3,10], ddof=1))
assert dm.col.min == 1
assert dm.col.max == 10
assert dm.col.sum == 16


def check_desc_stats(col_type, invalid, assert_invalid):
Expand All @@ -65,12 +64,12 @@ def check_desc_stats(col_type, invalid, assert_invalid):
# One lengths
dm.length = 1
dm.col = 1
eq_(dm.col.mean, 1)
eq_(dm.col.median, 1)
assert dm.col.mean == 1
assert dm.col.median == 1
assert_invalid(dm.col.std)
eq_(dm.col.min, 1)
eq_(dm.col.max, 1)
eq_(dm.col.sum, 1)
assert dm.col.min == 1
assert dm.col.max == 1
assert dm.col.sum == 1
# Zero lengths
dm.length = 0
assert_invalid(dm.col.mean)
Expand All @@ -82,12 +81,12 @@ def check_desc_stats(col_type, invalid, assert_invalid):

def assert_None(val):

ok_(val is None)
assert val is None


def assert_nan(val):

ok_(np.isnan(val))
assert np.isnan(val)


def test_seriescolumn():
Expand All @@ -97,15 +96,15 @@ def test_seriescolumn():
dm.col[0] = [1,2,3]
dm.col[1] = [3,3,3]
dm.col[2] = [4,4,4]
ok_(all(dm.col.mean == [8./3, 9./3, 10/3.]))
ok_(all(dm.col.median == [3,3,3]))
ok_(all(dm.col.max == [4,4,4]))
ok_(all(dm.col.min == [1,2,3]))
ok_(all(dm.col.std == [
assert all(dm.col.mean == [8./3, 9./3, 10/3.])
assert all(dm.col.median == [3,3,3])
assert all(dm.col.max == [4,4,4])
assert all(dm.col.min == [1,2,3])
assert all(dm.col.std == [
np.std([4,3,1], ddof=1),
np.std([4,3,2], ddof=1),
np.std([4,3,3], ddof=1)
]))
])


def test_mixedcolumn():
Expand Down
22 changes: 11 additions & 11 deletions testcases/test_extra_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
)
from datamatrix import operations as ops
from testcases.test_tools import check_col, check_row, check_series
from nose.tools import eq_, ok_, raises
import numpy as np
import itertools
import pytest


def test_replace():
Expand Down Expand Up @@ -81,11 +81,11 @@ def test_split():
# Without values
g = ops.split(dm.a)
val, dm = next(g)
eq_(val, 'a')
assert val == 'a'
check_col(dm.a, ['a', 'a'])
check_col(dm.b, [0, 1])
val, dm = next(g)
eq_(val, 'b')
assert val == 'b'
check_col(dm.a, ['b', 'b'])
check_col(dm.b, [2, 3])
# With values
Expand Down Expand Up @@ -113,9 +113,9 @@ def test_bin_split():
check_col(dm3.a, [2,3])
dm1, = ops.bin_split(dm.a, 1)
check_col(dm1.a, [0,1,2,3])
@raises(ValueError)
def _():
x, = ops.bin_split(dm.a, 5)
with pytest.raises(ValueError):
x, = ops.bin_split(dm.a, 5)
_()


Expand Down Expand Up @@ -220,9 +220,9 @@ def test_keep_only():
dm.c = 'y', 'z'
for cols in (['b', 'c'], [dm.b, dm.c]):
dm = ops.keep_only(dm, *cols)
ok_('a' not in dm.column_names)
ok_('b' in dm.column_names)
ok_('c' in dm.column_names)
assert 'a' not in dm.column_names
assert 'b' in dm.column_names
assert 'c' in dm.column_names


def test_auto_type():
Expand All @@ -232,6 +232,6 @@ def test_auto_type():
dm.b = 0.1, 1
dm.c = 0, 1
dm = ops.auto_type(dm)
ok_(isinstance(dm.a, MixedColumn))
ok_(isinstance(dm.b, FloatColumn))
ok_(isinstance(dm.c, IntColumn))
assert isinstance(dm.a, MixedColumn)
assert isinstance(dm.b, FloatColumn)
assert isinstance(dm.c, IntColumn)
Loading

0 comments on commit 0d5c44c

Please sign in to comment.