Skip to content

Commit 6387f38

Browse files
committed
Merge pull request #6848 from jreback/sort
API: make Series.sort/order arguments in the same order
2 parents 9119641 + 86bc2e3 commit 6387f38

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed

doc/source/release.rst

+7-13
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ API Changes
8686
for a Series with a ``DatetimeIndex`` or a ``PeriodIndex``; trying this on a non-supported Index type will
8787
now raise a ``TypeError``. (:issue:`4551`, :issue:`4056`, :issue:`5519`)
8888

89-
The following affected:
89+
The following are affected:
9090

9191
- ``date,time,year,month,day``
9292
- ``hour,minute,second,weekofyear``
@@ -135,26 +135,20 @@ API Changes
135135
the name of the inserted column containing the pivoted data.
136136

137137
- Allow specification of a more complex groupby, via ``pd.Grouper`` (:issue:`3794`)
138-
139138
- A tuple passed to ``DataFame.sort_index`` will be interpreted as the levels of
140139
the index, rather than requiring a list of tuple (:issue:`4370`)
141-
142140
- Fix a bug where invalid eval/query operations would blow the stack (:issue:`5198`)
143-
144141
- Following keywords are now acceptable for :meth:`DataFrame.plot` with ``kind='bar'`` and ``kind='barh'``:
145142

146143
- `width`: Specify the bar width. In previous versions, static value 0.5 was passed to matplotlib and it cannot be overwritten. (:issue:`6604`)
147-
148-
- `align`: Specify the bar alignment. Default is `center` (different from matplotlib). In previous versions, pandas passes `align='edge'` to matplotlib and adjust the location to `center` by itself, and it results `align` keyword is not applied as expected. (:issue:`4525`)
149-
144+
- `align`: Specify the bar alignment. Default is `center` (different from matplotlib). In previous versions, pandas passes `align='edge'` to
145+
matplotlib and adjust the location to `center` by itself, and it results `align` keyword is not applied as expected. (:issue:`4525`)
150146
- `position`: Specify relative alignments for bar plot layout. From 0 (left/bottom-end) to 1 (right/top-end). Default is 0.5 (center). (:issue:`6604`)
151147

152148
- Define and document the order of column vs index names in query/eval (:issue:`6676`)
153-
154149
- ``DataFrame.sort`` now places NaNs at the beginning or end of the sort according to the ``na_position`` parameter. (:issue:`3917`)
155150
- ``stack`` and ``unstack`` now raise a ``ValueError`` when the ``level`` keyword refers
156151
to a non-unique item in the ``Index`` (previously raised a ``KeyError``). (:issue:`6738`)
157-
158152
- all offset operations now return ``Timestamp`` types (rather than datetime), Business/Week frequencies were incorrect (:issue:`4069`)
159153
- ``Series.iteritems()`` is now lazy (returns an iterator rather than a list). This was the documented behavior prior to 0.14. (:issue:`6760`)
160154
- ``Panel.shift`` now uses ``NDFrame.shift``. It no longer drops the ``nan`` data and retains its original shape. (:issue:`4867`)
@@ -163,19 +157,19 @@ API Changes
163157
representation) (:issue:`6782`)
164158
- Arithmetic ops are now disallowed when passed two bool dtype Series or
165159
DataFrames (:issue:`6762`).
166-
167160
- Added ``nunique`` and ``value_counts`` functions to ``Index`` for counting unique elements. (:issue:`6734`)
168161

169162
- ``DataFrame.plot`` and ``Series.plot`` now support a ``table`` keyword for plotting ``matplotlib.Table``. The ``table`` kewyword can receive the following values.
170163

171164
- ``False``: Do nothing (default).
172-
173165
- ``True``: Draw a table using the ``DataFrame`` or ``Series`` called ``plot`` method. Data will be transposed to meet matplotlib's default layout.
174-
175166
- ``DataFrame`` or ``Series``: Draw matplotlib.table using the passed data. The data will be drawn as displayed in print method (not transposed automatically).
176-
177167
Also, helper function ``pandas.tools.plotting.table`` is added to create a table from ``DataFrame`` and ``Series``, and add it to an ``matplotlib.Axes``.
178168

169+
- drop unused order argument from ``Series.sort``; args now in the same orders as ``Series.order``;
170+
add ``na_position`` arg to conform to ``Series.order`` (:issue:`6847`)
171+
- default sorting algorithm for ``Series.order`` is not ``quicksort``, to conform with ``Series.sort``
172+
(and numpy defaults)
179173

180174
Deprecations
181175
~~~~~~~~~~~~

doc/source/v0.14.0.txt

+5-15
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ API changes
6565
for a Series with a ``DatetimeIndex`` or a ``PeriodIndex``; trying this on a non-supported Index type will
6666
now raise a ``TypeError``. (:issue:`4551`, :issue:`4056`, :issue:`5519`)
6767

68-
The following affected:
68+
The following are affected:
6969

7070
- ``date,time,year,month,day``
7171
- ``hour,minute,second,weekofyear``
@@ -208,6 +208,10 @@ API changes
208208
- Added ``nunique`` and ``value_counts`` functions to ``Index`` for counting unique elements. (:issue:`6734`)
209209
- ``stack`` and ``unstack`` now raise a ``ValueError`` when the ``level`` keyword refers
210210
to a non-unique item in the ``Index`` (previously raised a ``KeyError``).
211+
- drop unused order argument from ``Series.sort``; args now in the same orders as ``Series.order``;
212+
add ``na_position`` arg to conform to ``Series.order`` (:issue:`6847`)
213+
- default sorting algorithm for ``Series.order`` is not ``quicksort``, to conform with ``Series.sort``
214+
(and numpy defaults)
211215

212216
.. _whatsnew_0140.sql:
213217

@@ -329,20 +333,15 @@ Plotting
329333
~~~~~~~~
330334

331335
- Hexagonal bin plots from ``DataFrame.plot`` with ``kind='hexbin'`` (:issue:`5478`), See :ref:`the docs<visualization.hexbin>`.
332-
333336
- Plotting with Error Bars is now supported in the ``.plot`` method of ``DataFrame`` and ``Series`` objects (:issue:`3796`), See :ref:`the docs<visualization.errorbars>`.
334-
335337
- ``DataFrame.plot`` and ``Series.plot`` now support a ``table`` keyword for plotting ``matplotlib.Table``, See :ref:`the docs<visualization.table>`.
336-
337338
- ``plot(legend='reverse')`` will now reverse the order of legend labels for
338339
most plot kinds. (:issue:`6014`)
339340

340341
- Following keywords are now acceptable for :meth:`DataFrame.plot(kind='bar')` and :meth:`DataFrame.plot(kind='barh')`.
341342

342343
- `width`: Specify the bar width. In previous versions, static value 0.5 was passed to matplotlib and it cannot be overwritten. (:issue:`6604`)
343-
344344
- `align`: Specify the bar alignment. Default is `center` (different from matplotlib). In previous versions, pandas passes `align='edge'` to matplotlib and adjust the location to `center` by itself, and it results `align` keyword is not applied as expected. (:issue:`4525`)
345-
346345
- `position`: Specify relative alignments for bar plot layout. From 0 (left/bottom-end) to 1(right/top-end). Default is 0.5 (center). (:issue:`6604`)
347346

348347
Because of the default `align` value changes, coordinates of bar plots are now located on integer values (0.0, 1.0, 2.0 ...). This is intended to make bar plot be located on the same coodinates as line plot. However, bar plot may differs unexpectedly when you manually adjust the bar location or drawing area, such as using `set_xlim`, `set_ylim`, etc. In this cases, please modify your script to meet with new coordinates.
@@ -355,28 +354,19 @@ Prior Version Deprecations/Changes
355354
There are prior version deprecations that are taking effect as of 0.14.0.
356355

