Skip to content

BUG: make Series.sort_values(ascending=[False]) behave as ascending=False (#15604) #15607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

MLopez-Ibanez
Copy link

@@ -1722,6 +1723,12 @@ def _try_kind_sort(arr):

argsorted = _try_kind_sort(arr[good])

if is_sequence(ascending):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, how about is_list_like is our general purpose list-detector.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me, I was following the code in frame.py. Should I change and rebase?

raise ValueError('Length of ascending (%d) cannot be larger '
'than 1 for Series' % (len(ascending)))
ascending = ascending[0]

if not ascending:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then do:

if not is_bool(ascending):
   raise ValueError(....)

@@ -1722,6 +1723,12 @@ def _try_kind_sort(arr):

argsorted = _try_kind_sort(arr[good])

if is_sequence(ascending):
if len(ascending) > 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(ascending) != 1

assert_almost_equal(expected, ordered.valid().values)
ordered = ts.sort_values(ascending=[False], na_position='first')
assert_almost_equal(expected, ordered.valid().values)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you test a couple of invalid ones that they raise (e.g. [], [1, 2, 3], [False, False, False], 'foobar', None

(ascending=None) is technically invalid.

@jreback
Copy link
Contributor

jreback commented Mar 7, 2017

bit more testing / validation & please add a whatsnew note. ping when green.

@jreback jreback added Bug Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Mar 7, 2017
@MLopez-Ibanez
Copy link
Author

All fixed hopefully. There is already a whatsnew line added. Is it the wrong file?

@jreback
Copy link
Contributor

jreback commented Mar 7, 2017

no whatsnew is good (I may have been looking at something else). lgtm. ping on green.

@jreback jreback added this to the 0.20.0 milestone Mar 7, 2017
@MLopez-Ibanez
Copy link
Author

Sorry, it is my first patch ever here. What is green? How do I ping? The contributors document does not say.

@@ -64,6 +64,24 @@ def test_sort_values(self):
ordered = ts.sort_values(ascending=False, na_position='first')
assert_almost_equal(expected, ordered.valid().values)

# ascending=[False] should behave the same as ascending=False
ordered = ts.sort_values(ascending=[False])
expected = np.sort(ts.valid().values)[::-1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry didn't notice this. Can you construct the result series and use tm.assert_series_equal for both of these. (literally construct it, don't sort things)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate? I don't understand what you mean by constructing literally. Do you want me to create an example series for expected and then compare with ordered instead of creating it via np.sort? If you want to avoid NumPy, wouldn't it be better to simply compare the results of ascending=False and ascending=[False] to be _series_equal?

@jreback
Copy link
Contributor

jreback commented Mar 7, 2017

@MLopez-Ibanez another comment above.

See those 'pending checks', when the CI runs those will eventually turn green (or red if there is an error).

pinging is when everything is green, just say hey all green. (or really when you need a review if someone doesn't do it first).

@codecov-io
Copy link

Codecov Report

Merging #15607 into master will decrease coverage by -0.04%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master   #15607      +/-   ##
==========================================
- Coverage   91.03%      91%   -0.04%     
==========================================
  Files         137      143       +6     
  Lines       49309    49301       -8     
==========================================
- Hits        44887    44864      -23     
- Misses       4422     4437      +15
Impacted Files Coverage Δ
pandas/core/series.py 94.91% <100%> (+0.01%)
pandas/io/gbq.py 25% <0%> (-58.34%)
pandas/util/depr_module.py 78.94% <0%> (-9.95%)
pandas/tools/merge.py 91.76% <0%> (-0.36%)
pandas/tseries/common.py 89.15% <0%> (-0.13%)
pandas/core/frame.py 97.87% <0%> (-0.1%)
pandas/tseries/tdi.py 90.23% <0%> (-0.08%)
pandas/core/missing.py 84.9% <0%> (-0.05%)
pandas/tseries/tools.py 84.89% <0%> (-0.05%)
pandas/core/ops.py 91.66% <0%> (-0.05%)
... and 38 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c52ff68...6678574. Read the comment docs.

@MLopez-Ibanez
Copy link
Author

@jreback Hey all green!

@jreback jreback closed this in c9d4e0b Mar 8, 2017
@jreback
Copy link
Contributor

jreback commented Mar 8, 2017

thanks @MLopez-Ibanez

keep em coming!

AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this pull request Mar 21, 2017
…alse (pandas-dev#15604)

closes pandas-dev#15604

Author: manu <[email protected]>

Closes pandas-dev#15607 from MLopez-Ibanez/series-ascending and squashes the following commits:

6678574 [manu] BUG: make Series.sort_values(ascending=[False]) behave as ascending=False (pandas-dev#15604)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pandas.Series.sort_values(ascending=[False]) behaves as ascending=True
3 participants