Skip to content

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented May 24, 2014

#7096 returns incorrect dict when number of columns and subplots are different.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pandas.util.testing as tm


n=100
gender = tm.choice(['Male', 'Female'], size=n)
classroom = tm.choice(['A', 'B', 'C'], size=n)

df = pd.DataFrame({'gender': gender,
                          'classroom': classroom,
                          'height': np.random.normal(66, 4, size=n),
                          'weight': np.random.normal(161, 32, size=n),
                          'category': np.random.randint(4, size=n)})

df.boxplot(by='classroom', return_type='axes')
# {'category': array([<matplotlib.axes.AxesSubplot object at 0x104700e90>,
#        <matplotlib.axes.AxesSubplot object at 0x10671ca90>], dtype=object),
#  'height': array([<matplotlib.axes.AxesSubplot object at 0x106744dd0>,
#        <matplotlib.axes.AxesSubplot object at 0x106766b50>], dtype=object)}

# This must be a dict with 3 keys ('category', 'height' and 'weight') which value is AxesSubplot (not numpy.array).

Also, boxplot sometimes return OrderedDict and sometimes dict inconsistently.

df.boxplot(by='classroom', return_type='dict')
# OrderedDict([('category', {'medians': [<matplotlib.lines.Line2D object at 0x106fe8c10>,
# ...

The fix makes boxplot to always return OrderedDict which has correct mapping of keys and values

@jorisvandenbossche
Copy link
Member

@TomAugspurger

@jreback jreback added this to the 0.14.1 milestone May 25, 2014
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be compat.OrderedDict(d) if we want to always return an OrderedDict.

@TomAugspurger
Copy link
Contributor

Just that one comment. Returning a dict vs. an OrderedDict doesn't really matter in that case, and I don't have a strong preference either way. Everything else looks fine.

@jorisvandenbossche jorisvandenbossche modified the milestones: 0.14.0, 0.14.1 May 27, 2014
@jreback
Copy link
Contributor

jreback commented May 27, 2014

@TomAugspurger is this for 0.14.0?

jreback added a commit that referenced this pull request May 27, 2014
BUG: boxplot returns incorrect dict
@jreback jreback merged commit 9c92636 into pandas-dev:master May 27, 2014
@jreback
Copy link
Contributor

jreback commented May 27, 2014

I see, ok for 0.14.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants