Skip to content

Table sort with a tuple of keys - #4671

Merged
taldcroft merged 4 commits into
astropy:masterfrom
saimn:table-sort-with-tuple
Apr 12, 2016
Merged

taldcroft merged 4 commits into
astropy:masterfrom
saimn:table-sort-with-tuple

Conversation

@saimn

@saimn saimn commented Mar 7, 2016

Copy link
Copy Markdown
Contributor

Currently Table.sort works only with a list of keys, so I changed the test to include the possibility to pass a tuple:

t.sort(('a', 'b'))

This is a simple fix for a simple issue, but I wonder if it makes sense to support any kind of iterable (with utils.isiterable), or to do the same as Table.argsort (which is called by sort), i.e. changing the test to convert the argument to a list if it is a string (and btw it supports any iterable) ?

cc @taldcroft

@pllim pllim added the table label Mar 7, 2016
@astrofrog

Copy link
Copy Markdown
Member

+1 to allowing any iterable

Use the same test as Table.argsort to convert keys to a list if a string is
passed. Otherwise no assumption is made on keys and it can be any iterable.
@saimn

saimn commented Mar 23, 2016

Copy link
Copy Markdown
Contributor Author

@astrofrog - I changed the test to allow any iterable, the same as Table.argsort.

@saimn saimn closed this Mar 24, 2016
@saimn saimn reopened this Mar 24, 2016
@saimn

saimn commented Mar 24, 2016

Copy link
Copy Markdown
Contributor Author

Appveyor failed to install conda, restarting the build.

@saimn

saimn commented Apr 12, 2016

Copy link
Copy Markdown
Contributor Author

Up, @astrofrog @taldcroft ?
Seems straightforward ;)

@pllim

pllim commented Apr 12, 2016

Copy link
Copy Markdown
Member

Needs a change log -- perhaps under "new feature" for 1.2?

@taldcroft

Copy link
Copy Markdown
Member

@saimn - you should update the doc strings for sort and argsort to indicate that key can be a string, list or tuple. But for instance a numpy array of column names doesn't work.

In theory one could make the input side a bit more tolerant by doing key = list(key) after the check for key being a string. That's your call, I'm never sure how far to go with allowing any kind of sequence as an input (including e.g. a dict) since that might mask a bug in the calling code.

@saimn

saimn commented Apr 12, 2016

Copy link
Copy Markdown
Contributor Author

@taldcroft - About the docstring, it seems redundant to specify 'tuple of str'. The current 'str or list of str' seems enough to me.
Otherwise I agree with you it is sometimes difficult to know where to put the limits (i.e. should we try to convert to list ?), the important being to be consistent, and to follow common usages: in this case tuple and list are very similar, numpy.sort allows both (and its docstring mentions only 'str or list of str') but not ndarray, Table.argsort rely on Table.__getitem__ which will allow only tuple and list. So I would stay with the current changes, which seems to be the good compromise.

@saimn

saimn commented Apr 12, 2016

Copy link
Copy Markdown
Contributor Author

Added changelog in 1.2 as suggested by @pllim

@taldcroft
taldcroft merged commit 37a2563 into astropy:master Apr 12, 2016
@taldcroft

Copy link
Copy Markdown
Member

@saimn - fair enough. Thanks!

@saimn
saimn deleted the table-sort-with-tuple branch April 12, 2016 14:31
@astrofrog astrofrog added this to the v1.2.0 milestone May 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants