PatrikHlobil / Pandas-Bokeh

Bokeh Plotting Backend for Pandas and GeoPandas

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

plot_bokeh()/plot() methods don't work with Float32/Float64 types introduced in Pandas 1.2.0+

lordsutch opened this issue · comments

Pandas has introduced new Float32/Float64 (capitalized) datatypes in Pandas 1.2.0 that are similar to the Int64 datatype introduced a few releases ago that permit the use of the common 'pd.NA' value for missing data. Unfortunately plotting a series or dataframe with a Float32 or Float64 column results in an exception as follows:

/usr/local/lib/python3.9/site-packages/pandas_bokeh/plot.py in plot(df_in, x, y, kind, figsize, use_index, title, legend, logx, logy, xlabel, ylabel, xticks, yticks, xlim, ylim, fontsize_title, fontsize_label, fontsize_ticks, fontsize_legend, color, colormap, category, histogram_type, stacked, weights, bins, normed, cumulative, show_average, plot_data_points, plot_data_points_size, number_format, disable_scientific_axes, show_figure, return_html, panning, zooming, sizing_mode, toolbar_location, hovertool, hovertool_string, rangetool, vertical_xlabel, x_axis_location, webgl, reuse_plot, **kwargs)
416 f"Could not find '{col}' in the columns of the provided DataFrame/Series. Please provide for the parameter either a column name of the DataFrame/Series or an array of the same length."
417 )
--> 418 if np.issubdtype(df[col].dtype, np.number):
419 data_cols.append(col)
420 if len(data_cols) == 0:

/usr/local/lib/python3.9/site-packages/numpy/core/numerictypes.py in issubdtype(arg1, arg2)
386 """
387 if not issubclass_(arg1, generic):
--> 388 arg1 = dtype(arg1).type
389 if not issubclass_(arg2, generic):
390 arg2 = dtype(arg2).type

TypeError: Cannot interpret 'Float64Dtype()' as a data type

Casting the column(s) using the .astype() method works around the issue.

HI @lordsutch ,

thanks for reporting this bug. Obvioulsy, one has to change the check for numbers here because I do not like to implicit convert a datatype here.

Best Patrik

Hallo @lordsutch ,

the bug should be fixed with the newly released version 0.5.4. Could you please try it out and close the issue if the fix is fine.

Best Patrik

@PatrikHlobil - Yes, the issue seems to be fixed now, thanks!

Chris