Closed Theodlz closed 1 year ago
Hi Theo, Could you please specify what Python version you are using when it's not working? It is supposed to be an "official" way of checking whether the key is in the dictionary, so I'd prefer not to change it except they made some backward-incompatible change in the language
Hi @karpov-sv.
So the object is an astropy table, and not a dictionary.
The issue comes from astropy I believe. As you said, you can check if a key is in a dictionary using this syntax, however it does give me an error with astropy, here's an example (it's the same error that I get with thenget_object_sextractor
method:
>>> from astropy.table import QTable
>>> import astropy.units as u
>>> import numpy as np
>>> a = np.array([1, 4, 5], dtype=np.int32)
>>> b = [2.0, 5.0, 8.5]
>>> c = ['x', 'y', 'z']
>>> d = [10, 20, 30] * u.m / u.s
>>> t = QTable([a, b, c, d], names=('a', 'b', 'c', 'd'), meta={'name': 'first table'})
>>> t
<QTable length=3>
a b c d
m / s
int32 float64 str1 float64
----- ------- ---- -------
1 2.0 x 10.0
4 5.0 y 20.0
5 8.5 z 30.0
>>> 'a' in t
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/theodlz/.local/lib/python3.10/site-packages/astropy/table/row.py", line 76, in __eq__
return self.as_void() == other
TypeError: Cannot compare structured or void to non-void arrays.
but if I do:
>>> 'a' in t.keys()
True
it does work. I'm pretty sure this is retro compatible. If you have an older install of astropy, maybe you can run the code with this modification and see if it still works?
I'm using astropy astropy==5.1.1
, which is now a requirement for SkyPortal.
By the way, you were already using that above the line I modified, line 410 I believe
Yes, indeed you are right, that's not a dict there. Sorry for confusion! Merged it.
Hi @karpov-sv!
I've been working on integrating stdpipe with SkyPortal (https://github.com/skyportal/skyportal) and the
get_objects_sextractor
has been giving me errors consistently.This was working just fine about a month and a half ago. I guess that some changes made to newer versions of astropy or even python (those are 2 things I updated since then) could have broken it.
This ver minor change should fix it.
Thanks!