3
3
"""
4
4
5
5
from typing import Union , List , Optional
6
+ from astropy .table import Table
7
+
8
+ DEFAULT_LEAD_COLS_RAW = ['object' , 'ra' , 'dec' , 'dp_id' , 'date_obs' , 'prog_id' ]
9
+ DEFAULT_LEAD_COLS_PHASE3 = ['target_name' , 's_ra' , 's_dec' , 'dp_id' , 'date_obs' , 'proposal_id' ]
6
10
7
11
8
12
def _split_str_as_list_of_str (column_str : str ):
@@ -13,6 +17,27 @@ def _split_str_as_list_of_str(column_str: str):
13
17
return column_list
14
18
15
19
20
+ def reorder_columns (table : Table ,
21
+ leading_cols : Optional [List [str ]] = None ):
22
+ """
23
+ Reorders the columns of the pased table so that the
24
+ colums given by the list leading_cols are first.
25
+ If no leading cols are passed, it defaults to
26
+ ['object', 'ra', 'dec', 'dp_id', 'date_obs']
27
+ Returns a table with the columns reordered.
28
+ """
29
+ leading_cols = leading_cols or DEFAULT_LEAD_COLS_RAW
30
+ first_cols = []
31
+ last_cols = table .colnames [:]
32
+ for x in leading_cols :
33
+ if x in last_cols :
34
+ last_cols .remove (x )
35
+ first_cols .append (x )
36
+ last_cols = first_cols + last_cols
37
+ table = table [last_cols ]
38
+ return table
39
+
40
+
16
41
def adql_sanitize_val (x ):
17
42
"""
18
43
If the value is a string, put it into single quotes
0 commit comments