@@ -343,8 +343,8 @@ def list_votable_fields(self):
343
343
fields_dict = json .load (f )
344
344
345
345
print ("Available VOTABLE fields:\n " )
346
- for field in list ( sorted (fields_dict .keys () )):
347
- print ("{}" . format (field ))
346
+ for field in sorted (fields_dict .keys ()):
347
+ print (str (field ))
348
348
print ("For more information on a field:\n "
349
349
"Simbad.get_field_description ('field_name') \n "
350
350
"Currently active VOTABLE fields:\n {0}"
@@ -405,10 +405,7 @@ def add_votable_fields(self, *args):
405
405
os .path .join ('data' , 'votable_fields_dict.json' ))
406
406
407
407
with open (dict_file , "r" ) as f :
408
- fields_dict = json .load (f )
409
- fields_dict = dict (
410
- ((strip_field (ff ), fields_dict [ff ])
411
- for ff in fields_dict ))
408
+ fields_dict = {strip_field (k ): v for k , v in json .load (f ).items ()}
412
409
413
410
for field in args :
414
411
sf = strip_field (field )
@@ -417,34 +414,30 @@ def add_votable_fields(self, *args):
417
414
else :
418
415
self ._VOTABLE_FIELDS .append (field )
419
416
420
- def remove_votable_fields (self , * args , ** kwargs ):
417
+ def remove_votable_fields (self , * args , strip_params = False ):
421
418
"""
422
419
Removes the specified field names from ``SimbadClass._VOTABLE_FIELDS``
423
420
424
421
Parameters
425
422
----------
426
423
list of field_names to be removed
427
- strip_params: bool
424
+ strip_params: bool, optional
428
425
If true, strip the specified keywords before removing them:
429
426
e.g., ra(foo) would remove ra(bar) if this is True
430
427
"""
431
- strip_params = kwargs .pop ('strip_params' , False )
432
-
433
428
if strip_params :
434
- sargs = [ strip_field (a ) for a in args ]
429
+ sargs = { strip_field (a ) for a in args }
435
430
sfields = [strip_field (a ) for a in self ._VOTABLE_FIELDS ]
436
431
else :
437
- sargs = args
432
+ sargs = set ( args )
438
433
sfields = self ._VOTABLE_FIELDS
439
- absent_fields = set (sargs ) - set (sfields )
440
434
441
- for b , f in list (zip (sfields , self ._VOTABLE_FIELDS )):
442
- if b in sargs :
443
- self ._VOTABLE_FIELDS .remove (f )
444
-
445
- for field in absent_fields :
435
+ for field in sargs .difference (sfields ):
446
436
warnings .warn ("{field}: this field is not set" .format (field = field ))
447
437
438
+ zipped_fields = zip (sfields , self ._VOTABLE_FIELDS )
439
+ self ._VOTABLE_FIELDS = [f for b , f in zipped_fields if b not in sargs ]
440
+
448
441
# check if all fields are removed
449
442
if not self ._VOTABLE_FIELDS :
450
443
warnings .warn ("All fields have been removed. "
@@ -677,7 +670,7 @@ def query_region_async(self, coordinates, radius=2*u.arcmin,
677
670
if len (set (frame )) > 1 :
678
671
raise ValueError ("Coordinates have different frames" )
679
672
else :
680
- frame = set ( frame ). pop ()
673
+ frame = frame [ 0 ]
681
674
682
675
if isiterable (radius ):
683
676
if len (radius ) != len (ra ):
@@ -941,20 +934,13 @@ def query_objectids_async(self, object_name, cache=True,
941
934
return response
942
935
943
936
def _get_query_header (self , get_raw = False ):
944
- votable_fields = ',' .join (self .get_votable_fields ())
945
937
# if get_raw is set then don't fetch as votable
946
938
if get_raw :
947
939
return ""
948
- votable_def = "votable {" + votable_fields + "}"
949
- votable_open = "votable open"
950
- return "\n " .join ([votable_def , votable_open ])
940
+ return "votable {" + ',' .join (self .get_votable_fields ()) + "}\n votable open"
951
941
952
942
def _get_query_footer (self , get_raw = False ):
953
- if get_raw :
954
- return ""
955
- votable_close = "votable close"
956
-
957
- return votable_close
943
+ return "" if get_raw else "votable close"
958
944
959
945
@validate_epoch_decorator
960
946
@validate_equinox_decorator
@@ -989,25 +975,19 @@ def _args_to_payload(self, *args, **kwargs):
989
975
kwargs ['equi' ] = kwargs ['equinox' ]
990
976
del kwargs ['equinox' ]
991
977
# remove default None from kwargs
992
- # be compatible with python3
993
- for key in list (kwargs ):
994
- if not kwargs [key ]:
995
- del kwargs [key ]
978
+ kwargs = {key : value for key , value in kwargs .items () if value is not None }
996
979
# join in the order specified otherwise results in error
997
980
all_keys = ['radius' , 'frame' , 'equi' , 'epoch' ]
998
981
present_keys = [key for key in all_keys if key in kwargs ]
999
982
if caller == 'query_criteria_async' :
1000
- for k in kwargs :
1001
- present_keys .append (k )
983
+ present_keys .extend (kwargs )
1002
984
# need ampersands to join args
1003
985
args_str = '&' .join ([str (val ) for val in args ])
1004
- if len ( args ) > 0 and len ( present_keys ) > 0 :
986
+ if args and present_keys :
1005
987
args_str += " & "
1006
988
else :
1007
989
args_str = ' ' .join ([str (val ) for val in args ])
1008
- kwargs_str = ' ' .join ("{key}={value}" .format (key = key ,
1009
- value = kwargs [key ])
1010
- for key in present_keys )
990
+ kwargs_str = ' ' .join (f"{ key } ={ kwargs [key ]} " for key in present_keys )
1011
991
1012
992
# For the record, I feel dirty for writing this wildcard-case hack.
1013
993
# This entire function should be refactored when someone has time.
0 commit comments