Skip to content

Sorting table with Time column fails #8068

Closed

Description

@mwcraig

Trying to sort a table with a time column fails:

from astropy.time import Time
from astropy.table import Table
from astropy.coordinates import EarthLocation
t = Table()
t['a'] = Time([100.0, 200.0], scale='tt', format='mjd',
              location=EarthLocation(-2446354, 4237210, 4077985, unit='m'))
t['b'] = [3, 1]
t.sort('b')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-60-186ab71ceb04> in <module>()
      6               location=EarthLocation(-2446354, 4237210, 4077985, unit='m'))
      7 t['b'] = [3, 1]
----> 8 t.sort('b')

~/conda-main/envs/ipyfits/lib/python3.6/site-packages/astropy/table/table.py in sort(self, keys)
   2475 
   2476         for col in self.columns.values():
-> 2477             col[:] = col.take(indexes, axis=0)
   2478 
   2479         if sort_index is not None:

TypeError: 'Time' object does not support item assignment

(Apologies if all of the issues I'm opening here are known issues or the expected behavior)

Activity

  1. taldcroft commented on Nov 3, 2018

    @taldcroft
    Member

    Is this for master? It should be working, and that's what I see:

    In [6]: from astropy.time import Time
       ...: from astropy.table import Table
       ...: from astropy.coordinates import EarthLocation
       ...: t = Table()
       ...: t['a'] = Time([100.0, 200.0], scale='tt', format='mjd',
       ...:               location=EarthLocation(-2446354, 4237210, 4077985, unit='m'))
       ...: t['b'] = [3, 1]
       ...: t.sort('b')
       ...:               
    
    In [7]: t
    Out[7]: 
    <Table length=2>
      a      b  
    object int64
    ------ -----
     200.0     1
     100.0     3
    
  2. mwcraig commented on Nov 4, 2018

    @mwcraig
    MemberAuthor

    Sorry, forgot to check both master and the latest release. Looks like it is fixed in master, broken in 3.0.5, so feel free to close.

  3. mwcraig commented on Nov 4, 2018

    @mwcraig
    MemberAuthor

    @taldcroft -- one question about this one...sorting by a Time column fails in LTS. Is this a fix that should be backported?

  4. bsipocz commented on Nov 4, 2018

    @bsipocz
    Member

    @mwcraig - I suspect it's not, I vaguely remember the sorting is relying on a new feature/API change added after the LTS (but somehow cannot find the PRs now).

  5. taldcroft commented on Nov 4, 2018

    @taldcroft
    Member

    Yes sorting relies on Time being mutable which is a new feature of 3.1!

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions