Skip to content

Commit ea2d89e

Browse files
committed
More test cases. Clarify whatnew w/ example.
1 parent f43ab2e commit ea2d89e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

doc/source/whatsnew/v0.19.0.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,13 @@ Other enhancements
229229
- ``pd.read_html()`` has gained support for the ``decimal`` option (:issue:`12907`)
230230
- A top-level function :func:`union_categorical` has been added for combining categoricals, see :ref:`Unioning Categoricals<categorical.union>` (:issue:`13361`)
231231
- ``Series`` has gained the properties ``.is_monotonic``, ``.is_monotonic_increasing``, ``.is_monotonic_decreasing``, similar to ``Index`` (:issue:`13336`)
232-
- ``DataFrame.sort_values()`` has gained `axis=1` support to re-order columns with `by=index_label` (:issue:`10806`)
232+
- ``DataFrame`` has gained support to re-order the columns based on the values in a row using ``df.sort_values(by='index_label', axis=1)`` (:issue:`10806`)
233+
234+
.. ipython:: python
235+
236+
df = pd.DataFrame({'A': [2, 7], 'B': [3, 5], 'C': [4, 8]},
237+
index=['row1', 'row2'])
238+
df.sort_values(by='row2', axis=1)
233239

234240
.. _whatsnew_0190.api:
235241

pandas/tests/frame/test_sorting.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_sort_values(self):
125125
expected = frame.reindex(columns=['C', 'B', 'A'])
126126
assert_frame_equal(sorted_df, expected)
127127

128-
sorted_df = frame.sort_values(by=[1, 2], axis=1)
128+
sorted_df = frame.sort_values(by=[1, 2], axis='columns')
129129
expected = frame.reindex(columns=['B', 'A', 'C'])
130130
assert_frame_equal(sorted_df, expected)
131131

@@ -150,6 +150,11 @@ def test_sort_values_inplace(self):
150150
expected = frame.sort_values(by='A')
151151
assert_frame_equal(sorted_df, expected)
152152

153+
sorted_df = frame.copy()
154+
sorted_df.sort_values(by=1, axis=1, inplace=True)
155+
expected = frame.sort_values(by=1, axis=1)
156+
assert_frame_equal(sorted_df, expected)
157+
153158
sorted_df = frame.copy()
154159
sorted_df.sort_values(by='A', ascending=False, inplace=True)
155160
expected = frame.sort_values(by='A', ascending=False)
@@ -196,6 +201,10 @@ def test_sort_nan(self):
196201
sorted_df = df.sort_values(['A'], na_position='first', ascending=False)
197202
assert_frame_equal(sorted_df, expected)
198203

204+
expected = df.reindex(columns=['B', 'A'])
205+
sorted_df = df.sort_values(by=1, axis=1, na_position='first')
206+
assert_frame_equal(sorted_df, expected)
207+
199208
# na_position='last', order
200209
expected = DataFrame(
201210
{'A': [1, 1, 2, 4, 6, 8, nan],

0 commit comments

Comments
 (0)