comparison numerics/data.py @ 48:36e47061187f

stub a transposition function
author Jeff Hammel <k0scist@gmail.com>
date Mon, 19 Jan 2015 12:38:51 -0800
parents 87615a38190c
children 5caa67643162
comparison
equal deleted inserted replaced
47:6d34c02f7c9c 48:36e47061187f
4 data models 4 data models
5 """ 5 """
6 6
7 from collections import OrderedDict 7 from collections import OrderedDict
8 8
9 __all__ = ['Rows', 'Columns'] 9 __all__ = ['ColumnNumberException', 'ColumnLengthException', 'Rows', 'Columns']
10 10
11 11
12 class ColumnNumberException(Exception): 12 class ColumnNumberException(Exception):
13 """ 13 """
14 wrong number of columns: {given} given; {expected} expected 14 wrong number of columns: {given} given; {expected} expected
16 def __init__(self, given, expected): 16 def __init__(self, given, expected):
17 self.given = given 17 self.given = given
18 self.expected = expected 18 self.expected = expected
19 Exception.__init__(self.__doc__.format(**self.__dict__).strip()) 19 Exception.__init__(self.__doc__.format(**self.__dict__).strip())
20 20
21
22 def transpose(array):
23 """makes rows into columns or vice versa"""
24
25 if not array:
26 return array # nothing to do
27
28 n_cols = len(array[0])
29 retval = []] * n_cols
30 raise NotImplementedError('TODO') # -> record TODO items
21 31
22 class ColumnLengthException(ColumnNumberException): 32 class ColumnLengthException(ColumnNumberException):
23 """ 33 """
24 wrong length of column: {given} given; {expected} expected 34 wrong length of column: {given} given; {expected} expected
25 """ 35 """
67 self += (name, values) 77 self += (name, values)
68 78
69 def __iadd__(self, item): 79 def __iadd__(self, item):
70 column_name, values = item 80 column_name, values = item
71 assert column_name not in self.columns 81 assert column_name not in self.columns
72
73 return self 82 return self