357356
- Remove :class:`DateRange` in favor of :class:`DatetimeIndex` (:issue:`6816`)
358-
359357
- Remove ``column`` keyword from ``DataFrame.sort`` (:issue:`4370`)
360-
361358
- Remove ``precision`` keyword from :func:`set_eng_float_format` (:issue:`395`)
362-
363359
- Remove ``force_unicode`` keyword from :meth:`DataFrame.to_string`,
364360
:meth:`DataFrame.to_latex`, and :meth:`DataFrame.to_html`; these function
365361
encode in unicode by default (:issue:`2224`, :issue:`2225`)
366-
367362
- Remove ``nanRep`` keyword from :meth:`DataFrame.to_csv` and
368363
:meth:`DataFrame.to_string` (:issue:`275`)
369-
370364
- Remove ``unique`` keyword from :meth:`HDFStore.select_column` (:issue:`3256`)
371-
372365
- Remove ``inferTimeRule`` keyword from :func:`Timestamp.offset` (:issue:`391`)
373-
374366
- Remove ``name`` keyword from :func:`get_data_yahoo` and
375367
:func:`get_data_google` ( `commit b921d1a <https://github.com/pydata/pandas/commit/b921d1a2>`__ )
376-
377368
- Remove ``offset`` keyword from :class:`DatetimeIndex` constructor
378369
( `commit 3136390 <https://github.com/pydata/pandas/commit/3136390>`__ )
379-
380370
- Remove ``time_rule`` from several rolling-moment statistical functions, such
381371
as :func:`rolling_sum` (:issue:`1042`)
382372

pandas/core/series.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -1563,20 +1563,22 @@ def update(self, other):
15631563
#----------------------------------------------------------------------
15641564
# Reindexing, sorting
15651565

1566-
def sort(self, axis=0, kind='quicksort', order=None, ascending=True):
1566+
def sort(self, axis=0, ascending=True, kind='quicksort', na_position='last'):
15671567
"""
15681568
Sort values and index labels by value, in place. For compatibility with
15691569
ndarray API. No return value
15701570
15711571
Parameters
15721572
----------
15731573
axis : int (can only be zero)
1574+
ascending : boolean, default True
1575+
Sort ascending. Passing False sorts descending
15741576
kind : {'mergesort', 'quicksort', 'heapsort'}, default 'quicksort'
15751577
Choice of sorting algorithm. See np.sort for more
15761578
information. 'mergesort' is the only stable algorithm
1577-
order : ignored
1578-
ascending : boolean, default True
1579-
Sort ascending. Passing False sorts descending
1579+
na_position : {'first', 'last'} (optional, default='last')
1580+
'first' puts NaNs at the beginning
1581+
'last' puts NaNs at the end
15801582
15811583
See Also
15821584
--------
@@ -1588,9 +1590,9 @@ def sort(self, axis=0, kind='quicksort', order=None, ascending=True):
15881590
raise ValueError("This Series is a view of some other array, to "
15891591
"sort in-place you must create a copy")
15901592

1591-
result = self.order(kind=kind,
1592-
ascending=ascending,
1593-
na_position='last')
1593+
result = self.order(ascending=ascending,
1594+
kind=kind,
1595+
na_position=na_position)
15941596

15951597
self._update_inplace(result)
15961598

@@ -1690,7 +1692,7 @@ def rank(self, method='average', na_option='keep', ascending=True,
16901692
ascending=ascending, pct=pct)
16911693
return self._constructor(ranks, index=self.index).__finalize__(self)
16921694

1693-
def order(self, na_last=None, ascending=True, kind='mergesort', na_position='last'):
1695+
def order(self, na_last=None, ascending=True, kind='quicksort', na_position='last'):
16941696
"""
16951697
Sorts Series object, by value, maintaining index-value link
16961698
@@ -1700,7 +1702,7 @@ def order(self, na_last=None, ascending=True, kind='mergesort', na_position='las
17001702
Put NaN's at beginning or end
17011703
ascending : boolean, default True
17021704
Sort ascending. Passing False sorts descending
1703-
kind : {'mergesort', 'quicksort', 'heapsort'}, default 'mergesort'
1705+
kind : {'mergesort', 'quicksort', 'heapsort'}, default 'quicksort'
17041706
Choice of sorting algorithm. See np.sort for more
17051707
information. 'mergesort' is the only stable algorithm
17061708
na_position : {'first', 'last'} (optional, default='last')

0 commit comments

Comments
 (0)