Skip to content

Commit 5639442

Browse files
authored
Merge pull request #3130 from esdc-esac-esa-int/ESA_gaia_GAIAMNGT-1700_load_data
Gaia: update the output file name built by the method load_data to include microsecond resolution
2 parents e150df1 + ce16157 commit 5639442

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

CHANGES.rst

+2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ gaia
189189

190190
- New retrieval types for datalink (Gaia DR4 release). [#3110]
191191

192+
- The output file name built by the method load_data, includes microsecond resolution. This is based on the previous PR [#3014]. [#3130]
193+
192194

193195
jplhorizons
194196
^^^^^^^^^^^

astroquery/gaia/core.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL', retr
224224
dump_to_file: boolean, optional, default False.
225225
If it is true, a compressed directory named "datalink_output_<time_stamp>.zip" with all the DataLink
226226
files is made in the current working directory. The <time_stamp> format follows the ISO 8601 standard:
227-
"yyyymmddThhmmss".
227+
"YYYYMMDD_HHMMSS.mmmmmm".
228228
overwrite_output_file : boolean, optional, default False
229229
To overwrite the output file ("datalink_output.zip") if it already exists.
230230
verbose : bool, optional, default 'False'
@@ -239,13 +239,13 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL', retr
239239

240240
now = datetime.datetime.now(datetime.timezone.utc)
241241
if not dump_to_file:
242-
now_formatted = now.strftime("%Y%m%d_%H%M%S")
242+
now_formatted = now.strftime("%Y%m%d_%H%M%S.%f")
243243
temp_dirname = "temp_" + now_formatted
244244
downloadname_formated = "download_" + now_formatted
245245
output_file = os.path.join(os.getcwd(), temp_dirname, downloadname_formated)
246246

247247
else:
248-
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
248+
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S.%f") + '.zip'
249249
output_file_specified = True
250250
output_file = os.path.abspath(output_file)
251251
log.info(f"DataLink products will be stored in the {output_file} file")
@@ -258,7 +258,7 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL', retr
258258

259259
log.debug(f"Directory where the data will be saved: {path}")
260260

261-
if path != '':
261+
if path:
262262
if not os.path.isdir(path):
263263
try:
264264
os.mkdir(path)

astroquery/gaia/tests/test_gaiatap.py

+26-11
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
RADIUS = 1 * u.deg
8888
SKYCOORD = SkyCoord(ra=19 * u.deg, dec=20 * u.deg, frame="icrs")
8989

90-
FAKE_TIME = datetime.datetime(2024, 1, 1, 0, 0, 59)
90+
FAKE_TIME = datetime.datetime(2024, 1, 1, 0, 0, 59, 1)
9191

9292

9393
@pytest.fixture
@@ -999,9 +999,12 @@ def test_datalink_querier_load_data_fits(mock_datalink_querier_fits):
999999
assert not os.path.exists(datalink_output)
10001000

10011001

1002-
def test_load_data_vot(monkeypatch, tmp_path, tmp_path_factory):
1002+
def test_load_data_vot(monkeypatch, tmp_path, tmp_path_factory, patch_datetime_now):
1003+
1004+
assert datetime.datetime.now(datetime.timezone.utc) == FAKE_TIME
1005+
10031006
now = datetime.datetime.now(datetime.timezone.utc)
1004-
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
1007+
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S.%f") + '.zip'
10051008

10061009
path = Path(os.getcwd(), output_file)
10071010

@@ -1076,9 +1079,12 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
10761079
path.unlink()
10771080

10781081

1079-
def test_load_data_csv(monkeypatch, tmp_path, tmp_path_factory):
1082+
def test_load_data_csv(monkeypatch, tmp_path, tmp_path_factory, patch_datetime_now):
1083+
1084+
assert datetime.datetime.now(datetime.timezone.utc) == FAKE_TIME
1085+
10801086
now = datetime.datetime.now(datetime.timezone.utc)
1081-
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
1087+
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S.%f") + '.zip'
10821088

10831089
path = Path(os.getcwd(), output_file)
10841090

@@ -1112,9 +1118,12 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
11121118
path.unlink()
11131119

11141120

1115-
def test_load_data_ecsv(monkeypatch, tmp_path, tmp_path_factory):
1121+
def test_load_data_ecsv(monkeypatch, tmp_path, tmp_path_factory, patch_datetime_now):
1122+
1123+
assert datetime.datetime.now(datetime.timezone.utc) == FAKE_TIME
1124+
11161125
now = datetime.datetime.now(datetime.timezone.utc)
1117-
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
1126+
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S.%f") + '.zip'
11181127

11191128
path = Path(os.getcwd(), output_file)
11201129

@@ -1148,9 +1157,12 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
11481157
path.unlink()
11491158

11501159

1151-
def test_load_data_linking_parameter(monkeypatch, tmp_path):
1160+
def test_load_data_linking_parameter(monkeypatch, tmp_path, patch_datetime_now):
1161+
1162+
assert datetime.datetime.now(datetime.timezone.utc) == FAKE_TIME
1163+
11521164
now = datetime.datetime.now(datetime.timezone.utc)
1153-
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
1165+
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S.%f") + '.zip'
11541166

11551167
path = Path(os.getcwd(), output_file)
11561168

@@ -1185,9 +1197,12 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
11851197

11861198

11871199
@pytest.mark.parametrize("linking_param", ['TRANSIT_ID', 'IMAGE_ID'])
1188-
def test_load_data_linking_parameter_with_values(monkeypatch, tmp_path, linking_param):
1200+
def test_load_data_linking_parameter_with_values(monkeypatch, tmp_path, linking_param, patch_datetime_now):
1201+
1202+
assert datetime.datetime.now(datetime.timezone.utc) == FAKE_TIME
1203+
11891204
now = datetime.datetime.now(datetime.timezone.utc)
1190-
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
1205+
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S.%f") + '.zip'
11911206

11921207
path = Path(os.getcwd(), output_file)
11931208

0 commit comments

Comments
 (0)