Support __array__ and __list__ protocols
See original GitHub issueInputs 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:
- Created 9 years ago
- Comments:5 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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
DataAdapterclass is a (not yet complete) stab at a very thin wrapper that presents a “pandas-like” interface, regardless of that the actual data is.closing,
bokeh.chartsis gone. Possibly makes sense to suggest to HV