Skip to content

Commit f767320

Browse files
committed
Move feature test to new method, add to whatsnew
Also fix minor bug due to a misnamed var that both the test and pyflakes missed
1 parent 377f360 commit f767320

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ Other Enhancements
366366
- ``pandas.io.json.json_normalize()`` with an empty ``list`` will return an empty ``DataFrame`` (:issue:`15534`)
367367
- ``pandas.io.json.json_normalize()`` has gained a ``sep`` option that accepts ``str`` to separate joined fields; the default is ".", which is backward compatible. (:issue:`14883`)
368368
- ``pd.read_csv()`` will now raise a ``csv.Error`` error whenever an end-of-file character is encountered in the middle of a data row (:issue:`15913`)
369+
- ``parallel_coordinates()`` now has a ``sort_labels`` keyword arg that sorts class labels and the colours assigned to them (:issue:`15908`)
369370

370371

371372
.. _ISO 8601 duration: https://en.wikipedia.org/wiki/ISO_8601#Durations

pandas/tests/plotting/test_misc.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,16 @@ def test_parallel_coordinates(self):
241241
with tm.assert_produces_warning(FutureWarning):
242242
parallel_coordinates(df, 'Name', colors=colors)
243243

244+
def test_parallel_coordinates_with_sorted_labels(self):
245+
""" For #15908 """
246+
from pandas.tools.plotting import parallel_coordinates
247+
244248
df = DataFrame({"feat": [i for i in range(30)],
245249
"class": [2 for _ in range(10)] +
246250
[3 for _ in range(10)] +
247251
[1 for _ in range(10)]})
248252
ax = parallel_coordinates(df, 'class', sort_labels=True)
249-
polylines, lables = ax.get_legend_handles_labels()
253+
polylines, labels = ax.get_legend_handles_labels()
250254
color_label_tuples = \
251255
zip([polyline.get_color() for polyline in polylines], labels)
252256
ordered_color_label_tuples = sorted(color_label_tuples,

pandas/tools/plotting.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,11 @@ def parallel_coordinates(frame, class_column, cols=None, ax=None, color=None,
719719
If true, vertical lines will be added at each xtick
720720
axvlines_kwds: keywords, optional
721721
Options to be passed to axvline method for vertical lines
722-
sort_labels: bool, optional
722+
sort_labels: bool, False
723723
Sort class_column labels, useful when assigning colours
724+
725+
.. versionadded:: 0.20.0
726+
724727
kwds: keywords
725728
Options to pass to matplotlib plotting method
726729
@@ -779,6 +782,7 @@ def parallel_coordinates(frame, class_column, cols=None, ax=None, color=None,
779782

780783
if sort_labels is True:
781784
classes = sorted(classes)
785+
color_values = sorted(color_values)
782786
colors = dict(zip(classes, color_values))
783787

784788
for i in range(n):

0 commit comments

Comments
 (0)