Skip to content

Commit

Permalink
Handle a mixture that includes pandas objects with non-default index
Browse files Browse the repository at this point in the history
Fixes #1867
  • Loading branch information
mwaskom committed Dec 22, 2019
1 parent 66191d8 commit 78a942d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/releases/v0.9.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Bug fixes and adpatations

- Fixed a bug when setting the rotation of x tick labels on a :class:`FacetGrid`.

- Fixed a bug where values would be excluded from categorical plots when only one variable was a pandas ``Series`` with a non-default index.

- Fixed a bug when using ``Series`` objects as arguments for ``x_partial`` or ``y_partial`` in :func:`regplot`.

- Fixed a bug when passing a ``norm`` object and using color annotations in :func:`clustermap`.
Expand Down
6 changes: 5 additions & 1 deletion seaborn/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,11 @@ def _group_longform(self, vals, grouper, order):
"""Group a long-form variable by another with correct order."""
# Ensure that the groupby will work
if not isinstance(vals, pd.Series):
vals = pd.Series(vals)
if isinstance(grouper, pd.Series):
index = grouper.index
else:
index = None
vals = pd.Series(vals, index=index)

# Group the val data
grouped_vals = vals.groupby(grouper)
Expand Down
6 changes: 6 additions & 0 deletions seaborn/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ def test_single_long_direct_inputs(self):
nt.assert_is(p.value_label, None)
nt.assert_is(p.group_label, None)

# Test array and series with non-default index
x = pd.Series([1, 1, 1, 1], index=[0, 2, 4, 6])
y = np.array([1, 2, 3, 4])
p.establish_variables(x, y)
assert len(p.plot_data[0]) == 4

def test_single_long_indirect_inputs(self):

p = cat._CategoricalPlotter()
Expand Down

0 comments on commit 78a942d

Please sign in to comment.