You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Accessing astropy.table.Column.quantity always performs an expensive deepcopy of the .info object, although this information can't even be accessed on temporary objects:
In [19]: t['a'].quantity.info
...
AttributeError: failed to access "info" attribute on a temporary object.
So something that is expensive is done also in cases where it can never actually be usefull, e.g. in situations like:
c = t['a'].quantity + b
Expected behavior
Perform expensive operations only when actually needed.
Actual behavior
DataInfo.__set__ is called which performs expensive, not needed operations.
It is not really a bug, and certainly the equivalent is used for changing columns from aTable to quantities in a QTable. But I can see it is annoying. In principle, I guess one could change the implementation to Quantity(col.data, unit=col.unit, dtype=col.dtype, copy=False, order="A", subok=True) -- it is unlikely there are many cases where people rely on .info being set when they do col.quantity.
I wonder, though, why this comes up, as the presence of .quantity was really most to work-around the fact that Quantity could originally not be part of a Table. QTable does not have this restriction; is there a reason not to use that instead?
We had some issues related to metadata access when using pure tables, not QTable, let me dig that up. If using QTable solves that, we should probably just switch to using QTable.
Using a qtable is still somehow slower than using the pure table column, although the units are handled correctly and a quantity is returned by the pure column operation.
In [4]: %timeit qt['a'] + b
15.4 µs ± 475 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
In [5]: %timeit t['a'] + b
5.8 µs ± 31.9 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
Ah, I see, so b is a Quantity. I checked and the difference is actually related to this issue: qt['a'] + b copies info and stores it on the result. Which seems a bug: after the addition, the name, etc., really shouldn't be kept! See #14248 and actually also the much older #5047.
Coming back to the topic of this PR, I think that in doing col.quantity a user really would not generally expect that the name and description of a column would be preserved, so that it would be fine to change the implementation to be the faster Quantity(col.data, unit=col.unit, dtype=col.dtype, copy=False, order="A", subok=True) I suggested above. My only question really is whether it is worth it... Let me ping @taldcroft for suggestions.
Activity
mhvk commentedon Jan 2, 2023
It is not really a bug, and certainly the equivalent is used for changing columns from a
Tableto quantities in aQTable. But I can see it is annoying. In principle, I guess one could change the implementation toQuantity(col.data, unit=col.unit, dtype=col.dtype, copy=False, order="A", subok=True)-- it is unlikely there are many cases where people rely on.infobeing set when they docol.quantity.I wonder, though, why this comes up, as the presence of
.quantitywas really most to work-around the fact thatQuantitycould originally not be part of aTable.QTabledoes not have this restriction; is there a reason not to use that instead?maxnoe commentedon Jan 3, 2023
We had some issues related to metadata access when using pure tables, not QTable, let me dig that up. If using
QTablesolves that, we should probably just switch to usingQTable.maxnoe commentedon Jan 3, 2023
Using a qtable is still somehow slower than using the pure table column, although the units are handled correctly and a quantity is returned by the pure column operation.
mhvk commentedon Jan 3, 2023
But in a pure table, you presumably have an actual
Column, so the unit is ignored, which would naturally make it faster.maxnoe commentedon Jan 3, 2023
No, the unit is not ignored, it also works with the column in deg and the other quantity in rad, giving the correct result.
mhvk commentedon Jan 3, 2023
Ah, I see, so
bis aQuantity. I checked and the difference is actually related to this issue:qt['a'] + bcopiesinfoand stores it on the result. Which seems a bug: after the addition, thename, etc., really shouldn't be kept! See #14248 and actually also the much older #5047.mhvk commentedon Jan 4, 2023
So at least the slowdown you found in #14244 (comment) should be addressed by #14253
mhvk commentedon Jan 5, 2023
#14253 is merged. Hopefully this removes one disadvantage of
QTable!mhvk commentedon Jan 6, 2023
Coming back to the topic of this PR, I think that in doing
col.quantitya user really would not generally expect that the name and description of a column would be preserved, so that it would be fine to change the implementation to be the fasterQuantity(col.data, unit=col.unit, dtype=col.dtype, copy=False, order="A", subok=True)I suggested above. My only question really is whether it is worth it... Let me ping @taldcroft for suggestions.