nanograv / PINT

PINT is not TEMPO3 -- Software for high-precision pulsar timing
Other
118 stars 100 forks source link

Strange recursion problem with pint logging in recent astropy #1805

Open matteobachetti opened 1 month ago

matteobachetti commented 1 month ago

pint-pulsar 1.0.1 numpy 1.26.4/2.0.0 astropy 6.1.1

Does not happen in Astropy 5.3.4

In [1]: import pint
---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
Cell In[1], line 1
----> 1 import pint

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/pint/__init__.py:16
     14 import astropy
     15 import astropy.constants as c
---> 16 import astropy.time as time
     17 import astropy.units as u
     18 import numpy as np

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/astropy/time/__init__.py:47
     44 conf = Conf()
     46 # isort: off
---> 47 from .formats import *
     48 from .core import *
     50 # isort: on

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/astropy/time/formats.py:1713
   1708             outs.append(str(self.format_string(str_fmt, **kwargs)))
   1710         return np.array(outs).reshape(self.jd1.shape)
-> 1713 class TimeISO(TimeString):
   1714     """
   1715     ISO 8601 compliant date-time format "YYYY-MM-DD HH:MM:SS.sss...".
   1716     For example, 2000-01-01 00:00:00.000 is midnight on January 1, 2000.
   (...)
   1722     - 'date': date
   1723     """
   1725     name = "iso"

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/astropy/time/formats.py:1479, in TimeString.__init_subclass__(cls, **kwargs)
   1477 if "fast_parser_pars" in cls.__dict__:
   1478     fpp = cls.fast_parser_pars
-> 1479     fpp = np.array(
   1480         list(
   1481             zip(
   1482                 map(chr, fpp["delims"]),
   1483                 fpp["starts"],
   1484                 fpp["stops"],
   1485                 fpp["break_allowed"],
   1486             )
   1487         ),
   1488         _parse_times.dt_pars,
   1489     )
   1490     if cls.fast_parser_pars["has_day_of_year"]:
   1491         fpp["start"][1] = fpp["stop"][1] = -1

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:46, in __repr__(dtype)
     45 def __repr__(dtype):
---> 46     arg_str = _construction_repr(dtype, include_align=False)
     47     if dtype.isalignedstruct:
     48         arg_str = arg_str + ", align=True"

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:96, in _construction_repr(dtype, include_align, short)
     69 """
     70 Creates a string repr of the dtype, excluding the 'dtype()' part
     71 surrounding the object. This object may be a string, a list, or
   (...)
     93     provided as the second parameter.
     94 """
     95 if dtype.fields is not None:
---> 96     return _struct_str(dtype, include_align=include_align)
     97 elif dtype.subdtype:
     98     return _subarray_str(dtype)

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:310, in _struct_str(dtype, include_align)
    305 def _struct_str(dtype, include_align):
    306     # The list str representation can't include the 'align=' flag,
    307     # so if it is requested and the struct has the aligned flag set,
    308     # we must use the dict str instead.
    309     if not (include_align and dtype.isalignedstruct) and _is_packed(dtype):
--> 310         sub = _struct_list_str(dtype)
    312     else:
    313         sub = _struct_dict_str(dtype, include_align)

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:297, in _struct_list_str(dtype)
    292     item += "{}, {}".format(
    293         _construction_repr(base, short=True),
    294         shape
    295     )
    296 else:
--> 297     item += _construction_repr(fld_dtype, short=True)
    299 item += ")"
    300 items.append(item)

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:100, in _construction_repr(dtype, include_align, short)
     98     return _subarray_str(dtype)
     99 else:
--> 100     return _scalar_str(dtype, short=short)

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:143, in _scalar_str(dtype, short)
    140 elif dtype.type == np.timedelta64:
    141     return "'%sm8%s'" % (byteorder, _datetime_metadata_str(dtype))
--> 143 elif np.issubdtype(dtype, np.number):
    144     # Short repr with endianness, like '<f8'
    145     if short or dtype.byteorder not in ('=', '|'):
    146         return "'%s%c%d'" % (byteorder, dtype.kind, dtype.itemsize)

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/numerictypes.py:417, in issubdtype(arg1, arg2)
    359 r"""
    360 Returns True if first argument is a typecode lower/equal in type hierarchy.
    361 
   (...)
    414 
    415 """
    416 if not issubclass_(arg1, generic):
--> 417     arg1 = dtype(arg1).type
    418 if not issubclass_(arg2, generic):
    419     arg2 = dtype(arg2).type

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:46, in __repr__(dtype)
     45 def __repr__(dtype):
---> 46     arg_str = _construction_repr(dtype, include_align=False)
     47     if dtype.isalignedstruct:
     48         arg_str = arg_str + ", align=True"

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:100, in _construction_repr(dtype, include_align, short)
     98     return _subarray_str(dtype)
     99 else:
--> 100     return _scalar_str(dtype, short=short)

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:143, in _scalar_str(dtype, short)
    140 elif dtype.type == np.timedelta64:
    141     return "'%sm8%s'" % (byteorder, _datetime_metadata_str(dtype))
--> 143 elif np.issubdtype(dtype, np.number):
    144     # Short repr with endianness, like '<f8'
    145     if short or dtype.byteorder not in ('=', '|'):
    146         return "'%s%c%d'" % (byteorder, dtype.kind, dtype.itemsize)

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/numerictypes.py:417, in issubdtype(arg1, arg2)
    359 r"""
    360 Returns True if first argument is a typecode lower/equal in type hierarchy.
    361 
   (...)
    414 
    415 """
    416 if not issubclass_(arg1, generic):
--> 417     arg1 = dtype(arg1).type
    418 if not issubclass_(arg2, generic):
    419     arg2 = dtype(arg2).type

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:46, in __repr__(dtype)
     45 def __repr__(dtype):
---> 46     arg_str = _construction_repr(dtype, include_align=False)
     47     if dtype.isalignedstruct:
     48         arg_str = arg_str + ", align=True"

    [... skipping similar frames: _construction_repr at line 100 (490 times), __repr__ at line 46 (489 times), _scalar_str at line 143 (489 times), issubdtype at line 417 (489 times)]

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:143, in _scalar_str(dtype, short)
    140 elif dtype.type == np.timedelta64:
    141     return "'%sm8%s'" % (byteorder, _datetime_metadata_str(dtype))
--> 143 elif np.issubdtype(dtype, np.number):
    144     # Short repr with endianness, like '<f8'
    145     if short or dtype.byteorder not in ('=', '|'):
    146         return "'%s%c%d'" % (byteorder, dtype.kind, dtype.itemsize)

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/numerictypes.py:417, in issubdtype(arg1, arg2)
    359 r"""
    360 Returns True if first argument is a typecode lower/equal in type hierarchy.
    361 
   (...)
    414 
    415 """
    416 if not issubclass_(arg1, generic):
--> 417     arg1 = dtype(arg1).type
    418 if not issubclass_(arg2, generic):
    419     arg2 = dtype(arg2).type

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:46, in __repr__(dtype)
     45 def __repr__(dtype):
---> 46     arg_str = _construction_repr(dtype, include_align=False)
     47     if dtype.isalignedstruct:
     48         arg_str = arg_str + ", align=True"

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:100, in _construction_repr(dtype, include_align, short)
     98     return _subarray_str(dtype)
     99 else:
--> 100     return _scalar_str(dtype, short=short)

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:104, in _scalar_str(dtype, short)
    103 def _scalar_str(dtype, short):
--> 104     byteorder = _byte_order_str(dtype)
    106     if dtype.type == np.bool_:
    107         if short:

File ~/opt/anaconda3/envs/py311/lib/python3.11/site-packages/numpy/core/_dtype.py:163, in _byte_order_str(dtype)
    161 """ Normalize byteorder to '<' or '>' """
    162 # hack to obtain the native and swapped byte order characters
--> 163 swapped = np.dtype(int).newbyteorder('S')
    164 native = swapped.newbyteorder('S')
    166 byteorder = dtype.byteorder

RecursionError: maximum recursion depth exceeded while calling a Python object
dlakaplan commented 1 month ago

Hi, Matteo. This looks odd, and I cannot replicate it. I have numpy 2.0.0 and astropy 6.1.1, although my PINT is the latest pull from GitHub rather than the released version. But I can import pint with no problems. I'll see if I can grab the PINT from conda instead, but if you or anybody else can provide additional info about when this does/does not happen that would help.

dlakaplan commented 1 month ago

OK, just installed PINT 1.0.1 from pip and still don't show this issue.