Skip to content

BUG: grouped hist raises AttributeError with single group #7234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2014

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented May 24, 2014

Includes 3 minor fixes for hist.

  • DataFrame.hist raises AttributeError when the target column specifiedwith by kw only contains a single value.
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)
single = tm.choice(['S'], size=n)

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

df.hist(by='single')
# AttributeError: 'AxesSubplot' object has no attribute 'ravel'
  • hist can accept rot kw only when by is specified, but rot actually does nothing. I understand rot value should be used for xticklabels rotation if xrot is not specified?
df.hist(rot=45)
# AttributeError: Unknown property rot
# -> This is OK because we can use xrot kw

df.hist(by='classroom', rot=45)
# It raises no error, but ticks are NOT rotated.
  • hist always displays xticklabels on all axes even if specifying sharex=True. Other plots only draws xticklabels on bottom axes if sharex is True.

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

jreback commented May 30, 2014

@TomAugspurger ?

@TomAugspurger
Copy link
Contributor

For me, df.hist(by='classroom', rot=45) does rotate the xlabels.

I'd say rot should be a synonym for xrot in hist. If you one of them, use that for thexticklabels. If you see both raise aValueError. Make sure it's consistent forhist_frame,hist_series, andgrouped_hist`.

@@ -2643,6 +2618,7 @@ def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,

def grouped_hist(data, column=None, by=None, ax=None, bins=50, figsize=None,
layout=None, sharex=False, sharey=False, rot=90, grid=True,
xlabelsize=None, xrot=None, ylabelsize=None, yrot=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably don't need both rot and xrot in the function signature.

I'd just keep it as rot (even though its inconsistent with hist), and in the function body check

xrot = kwargs.get('xrot') or rot

@sinhrks
Copy link
Member Author

sinhrks commented May 31, 2014

Strange. The latest master seems to output following result, and both grouped_hist and _grouped_plot doesn't have rot logic. I'm not sure on what part xticks can be rotated in current code.

axes = df.hist(by='classroom', rot=30)

figure_1

Whatever, how about remove rot fix from this PR? I only cared to get grouped_hist worked assuming it is a special case of grouped_hist. To make plot functions consistent, it is better to use same logic as theplot and boxplot (not only hist). I'll open separate issue once organized.

@jreback
Copy link
Contributor

jreback commented Jul 6, 2014

@sinhrks pls rebase

@jreback
Copy link
Contributor

jreback commented Jul 7, 2014

this looks ok, @TomAugspurger ?

@jreback jreback merged commit 647a7c4 into pandas-dev:master Jul 7, 2014
@sinhrks sinhrks deleted the histbug branch July 9, 2014 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants