-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_index_column.py
38 lines (24 loc) · 946 Bytes
/
table_index_column.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def table_index_column(table=None, colname=None, casesensitive=False, debug=False):
"""
see also astropy.Table.index_column
http://astropy.readthedocs.org/en/latest/api/astropy.table.Table.html#astropy.table.Table.index_column
could deprecate and use the astropy version and make the
case sensitive support via either changing the colnames in main code
or via trying both cases sequentially.
astropy table function; could be modified to also support pyfits and
Erin Sheldons fitsio
includes non case sensitive option
return icol = -1 if no column exists
"""
if debug:
print(table.colnames)
print
print('column name: ', colname)
if casesensitive:
icol=table.colnames.index(colname)
if not casesensitive:
icol=map(str.lower,table.colnames).index(colname)
if debug:
print('column number: ', icol)
if icol < 0: print('Column {0} does not exist'.format(colname))
return icol