Skip to content

Commit 0436007

Browse files
committed
ENH: fix to enable to pass Path objects longer than a filename as output_file
1 parent ec61ab1 commit 0436007

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ cadc
5656

5757
- Deprecated keywords and ``run_query`` method have been removed. [#2389]
5858

59+
- Added the ability to pass longer that filename Path objects as
60+
``output_file``. [#2541]
61+
5962
casda
6063
^^^^^
6164

astroquery/cadc/core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import warnings
1212
import requests
1313
from numpy import ma
14+
from pathlib import Path
1415
from urllib.parse import urlencode
1516
from urllib.error import HTTPError
1617

@@ -587,7 +588,7 @@ def exec_sync(self, query, maxrec=None, uploads=None, output_file=None,
587588
the maximum records to return. defaults to the service default
588589
uploads :
589590
Temporary tables to upload and run with the queries
590-
output_file : str or file handler
591+
output_file : str, Path, or file handler
591592
File to save the results to
592593
output_format :
593594
Format of the output (default is basic). Must be one
@@ -608,10 +609,13 @@ def exec_sync(self, query, maxrec=None, uploads=None, output_file=None,
608609
if output_file:
609610
if isinstance(output_file, str):
610611
fname = output_file
612+
elif isinstance(output_file, Path):
613+
# Merge this case into the str once astropy is >=5.1
614+
fname = str(output_file)
611615
elif hasattr(output_file, 'name'):
612616
fname = output_file.name
613617
else:
614-
raise AttributeError('Not a valid file name or file handler')
618+
raise AttributeError('Not a valid file name, Path, or file handler')
615619
result.write(fname, format=output_format, overwrite=True)
616620
return result
617621

astroquery/cadc/tests/test_cadctap.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from pathlib import Path
1111
import os
1212
import sys
13-
from pathlib import Path
1413

1514
from astropy.table import Table as AstroTable
1615
from astropy.io.fits.hdu.hdulist import HDUList

0 commit comments

Comments
 (0)