Code Monkey home page Code Monkey logo

Comments (1)

larsrinn avatar larsrinn commented on June 18, 2024

I posted the same issue on the bokeh repository not knowing that bokeh.charts was moved here. For the sake of completeness and because I found a workaround, I'm going to repost it here:

Using any of the bokeh.charts classes on a pandas DataFrame as source, I get an TypeError, if one of the axes is timezone aware. However, it works fine with timezone naive axes. I solved the issue for myself by removing the timezone information manually. However, you need to pay attention to use tz_localize(None) in order to not convert the timestamps to UTC when making it unaware (as shown in the minimum not working example below).

ALL software version info (bokeh, python, notebook, OS, browser, any other relevant packages)

Python 3.5.3 and 3.6.0
Bokeh 0.12.5
Pandas 0.19.2 and 0.20.2
Windows 10
Tried notebooks:

  • Cauldron 0.0.31
  • Jupyter 4.3.1

Description of expected behavior and the observed behavior

I expected there would be no difference whether a DataFrame column is aware or naive of the timezone. If it is naive, it works fine. If it is time zone aware, I get the TypeError "data type not understood"

Complete, minimal, self-contained example code that reproduces the issue

import pandas as pd
from bokeh.charts import Scatter # also tried with Line. I guess the issue is more fundamental

rng = pd.date_range('1/1/2017', periods=4, freq='H', tz='Europe/Berlin')
df = pd.DataFrame(
    {'value': [1, 2, 3, 4]},
    index=rng
)
df.index.set_names('time', inplace=True)
df.reset_index(inplace=True)

# df.time = df.time.dt.tz_localize(None) # uncommenting this line "fixes" the issue
Scatter(df, x='time', y='value')

Stack traceback and/or browser JavaScript console output

TypeError                                 Traceback (most recent call last)
<ipython-input-3-b296041eae00> in <module>()
     11 
     12 # df.time = df.time.dt.tz_localize(None)
---> 13 Line(df, x='time', y='value')

Anaconda3\lib\site-packages\bokeh\charts\builders\line_builder.py in Line(data, x, y, **kws)
     88     kws['x'] = x
     89     kws['y'] = y
---> 90     return create_and_build(LineBuilder, data, **kws)
     91 
     92 

Anaconda3\lib\site-packages\bokeh\charts\builder.py in create_and_build(builder_class, *data, **kws)
     55     chart_kws = {k: v for k, v in kws.items() if k not in builder_props}
     56     chart = Chart(**chart_kws)
---> 57     chart.add_builder(builder)
     58     chart.start_plot()
     59 

Anaconda3\lib\site-packages\bokeh\charts\chart.py in add_builder(self, builder)
    151     def add_builder(self, builder):
    152         self._builders.append(builder)
--> 153         builder.create(self)
    154 
    155     def add_ranges(self, dim, range):

Anaconda3\lib\site-packages\bokeh\charts\builder.py in create(self, chart)
    523         # handle ranges after renders, since ranges depend on aggregations
    524         # ToDo: should reconsider where this occurs
--> 525         self.set_ranges()
    526         chart.add_ranges('x', self.x_range)
    527         chart.add_ranges('y', self.y_range)
Anaconda3\lib\site-packages\bokeh\charts\builder.py in set_ranges(self)
    616         endx = extents['x_max']
    617         startx = extents['x_min']
--> 618         self.x_range = self._get_range('x', startx, endx)
    619 
    620         endy = extents['y_max']

Anaconda3\lib\site-packages\bokeh\charts\builder.py in _get_range(self, dim, start, end)
    671             setattr(self, dim + 'scale', 'categorical')
    672             return FactorRange(factors=factors.tolist())
--> 673         elif np.issubdtype(dtype, np.datetime64):
    674             setattr(self, dim + 'scale', 'datetime')
    675             return Range1d(start=start, end=end)

Anaconda3\lib\site-packages\numpy\core\numerictypes.py in issubdtype(arg1, arg2)
    753     """
    754     if issubclass_(arg2, generic):
--> 755         return issubclass(dtype(arg1).type, arg2)
    756     mro = dtype(arg2).type.mro()
    757     if len(mro) > 1:

TypeError: data type not understood

from bkcharts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.