question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support __array__ and __list__ protocols

See original GitHub issue

Inputs to bokeh graphing functions seem to be able to take one of the following forms

DataFrame, dict, OrderedDict, list, tuple, ndarray

I wonder if we could extend this to include anything that supports the __array__ or __iter__ protocols. In my own experiments I wrote this function

def normalize_data(data):
    """ Normalize input data to supported types """
    if isinstance(data, (np.ndarray, pd.DataFrame, list, tuple, dict,
        OrderedDict)):
        return data
    if np and hasattr(data, '__array__'):
        result = np.array(data)
        # TODO: Other parts of Bokeh should support numpy record dtypes
        #       convert to DataFrame for now
        if isinstance(result.dtype.descr, list):  # record dtype
            return pd.DataFrame(result)
        else:
            return result
    if isinstance(data, Iterable):
        return list(data)

    raise TypeError("Input type %s not supported" % type(data).__name__)

and inserted it into bokeh/charts/_builder.py:_adapt_values. This allowed me to use Blaze expressions directly in Bokeh plots which felt pretty cool.

More generally would it make sense to normalize inputs even further, perhaps using only a single data type within Bokeh, presumably either a DataFrame or OrderedDict. I notice that some functions seem to branch on the type of _values.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bryevdvcommented, Feb 16, 2015

That is really cool! we should enable this right after 0.8 release I think. Regarding a single type, we are doing out best not to have a hard dependency on Pandas, but also not to require unnecessary copying. Our DataAdapter class is a (not yet complete) stab at a very thin wrapper that presents a “pandas-like” interface, regardless of that the actual data is.

0reactions
bryevdvcommented, Oct 13, 2017

closing, bokeh.charts is gone. Possibly makes sense to suggest to HV

Read more comments on GitHub >

github_iconTop Results From Across the Web

Usage of protocols as array types and function parameters in ...
The objects should be stored in a typed array. According to the Swift documentation protocols can be used as types: Because it is...
Read more >
Define Array of protocol which conforms to Identifiable
I am using a List control in SwiftUI which requires Identifiable. The data source will be an Array of type X where X...
Read more >
Array - JavaScript - MDN Web Docs
The Array object, as with arrays in other programming languages, enables storing a collection of multiple items under a single variable name ...
Read more >
array — Efficient arrays of numeric values — Python 3.11.1 ...
Arrays are sequence types and behave very much like lists, e. ... Array objects support the ordinary sequence operations of indexing, slicing, concatenation ......
Read more >
Create SwiftUI List from an Array - Sarunw
SwiftUI gives us two ways to provide an identity for the data. Identifiable protocol; KeyPath. You can easily support sarunw.com by checking out ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found