@@ -2813,19 +2813,35 @@ def hist_frame(data, column=None, weights=None, by=None, grid=True,
2813
2813
kwds : other plotting keyword arguments
2814
2814
To be passed to hist function
2815
2815
"""
2816
-
2817
2816
if by is not None :
2818
2817
axes = grouped_hist (data , column = column , weights = weights , by = by , ax = ax , grid = grid , figsize = figsize ,
2819
2818
sharex = sharex , sharey = sharey , layout = layout , bins = bins ,
2820
2819
xlabelsize = xlabelsize , xrot = xrot , ylabelsize = ylabelsize , yrot = yrot ,
2821
2820
** kwds )
2822
2821
return axes
2823
2822
2823
+ inx_na = np .zeros (len (data ), dtype = bool )
2824
+ if weights is not None :
2825
+ # first figure out if given my column name, or by an array
2826
+ if isinstance (weights , str ):
2827
+ weights = data [weights ]
2828
+ if isinstance (weights , np .ndarray ) == False :
2829
+ weights = weights .values
2830
+ # remove fields where we have nan in weights OR in group
2831
+ # for both data sets
2832
+ inx_na = (np .isnan (weights ))
2833
+
2824
2834
if column is not None :
2825
2835
if not isinstance (column , (list , np .ndarray , Index )):
2826
2836
column = [column ]
2827
2837
data = data [column ]
2828
2838
data = data ._get_numeric_data ()
2839
+ inx_na |= np .isnan (data .T .values )[0 ]
2840
+
2841
+ data = data .ix [~ inx_na ]
2842
+ if weights is not None :
2843
+ weights = weights [~ inx_na ]
2844
+
2829
2845
naxes = len (data .columns )
2830
2846
2831
2847
fig , axes = _subplots (naxes = naxes , ax = ax , squeeze = False ,
@@ -2835,7 +2851,7 @@ def hist_frame(data, column=None, weights=None, by=None, grid=True,
2835
2851
2836
2852
for i , col in enumerate (com ._try_sort (data .columns )):
2837
2853
ax = _axes [i ]
2838
- ax .hist (data [col ].dropna (). values , bins = bins , ** kwds )
2854
+ ax .hist (data [col ].values , bins = bins , weights = weights , ** kwds )
2839
2855
ax .set_title (col )
2840
2856
ax .grid (grid )
2841
2857
@@ -3063,17 +3079,22 @@ def _grouped_plot(plotf, data, column=None, weights=None, by=None,
3063
3079
"size by tuple instead" , FutureWarning , stacklevel = 4 )
3064
3080
figsize = None
3065
3081
3082
+ added_weights_dummy_column = False
3066
3083
if isinstance (weights , np .ndarray ):
3067
3084
# weights supplied as an array instead of a part of the dataframe
3068
3085
data ['weights' ] = weights
3069
3086
weights = 'weights'
3087
+ added_weights_dummy_column = True
3070
3088
3071
3089
grouped = data .groupby (by )
3072
3090
if column is not None :
3073
3091
if weights is not None :
3074
3092
weights = grouped [weights ]
3075
3093
grouped = grouped [column ]
3076
3094
3095
+ if added_weights_dummy_column :
3096
+ data = data .drop ('weights' , axis = 1 )
3097
+
3077
3098
naxes = len (grouped )
3078
3099
fig , axes = _subplots (naxes = naxes , figsize = figsize ,
3079
3100
sharex = sharex , sharey = sharey , ax = ax ,
0 commit comments