def test_table_apply(): data = np.ones([3, 100]) data[1] = 2 data[2] = 3 tab = ds.Table(columns=data, labels=['a', 'b', 'c']) newtab = util.table_apply(tab, np.mean) assert newtab.num_rows == 1 assert all(newtab['a'] == np.mean(tab['a'])) newtab = util.table_apply(tab, lambda a: a + 1) assert all(newtab['a'] == tab['a'] + 1) newtab = util.table_apply(tab, lambda a: a + 1, subset=['b', 'c']) assert all(newtab['a'] == tab['a']) assert all(newtab['b'] == tab['b'] + 1)
def test_table_apply(): data = np.ones([3, 100]) data[1] = 2 data[2] = 3 # tab = ds.Table(data, ['a', 'b', 'c']) tab = ds.Table().with_columns('a', data[0], 'b', data[1], 'c', data[2]) newtab = util.table_apply(tab, np.mean) assert newtab.num_rows == 1 assert all(newtab['a'] == np.mean(tab['a'])) newtab = util.table_apply(tab, lambda a: a + 1) assert all(newtab['a'] == tab['a'] + 1) newtab = util.table_apply(tab, lambda a: a + 1, subset=['b', 'c']) assert all(newtab['a'] == tab['a']) assert all(newtab['b'] == tab['b'] + 1)
def mne_to_table(data): """Convert an MNE Raw object into a datascience table. Parameters ---------- data : instance of MNE raw object. The data to be converted to a table. Returns ------- table : instance of datascience Table. The data in table format. """ df = pd.DataFrame(data._data.T, columns=data.ch_names) table = ds.Table().from_df(df) table['time'] = np.arange(df.shape[0]) / data.info['sfreq'] return table
def test_currency_format(): vs = ['$60', '$162.5'] t = ds.Table([vs, vs, vs], ['num1', 'num2', 'str']) t.set_format(['num1', 'num2'], ds.CurrencyFormatter('$')) assert_equal(t, """ num1 | num2 | str $60.00 | $60.00 | $60 $162.50 | $162.50 | $162.5 """) assert_equal(t.sort('num1'), """ num1 | num2 | str $60.00 | $60.00 | $60 $162.50 | $162.50 | $162.5 """) assert_equal(t.sort('str'), """ num1 | num2 | str $162.50 | $162.50 | $162.5 $60.00 | $60.00 | $60 """)
def test_table_apply(): data = np.ones([3, 100]) data[1] = 2 data[2] = 3 # tab = ds.Table(data, ['a', 'b', 'c']) tab = ds.Table().with_columns('a', data[0], 'b', data[1], 'c', data[2]) newtab = util.table_apply(tab, np.mean) assert newtab.num_rows == 1 assert all(newtab['a'] == np.mean(tab['a'])) newtab = util.table_apply(tab, lambda a: a + 1) assert all(newtab['a'] == tab['a'] + 1) newtab = util.table_apply(tab, lambda a: a + 1, subset=['b', 'c']) assert all(newtab['a'] == tab['a']) assert all(newtab['b'] == tab['b'] + 1) with pytest.raises(ValueError) as err: util.table_apply(tab, lambda a: a + 1, subset=['b', 'd']) assert "Colum mismatch: ['d']" in str(err.value)
def test_date_format(): vs = ['2015-07-01 22:39:44.900351'] t = ds.Table([vs], ['time']) t.set_format('time', ds.DateFormatter("%Y-%m-%d %H:%M:%S.%f")) assert isinstance(t['time'][0], float)