Skip to content

numpy TypeError on coordinate transform (TypeError: For this input type lists must contain either int or Ellipsis) #7051

Closed

Description

@bengranett

A numpy TypeError is raised when doing a coordinate transformation on an array. This appeared with numpy v 1.14.0. The following code gives the error, copied below.
python version is 2.7
astropy version is 2.0.3

import numpy as np
import astropy
from astropy import coordinates, units

print "numpy v", np.__version__
print "astropy v", astropy.__version__

c = coordinates.SkyCoord(ra=[10, 11, 12, 13]*units.degree, dec=[41, -5, 42, 0]*units.degree)
print c.transform_to('galactic')
numpy v 1.14.0
astropy v 2.0.3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ben/.virtualenvs/test/lib/python2.7/site-packages/astropy/coordinates/sky_coordinate.py", line 482, in transform_to
    new_coord = trans(self.frame, generic_frame)
  File "/Users/ben/.virtualenvs/test/lib/python2.7/site-packages/astropy/coordinates/transformations.py", line 1314, in __call__
    curr_coord = t(curr_coord, curr_toframe)
  File "/Users/ben/.virtualenvs/test/lib/python2.7/site-packages/astropy/coordinates/transformations.py", line 1232, in __call__
    newrep = self._apply_transform(fromcoord, M, None)
  File "/Users/ben/.virtualenvs/test/lib/python2.7/site-packages/astropy/coordinates/transformations.py", line 1005, in _apply_transform
    rep = rep.transform(matrix)
  File "/Users/ben/.virtualenvs/test/lib/python2.7/site-packages/astropy/coordinates/representation.py", line 1115, in transform
    newxyz = np.einsum('...ij,j...->i...', matrix, oldxyz.value)
  File "/Users/ben/.virtualenvs/test/lib/python2.7/site-packages/numpy/core/einsumfunc.py", line 1087, in einsum
    einsum_call=True)
  File "/Users/ben/.virtualenvs/test/lib/python2.7/site-packages/numpy/core/einsumfunc.py", line 688, in einsum_path
    input_subscripts, output_subscript, operands = _parse_einsum_input(operands)
  File "/Users/ben/.virtualenvs/test/lib/python2.7/site-packages/numpy/core/einsumfunc.py", line 432, in _parse_einsum_input
    raise TypeError("For this input type lists must contain "
TypeError: For this input type lists must contain either int or Ellipsis

Activity

  1. pllim commented on Jan 8, 2018

    @pllim
    Member

    FWIW, I don't see any error using Python 3 and Astropy dev. Can you update Python and/or Astropy?

    >>> import numpy as np
    >>> import astropy
    >>> from astropy import coordinates, units
    >>> print("numpy v", np.__version__)
    numpy v 1.14.0
    >>> print("astropy v", astropy.__version__)
    astropy v 3.1.dev21142
    >>> c = coordinates.SkyCoord(ra=[10, 11, 12, 13]*units.degree, dec=[41, -5, 42, 0]*units.degree)
    >>> print(c.transform_to('galactic'))
    <SkyCoord (Galactic): (l, b) in deg
        [(120.60763058, -21.82012272), (118.02401029, -67.80084115),
         (122.24838304, -20.86718474), (123.24009635, -62.87141125)]>
  2. added
    Upstream Action Required
    on Jan 8, 2018
  3. mhvk commented on Jan 8, 2018

    @mhvk
    Contributor

    I cannot directly reproduce the error on python3 (astropy 2.0.3, numpy-dev), but can reproduce a later part:

    c.cartesian.transform(np.eye(3)[np.newaxis])
    # ValueError: ("Size of label '%s' for operand %d does not match previous terms.", 'N', 1)
    

    Or more directly proving this is an upstream problem:

    np.einsum('...ij,j...->i...', np.eye(3)[np.newaxis], np.array([[1., 1.], [2., 2.], [3., 3.]]))
    

    It is almost certainly related to numpy/numpy#10343, since I can get rid of it by passing on optimize=False.

    I labelled it upstream-fix required since the underlying problem is numpy, though if need be we probably could have a work-around.

  4. pllim commented on Jan 9, 2018

    @pllim
    Member

    Huh... Incidentally there is a numpy-dev failure at https://travis-ci.org/astropy/astropy/jobs/326547832 that also mentioned "einsum". Is that related?

  5. mzechmeister commented on Jan 11, 2018

    @mzechmeister

    I have this problem when I try get to run this http://docs.astropy.org/en/stable/time/#barycentric-and-heliocentric-light-travel-time-corrections.

    I traced it back to unicode_literals used in astropy/coordinates/builtin_frames/utils.py. Because

    from __future__ import unicode_literals
    import numpy as np
    np.einsum('...i,...i', [1,2,3], [2,3,4])

    gives the error. Without unicode_literals it runs. I figured out that immediately in the call np.einsum '...i,...i' is converted to u'...i,...i'. Maybe related to this https://lists.gt.net/python/dev/1292881.

  6. saimn commented on Jan 11, 2018

    @saimn
    Contributor

    It's a Numpy 1.14 issue, since it worked with the previous versions (I just upgraded to Numpy 1.14 in my conda py2 env and now I get the error). It should work as before with unicode_literals since the string contains only ascii characters.

    EDIT: see numpy/numpy#10369

  7. added
    🔥
    and removed on Jan 11, 2018
  8. added this to the v3.0.0 milestone on Jan 11, 2018
  9. jobovy commented on Jan 12, 2018

    @jobovy
    Contributor

    I'm getting this error using the astropy implementation of (ra,dec) -> (l,b) coordinate transformations

    https://travis-ci.org/jobovy/galpy/jobs/328214749

    Only my Python2 tests fail, Python3 all pass.

  10. mhvk commented on Jan 12, 2018

    @mhvk
    Contributor

    @jobovy - This indeed looks like the same bug, at least if you are also using numpy 1.14.

  11. jobovy commented on Jan 12, 2018

    @jobovy
    Contributor

    This is a travis build, using whatever numpy conda install numpy currently gives (can't go back and check!), but I assume this is numpy 1.14.

  12. 6 remaining items

  13. modified the milestones: v3.0.0, v2.0.4 on Jan 14, 2018
  14. mhvk commented on Jan 15, 2018

    @mhvk
    Contributor

    @bsipocz - not quite: on python3, I have a problem with

    c.cartesian.transform(np.eye(3)[np.newaxis])
    

    The fact that we don't use this internally doesn't mean it cannot get done...

  15. eteq commented on Jan 21, 2018

    @eteq
    Member

    The core question is: are we satisfied just saying astropy is "not compatible" with 1.14.0 and requires 1.14.1? It's pretty clear this is a straight-up bug in numpy (c.f. numpy/numpy#10369 / numpy/numpy#10369 numpy/numpy#10371), so saying we aren't going to address it is fairly reasonable, IMHO.

    The alternative would probably require adjusting the einsum call to do whatever set of transposes/etc are necessary to replicate the einsum. That would have both performance and readability implications that I am not too comfortable with.

    So with that in mind I think we should not make a change, and close this issue once 1.14.1 is out (and we are sure it's working). Anyone disagree?

    If we do go that route, though, we may want to hold off on the astropy 3.0 release until 1.14.1 is out... @mhvk, do you have any idea whether "end of Jan" is likely to be acheived or if we should have a backup in case not?

  16. eteq commented on Jan 21, 2018

    @eteq
    Member

    Scratch that - I realize the fix is pretty trivial (should have read #7051 (comment) more carefully) - set the optimize keyword explicitly to False only for numpy 1.14.0... See #7105 . So I take back all of #7051 (comment) and instead would say just merging #7105 is the best solution...

  17. bsipocz commented on Jan 21, 2018

    @bsipocz
    Member

    @eteq - I'm in favour of having the fix for now, as the numpy milestoning is a little bit confusing as the fix upstream is milestoned to 1.15. We can always remove the workaround if the upstream fix comes out before astropy 3.0

  18. rkpradhan commented on Jan 21, 2018

    @rkpradhan

    Can you help me? @jobovy

    import astropy.units as u
    import astropy.coordinates as coord
    icrs = coord.ICRS(ra=258.58356362u.deg, dec=14.55255619u.deg,
    ... radial_velocity=-16.1*u.km/u.s)
    Traceback (most recent call last):
    File "", line 2, in
    File "/usr/lib/python2.7/dist-packages/astropy/coordinates/baseframe.py", line 574, in init
    list(kwargs)))
    TypeError: Coordinate frame got unexpected keywords: ['radial_velocity']

  19. mhvk commented on Jan 21, 2018

    @mhvk
    Contributor

    @pythonastroM31 - this is not related to this bug -- are you sure you are using astropy version >= 2.0? (the radial_velocity was only introduced in 2.0). If so, please open a new issue and give more details about versions, etc.

  20. rkpradhan commented on Jan 21, 2018

    @rkpradhan

    @mhvk -- first of all, thank you so much. Now I have upgraded the astropy-2.0.3; again the same issue raised when I run the same code in the terminal. I am looking for conversion of phase-space coordinates from the galacto-centric frame of reference, and for calculating the values of radial, angular and azimuthal velocity from given ra, dec, d_gc etc. of CSV file data.

  21. adrn commented on Jan 21, 2018

    @adrn
    Member

    @pythonastroM31 Your question is not related to this issue. Please raise your question in a new issue, or in the astropy slack channel

  22. rkpradhan commented on Jan 21, 2018

    @rkpradhan

    @adrn Okay, my problem is related to typeError in running the program. I just run in the terminal; code like that...

    import astropy.units as u
    import astropy.coordinates as coord
    icrs = coord.ICRS(ra=258.58356362u.deg, dec=14.55255619u.deg, radial_velocity=-16.1*u.km/u.s)
    Traceback (most recent call last):
    File "", line 2, in
    File "/usr/lib/python2.7/dist-packages/astropy/coordinates/baseframe.py", line 574, in init
    list(kwargs)))
    TypeError: Coordinate frame got unexpected keywords: ['radial_velocity']

    Can you help me with this problem? How can we resolve this?

  23. mhvk commented on Jan 21, 2018

    @mhvk
    Contributor

    @pythonastroM31 - please open a new issue - it is not helpful to us to have comments about unrelated problems in this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔥BugUpstream Action Requiredcoordinates

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions