def test_offset_1part_5(self): # already regular offset interval (but some missing) to larger one in_val = [pandas.Series(['a', 'b', 'c'], index=[0.0, 0.5, 1.5], name=('Indexer', '0'))] expected = pandas.Series(['a', 'b', 'c'], index=[0.0, 1.0, 2.0], name=('Indexer', '0')) offset_interval = 1.0 ind = FilterByOffsetIndexer(in_val, {u'quarterLength': offset_interval}) actual = ind.run()['offset.FilterByOffsetIndexer'] self.assertEqual(1, len(actual.columns)) # same number of columns? actual = actual['0'] self.assertSequenceEqual(list(expected.values), list(actual.values)) # same rows? self.assertSequenceEqual(list(expected.index), list(actual.index)) # same index?
def test_offset_1part_2(self): # input is expected output in_val = [pandas.Series(['a', 'b', 'c', 'd'], index=[0.0, 0.5, 1.0, 1.5], name=('Indexer', '0'))] expected = pandas.Series(['a', 'b', 'c', 'd'], index=[0.0, 0.5, 1.0, 1.5], name=('Indexer', '0')) offset_interval = 0.5 ind = FilterByOffsetIndexer(in_val, {u'quarterLength': offset_interval}) actual = ind.run()['offset.FilterByOffsetIndexer'] self.assertEqual(1, len(actual.columns)) # same number of columns? actual = actual['0'] self.assertSequenceEqual(list(expected.values), list(actual.values)) # same rows? self.assertSequenceEqual(list(expected.index), list(actual.index)) # same index?
def test_offset_1part_1(self): # 0 length in_val = [pandas.Series(name=('Indexer', '0'))] expected = pandas.Series(name=('Indexer', '0')) offset_interval = 0.5 ind = FilterByOffsetIndexer(in_val, {u'quarterLength': offset_interval}) actual = ind.run()['offset.FilterByOffsetIndexer'] self.assertEqual(len(in_val), len(actual.columns)) # same number of columns? actual = actual['0'] self.assertEqual(len(expected), len(actual)) # same number of rows? self.assertEqual(list(expected.index), list(actual.index)) # same row names?
def test_offset_1part_10(self): # targeted test for end-of-piece: when last thing doesn't land on an observed offset in_val = [pandas.Series(['a', 'b', 'c', 'd'], index=[0.0, 0.4, 1.1, 2.1], name=('N', '0'))] expected = pandas.Series(['a', 'b', 'b', 'c', 'c', 'd'], name=('N', '0'), index=[0.0, 0.5, 1.0, 1.5, 2.0, 2.5]) offset_interval = 0.5 ind = FilterByOffsetIndexer(in_val, {u'quarterLength': offset_interval}) actual = ind.run()['offset.FilterByOffsetIndexer'] self.assertEqual(1, len(actual.columns)) # same number of columns? actual = actual['0'] self.assertSequenceEqual(list(expected.values), list(actual.values)) # same rows? self.assertSequenceEqual(list(expected.index), list(actual.index)) # same index?
def test_offset_1part_4b(self): # already regular offset interval to a very small one in_val = [pandas.Series(['a', 'b'], index=[0.0, 0.5], name=('Indexer', '0'))] expected = pandas.Series(['a', 'a', 'a', 'a', 'b'], name=('Indexer', '0'), index=[0.0, 0.125, 0.25, 0.375, 0.5]) offset_interval = 0.125 ind = FilterByOffsetIndexer(in_val, {u'quarterLength': offset_interval}) actual = ind.run()['offset.FilterByOffsetIndexer'] self.assertEqual(1, len(actual.columns)) # same number of columns? actual = actual['0'] self.assertSequenceEqual(list(expected.values), list(actual.values)) # same rows? self.assertSequenceEqual(list(expected.index), list(actual.index)) # same index?
def test_offset_xparts_0a(self): # 0 length, many parts in_val = [pandas.Series(name=('N', str(i))) for i in range(4)] expected = pandas.DataFrame({str(i): pandas.Series() for i in range(4)}) offset_interval = 12.0 ind = FilterByOffsetIndexer(in_val, {u'quarterLength': offset_interval}) actual = ind.run()['offset.FilterByOffsetIndexer'] self.assertEqual(len(expected.columns), len(actual.columns)) expected = expected.fillna(value='None') # avoid having to use isnan() actual = actual.fillna(value='None') for partname in expected.columns: self.assertSequenceEqual(list(expected[partname].values), list(actual[partname].values)) self.assertSequenceEqual(list(expected[partname].index), list(actual[partname].index))
def test_offset_xparts_2(self): # input is expected output; 10 parts letters = ['a', 'b', 'c', 'd'] offsets = [0.0, 0.5, 1.0, 1.5] in_val = [pandas.Series(letters, index=offsets, name=('N', str(_))) for _ in range(10)] expected = {str(i): pandas.Series(letters, index=offsets) for i in range(10)} expected = pandas.DataFrame(expected) offset_interval = 0.5 ind = FilterByOffsetIndexer(in_val, {u'quarterLength': offset_interval}) actual = ind.run()['offset.FilterByOffsetIndexer'] self.assertEqual(len(expected.columns), len(actual.columns)) expected = expected.fillna(value='None') # avoid having to use isnan() actual = actual.fillna(value='None') for partname in expected.columns: self.assertSequenceEqual(list(expected[partname].values), list(actual[partname].values)) self.assertSequenceEqual(list(expected[partname].index), list(actual[partname].index))
def test_offset_xparts_1(self): # input is expected output; 2 parts in_val = [pandas.Series(['a', 'b', 'c', 'd'], index=[0.0, 0.5, 1.0, 1.5], name=('N', '0')), pandas.Series(['a', 'b', 'c', 'd'], index=[0.0, 0.5, 1.0, 1.5], name=('N', '1'))] expected = {'0': pandas.Series(['a', 'b', 'c', 'd'], index=[0.0, 0.5, 1.0, 1.5]), '1':pandas.Series(['a', 'b', 'c', 'd'], index=[0.0, 0.5, 1.0, 1.5])} expected = pandas.DataFrame(expected) offset_interval = 0.5 ind = FilterByOffsetIndexer(in_val, {u'quarterLength': offset_interval}) actual = ind.run()['offset.FilterByOffsetIndexer'] self.assertEqual(len(expected.columns), len(actual.columns)) expected = expected.fillna(value='None') # avoid having to use isnan() actual = actual.fillna(value='None') for partname in expected.columns: self.assertSequenceEqual(list(expected[partname].values), list(actual[partname].values)) self.assertSequenceEqual(list(expected[partname].index), list(actual[partname].index))
def test_offset_xparts_4(self): # irregular offset interval to 1.0; 3 parts, same offsets in_val = [pandas.Series(['a', 'b', 'c', 'd'], index=[0.0, 0.4, 1.1, 2.9], name=('N', '0')), pandas.Series(['q', 'w', 'e', 'r'], index=[0.0, 0.3, 1.4, 2.6], name=('N', '1')), pandas.Series(['t', 'a', 'l', 'l'], index=[0.0, 0.2, 1.9, 2.555], name=('N', '2'))] expected = {'0': pandas.Series(['a', 'b', 'c', 'd'], index=[0.0, 1.0, 2.0, 3.0]), '1': pandas.Series(['q', 'w', 'e', 'r'], index=[0.0, 1.0, 2.0, 3.0]), '2': pandas.Series(['t', 'a', 'l', 'l'], index=[0.0, 1.0, 2.0, 3.0])} expected = pandas.DataFrame(expected) offset_interval = 1.0 ind = FilterByOffsetIndexer(in_val, {u'quarterLength': offset_interval}) actual = ind.run()['offset.FilterByOffsetIndexer'] self.assertEqual(len(expected.columns), len(actual.columns)) expected = expected.fillna(value='None') # avoid having to use isnan() actual = actual.fillna(value='None') for partname in expected.columns: self.assertSequenceEqual(list(expected[partname].values), list(actual[partname].values)) self.assertSequenceEqual(list(expected[partname].index), list(actual[partname].index))
def test_offset_xparts_0b(self): # 0 length, many parts, but one part has stuff in_val = [pandas.Series(name=('N', '0')), pandas.Series(['a', 'b', 'c'], name=('N', '1'), index=[0.0, 0.5, 1.0]), pandas.Series(name=('N', '2')), pandas.Series(name=('N', '3'))] expected = {str(i): pandas.Series() for i in [0, 2, 3]} #print(str(expected)) # DEBUG expected['1'] = pandas.Series(['a', 'b', 'c'], index=[0.0, 0.5, 1.0]) #print(str(expected)) # DEBUG expected = pandas.DataFrame(expected) offset_interval = 0.5 ind = FilterByOffsetIndexer(in_val, {u'quarterLength': offset_interval}) actual = ind.run()['offset.FilterByOffsetIndexer'] self.assertEqual(len(expected.columns), len(actual.columns)) expected = expected.fillna(value='None') # avoid having to use isnan() actual = actual.fillna(value='None') for partname in expected.columns: self.assertSequenceEqual(list(expected[partname].values), list(actual[partname].values)) self.assertSequenceEqual(list(expected[partname].index), list(actual[partname].index))