Skip to content

Infinite loop for doctesting: caching issue with atomic #2338

Description

@bsipocz

I'm not exatly sure what's going on here with this docs example:

>>> from astropy import units as u
>>> from astroquery.atomic import AtomicLineList
>>> wavelength_range = (15 * u.nm, 1.5e+16 * u.Hz)
>>> AtomicLineList.query_object(wavelength_range=wavelength_range, wavelength_type='Air',
...                             wavelength_accuracy=20, element_spectrum='C II-IV')

Running it in ipython I get the expected result (pending some not yet merged changes that get rid of a few warnings):

<Table length=3>
LAMBDA VAC ANG SPECTRUM  TT  CONFIGURATION   TERM   J J      A_ki    LEVEL ENERGY  CM 1
   float64       str4   str2     str14       str6   str5   float64         str18       
-------------- -------- ---- -------------- ------ ----- ----------- ------------------
      196.8874     C IV   E1 1s2.2s-1s2.12p 2S-2Po 1/2-*  91300000.0 0.00 -   507904.40
      197.7992     C IV   E1 1s2.2s-1s2.11p 2S-2Po 1/2-* 118000000.0 0.00 -   505563.30
      199.0122     C IV   E1 1s2.2s-1s2.10p 2S-2Po 1/2-* 157000000.0 0.00 -   502481.80

Running it with doctest OTOH:

========================================================================= FAILURES =========================================================================
___________________________________________________________________ [doctest] atomic.rst ___________________________________________________________________
023 In the following Python session you can see the ``atomic`` package in
024 action. Note that Hz is actually not a supported unit by Atomic Line List,
025 the atomic package takes care to support all spectral units.
026 
027 .. doctest-remote-data::
028 
029     >>> from astropy import units as u
030     >>> from astroquery.atomic import AtomicLineList
031     >>> wavelength_range = (15 * u.nm, 1.5e+16 * u.Hz)
032     >>> AtomicLineList.query_object(wavelength_range=wavelength_range, wavelength_type='Air',
UNEXPECTED EXCEPTION: RecursionError('maximum recursion depth exceeded while calling a Python object')
Traceback (most recent call last):
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/doctest.py", line 1336, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest atomic.rst[3]>", line 1, in <module>
  File "/private/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/astroquery-test-r53oieer/lib/python3.9/site-packages/astroquery/atomic/core.py", line 151, in query_object
    response = self.query_object_async(
  File "/private/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/astroquery-test-r53oieer/lib/python3.9/site-packages/astroquery/atomic/core.py", line 246, in query_object_async
    response = self._submit_form(input_payload, cache=cache)
  File "/private/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/astroquery-test-r53oieer/lib/python3.9/site-packages/astroquery/atomic/core.py", line 299, in _submit_form
    response = self._request("POST", url=url, data=payload,
  File "/private/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/astroquery-test-r53oieer/lib/python3.9/site-packages/astroquery/query.py", line 324, in _request
    to_cache(response, query.request_file(self.cache_location))
  File "/private/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/astroquery-test-r53oieer/lib/python3.9/site-packages/astroquery/query.py", line 30, in to_cache
    response = copy.deepcopy(response)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
...
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "/Users/bsipocz/.pyenv/versions/3.9.1/lib/python3.9/copy.py", line 137, in deepcopy
    d = id(x)
RecursionError: maximum recursion depth exceeded while calling a Python object
/private/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/astroquery-test-r53oieer/lib/python3.9/site-packages/docs/atomic/atomic.rst:32: UnexpectedException
================================================================= short test summary info ==================================================================
FAILED docs/atomic/atomic.rst::atomic.rst
=============================================================== 1 failed, 9 passed in 3.35s ================================================================

All the while if I add the cache=False kwarg the doctesting passes as expected, too.

I haven't seen this type of issues with any of the other modules, so it may not be a generic caching issue, but something specific to atomic.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions