Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate raw response from non-async method #3089

Merged
merged 16 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ mpc

- Parse star catalog information when querying observations database [#2957]
- Parse ephemeris with sky motion with three digit precision [#3026]
- Raise EmptyResponseError when empty ephemeris reponse is returned [#3026]
- Raise EmptyResponseError when empty ephemeris response is returned [#3026]
- Deprecate ``get_raw_response`` parameter in query methods. The raw response
may be retrieved from the _async() methods. [#3089]

linelists.cdms
^^^^^^^^^^^^^^
Expand Down Expand Up @@ -191,6 +193,11 @@ mast
- Support for case-insensitive criteria keyword arguments in ``mast.Observations.query_criteria`` and
``mast.Catalogs.query_criteria``. [#3087]

mpc
^^^

- Fix bug in ``MPC.get_ephemeris`` that caused the ``cache`` keyword parameter to be ignored. [#3089]


0.4.7 (2024-03-08)
==================
Expand Down
31 changes: 15 additions & 16 deletions astroquery/mpc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from . import conf
from ..utils import async_to_sync, class_or_instance
from ..exceptions import InvalidQueryError, EmptyResponseError
from astropy.utils.decorators import deprecated_renamed_argument

__all__ = ['MPCClass']

Expand Down Expand Up @@ -186,7 +187,7 @@ def query_object_async(self, target_type, *, get_query_payload=False, **kwargs):

"""

self.get_mpc_object_endpoint(target_type)
self._get_mpc_object_endpoint(target_type)

kwargs['limit'] = 1
return self.query_objects_async(target_type, get_query_payload=get_query_payload, **kwargs)
Expand Down Expand Up @@ -315,7 +316,7 @@ def query_objects_async(self, target_type, *, get_query_payload=False, **kwargs)
Limit the number of results to the given value

"""
mpc_endpoint = self.get_mpc_object_endpoint(target_type)
mpc_endpoint = self._get_mpc_object_endpoint(target_type)

if (target_type == 'comet'):
kwargs['order_by_desc'] = "epoch"
Expand All @@ -329,7 +330,7 @@ def query_objects_async(self, target_type, *, get_query_payload=False, **kwargs)
auth = (self.MPC_USERNAME, self.MPC_PASSWORD)
return self._request('GET', mpc_endpoint, params=request_args, auth=auth)

def get_mpc_object_endpoint(self, target_type):
def _get_mpc_object_endpoint(self, target_type):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is technically an API change (though wasn't used in the docs, nor has any docstrings in the API docs), so I would say, mentioning the cleanup the changelog would be sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

mpc_endpoint = self.MPC_URL
if target_type == 'asteroid':
mpc_endpoint = mpc_endpoint + '/search_orbits'
Expand All @@ -344,8 +345,7 @@ def get_ephemeris_async(self, target, *, location='500', start=None, step='1d',
proper_motion='total', proper_motion_unit='arcsec/h',
suppress_daytime=False, suppress_set=False,
perturbed=True, unc_links=False,
get_query_payload=False,
get_raw_response=False, cache=False):
get_query_payload=False, cache=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changelog says deprecate, yet outright removed. Consider adding the decorator for now.

Copy link
Contributor Author

@mkelley mkelley Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was removed rather than deprecated because the parameter was unused and had no effect on the method's behavior. I can deprecate it even though it doesn't do anything, or just add a comment in the change log.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same comment for get_observatory_codes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned these changes (and justification) in the change log.

r"""
Object ephemerides from the Minor Planet Ephemeris Service.

Expand Down Expand Up @@ -436,10 +436,6 @@ def get_ephemeris_async(self, target, *, location='500', start=None, step='1d',
Return the HTTP request parameters as a dictionary
(default: ``False``).

get_raw_response : bool, optional
Return raw data without parsing into a table (default:
``False``).

cache : bool
Defaults to False. If set overrides global caching behavior.
See :ref:`caching documentation <astroquery_cache>`.
Expand Down Expand Up @@ -486,7 +482,7 @@ def get_ephemeris_async(self, target, *, location='500', start=None, step='1d',
| P/2003 CP7 | Comet P/2003 CP7 (LINEAR-NEAT) |
+------------+-----------------------------------+

For comets, P/ and C/ are interchangable. The designation
For comets, P/ and C/ are interchangeable. The designation
may also be in a packed format:

+------------+-----------------------------------+
Expand Down Expand Up @@ -601,21 +597,18 @@ def get_ephemeris_async(self, target, *, location='500', start=None, step='1d',
return request_args

self.query_type = 'ephemeris'
response = self._request('POST', self.MPES_URL, data=request_args)
response = self._request('POST', self.MPES_URL, data=request_args, cache=cache)

return response

@class_or_instance
def get_observatory_codes_async(self, *, get_raw_response=False, cache=True):
def get_observatory_codes_async(self, *, cache=True):
"""
Table of observatory codes from the IAU Minor Planet Center.


Parameters
----------
get_raw_response : bool, optional
Return raw data without parsing into a table (default:
`False`).

cache : bool
Defaults to True. If set overrides global caching behavior.
Expand Down Expand Up @@ -771,9 +764,10 @@ def _args_to_ephemeris_payload(self, **kwargs):
return request_args

@class_or_instance
@deprecated_renamed_argument("get_raw_response", None, since="0.4.9",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what needs to be done for the other methods, too.

Suggested change
@deprecated_renamed_argument("get_raw_response", None, since="0.4.9",
@deprecated_renamed_argument("get_raw_response", None, since="0.4.8",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

alternative="async methods")
def get_observations_async(self, targetid, *,
id_type=None,
comettype=None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened with this parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was an unused parameter and doesn't correspond to anything in the API. I can make a comment in the change log.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned in the change log.

get_mpcformat=False,
get_raw_response=False,
get_query_payload=False,
Expand All @@ -783,6 +777,11 @@ def get_observations_async(self, targetid, *,
from the `Minor Planet Center observations database
<https://minorplanetcenter.net/db_search>`_.

.. deprecated:: 0.4.9
The ``get_raw_response`` keyword argument is deprecated. The
`~MPCClass.get_observations_async` method will return a raw response.


Parameters
----------
targetid : int or str
Expand Down
34 changes: 13 additions & 21 deletions astroquery/mpc/tests/test_mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_args_to_object_payload():
('asteroid',
'https://minorplanetcenter.net/web_service/search_orbits')])
def test_get_mpc_object_endpoint(type, url):
query_url = mpc.core.MPC.get_mpc_object_endpoint(target_type=type)
query_url = mpc.core.MPC._get_mpc_object_endpoint(target_type=type)
assert query_url == url


Expand All @@ -176,19 +176,6 @@ def test_get_ephemeris_Moon_phase(patch_post):
assert result['Moon phase'][0] >= 0


def test_get_ephemeris_Uncertainty(patch_post):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the reason for removing these tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is a mistake. I thought I had made a copy-paste error, but these were actually working mocked tests. I can restore them.

Copy link
Contributor Author

@mkelley mkelley Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I partially thought it was a mistake because test_get_ephemeris_Moon_phase_and_Uncertainty was defined twice.

I think PR #3026 attempted to replace 1994 XG with 2024 AA, even though in the mocked tests it wasn't needed (because the mocked data didn't change, only the online results). I'll clean this up.

# this test requires an object with uncertainties != N/A
result = mpc.core.MPC.get_ephemeris('2024 AA')
assert result['Uncertainty 3sig'].quantity[0] > 0 * u.arcsec


def test_get_ephemeris_Moon_phase_and_Uncertainty(patch_post):
# this test requires an object with uncertainties != N/A
result = mpc.core.MPC.get_ephemeris('2024 AA', location='G37')
assert result['Moon phase'][0] >= 0
assert result['Uncertainty 3sig'].quantity[0] > 0 * u.arcsec


def test_get_ephemeris_by_name_empty(patch_post):
with pytest.raises(EmptyResponseError):
mpc.core.MPC.get_ephemeris('340P', location='G37')
Expand Down Expand Up @@ -383,9 +370,16 @@ def test_get_ephemeris_perturbed(perturbed, val):

@pytest.mark.parametrize('unc_links', (True, False))
def test_get_ephemeris_unc_links(unc_links, patch_post):
tab = mpc.core.MPC.get_ephemeris('1994 XG', unc_links=unc_links)
assert ('Unc. map' in tab.colnames) == unc_links
assert ('Unc. offsets' in tab.colnames) == unc_links
result = mpc.core.MPC.get_ephemeris('1994 XG', unc_links=unc_links)
assert np.all(result['Uncertainty 3sig'].quantity > 0 * u.arcsec)
assert ('Unc. map' in result.colnames) == unc_links
assert ('Unc. offsets' in result.colnames) == unc_links


def test_get_ephemeris_Moon_phase_and_Uncertainty(patch_post):
result = mpc.core.MPC.get_ephemeris('1994 XG', location='G37')
assert np.all(result['Moon phase'][0] >= 0)
assert np.all(result['Uncertainty 3sig'].quantity > 0 * u.arcsec)


def test_get_observatory_codes(patch_get):
Expand Down Expand Up @@ -415,10 +409,8 @@ def test_get_observations(patch_get):
assert result['DEC'].unit == u.deg
assert result['epoch'].unit == u.d

result = mpc.core.MPC.get_observations('12893',
get_raw_response=True)

assert result[0]['designation'] == "1998 QS55"
result = mpc.core.MPC.get_observations_async('12893')
assert result.json()[0]['designation'] == "1998 QS55"

result = mpc.core.MPC.get_observations('12893',
get_mpcformat=True)
Expand Down
14 changes: 1 addition & 13 deletions astroquery/mpc/tests/test_mpc_remote.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import requests
import pytest
import astropy.units as u
from astroquery.exceptions import InvalidQueryError
from astroquery import mpc

Expand Down Expand Up @@ -72,7 +71,7 @@ def test_get_observatory_codes(self):
greenwich = ['000', 0.0, 0.62411, 0.77873, 'Greenwich']
assert all([r == g for r, g in zip(response[0], greenwich)])

@pytest.mark.parametrize('target', ['(3202)', 'C/2003 A2'])
@pytest.mark.parametrize('target', ['(3202)', 'C/2024 N4'])
def test_get_ephemeris_by_target(self, target):
# test that query succeeded
response = mpc.MPC.get_ephemeris(target)
Expand All @@ -82,17 +81,6 @@ def test_get_ephemeris_Moon_phase(self):
result = mpc.core.MPC.get_ephemeris('2P', location='G37')
assert result['Moon phase'][0] >= 0

def test_get_ephemeris_Uncertainty(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the reason for removing these? I see that you mention to cleanup some tests to only run the mock versions but these seem to be removed for the mock test, too.

Copy link
Contributor Author

@mkelley mkelley Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uncertainty column is effectively tested with the test_get_ephemeris_unc_links method. Perhaps the method should be renamed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the remote file, and these are definitely the tests that need to be removed.

# this test requires an object with uncertainties != N/A
result = mpc.core.MPC.get_ephemeris('2024 AA', start='2024-06-15')
assert result['Uncertainty 3sig'].quantity[0] > 0 * u.arcsec

def test_get_ephemeris_Moon_phase_and_Uncertainty(self):
# this test requires an object with uncertainties != N/A
result = mpc.core.MPC.get_ephemeris('2024 AA', location='G37', start='2024-06-15')
assert result['Moon phase'][0] >= 0
assert result['Uncertainty 3sig'].quantity[0] > 0 * u.arcsec

def test_get_ephemeris_target_fail(self):
# test that query failed
with pytest.raises(InvalidQueryError):
Expand Down
Loading