def __getitem__(self, key_list):
     val = []
     key = []
     #input is a ll list
     if isinstance(key_list, LabeledList):
         for i, j in zip(self.values, self.index):
             if j in key_list.values:
                 val.append(i)
                 key.append(j)
         return tt.LabeledList(val, key)
     #input is a list of string
     if isinstance(key_list, list):
         if (isinstance(key_list[0], str)):
             for i, j in zip(self.values, self.index):
                 if j in key_list:
                     val.append(i)
                     key.append(j)
             if (len(val) == 1):
                 return val[0]
             else:
                 return tt.LabeledList(val, key)
         if (isinstance(key_list[0], bool)):  # input is a list of boolean
             for i, j, k in zip(self.values, self.index, key_list):
                 if k == True:
                     val.append(i)
                     key.append(j)
             return tt.LabeledList(val, key)
     if isinstance(key_list, str):
         for i, j in zip(self.values, self.index):
             if j in key_list:
                 val.append(i)
                 key.append(j)
         if (len(val) == 1):
             return val[0]
         else:
             return tt.LabeledList(val, key)
Beispiel #2
0
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 15 23:02:52 2019

@author: joshu
"""

import tabletools as tt


ll = tt.LabeledList([1, 2, 3, 4, 5], [True, 'BB', 'BB', 'CCC', 'D'])

print(str(ll))
print(repr(ll))

ll = tt.LabeledList([1, 2, 3, 4, 5], ['A', 'BB', 'BB', 'CCC', 'D'])

# 1 (values are taken from LabeledList as a list...
# more than one label yields all label and value pairs)
print(ll[tt.LabeledList(['A', 'BB'])])
print(ll[['A', 'BB']])

print(ll[[False, False, False, True, True]])

print(ll['A'])

print(ll['BB']) #

ll = tt.LabeledList([1, 2], ['x', 'y'])
print(ll==1)
print(ll>1)
Beispiel #3
0
              ['foo', 'bar', 'bazzy', 'qux', 'quxx'])
    print(t)
    print()

    print('Test no index and columns')
    t = Table([['foo', 'bar', 'baz'], ['qux', 'quxx', 'corge']])
    print(t)

    print('Test __repr__')
    print(t.__repr__())
    print()

    print('Test getitem w/ LabeledList')
    t = Table(d, ['foo', 'bar', 'bazzy', 'qux', 'quxx'],
              ['a', 'b', 'c', 'd', 'e'])
    print(t[tt.LabeledList(['a', 'b'])])
    print()

    print('Test getitem w/ list containing duplicate columns')
    t = Table([[15, 17, 19], [14, 16, 18]], columns=['x', 'y', 'z'])
    print(t[['x', 'x', 'y']])
    print()

    print('Test get item w/ boolean list')
    t = Table([[1, 2, 3], [4, 5, 6], [7, 8, 9]], columns=['x', 'y', 'z'])
    print(t[[True, False, True]])
    print()

    print('Test get w/ dup column definition')
    pdb.set_trace()
    t = Table([[1, 2, 3], [4, 5, 6]], columns=['a', 'b', 'a'])
 def map(self, f):
     result = []
     result = list(map(f, self.values))
     return tt.LabeledList(result)
 def __lt__(self, scalar):
     val = [True if x < scalar else False for x in self.values]
     return tt.LabeledList(val)