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.

color_bins_layer breaks argument should take in iterables

See original GitHub issue

I tried passing a numpy array for the breaks argument of a color_bins_layer helper:

from cartoframes.viz.helpers import color_bins_layer

breaks = np.arange(
    np.log(counties_w_counts.properties_per_household.max()) / 7,

            counties_w_counts[["geometry", "properties_per_household"]],
        Layer("SELECT * FROM mamataakella.state_bounds", "color: opacity(black, 0.5)"),
    viewport={"zoom": 3.15, "lat": 39.051997, "lng": -99.333419},

And received the following error:

ValueError                                Traceback (most recent call last)
<ipython-input-308-147ad3fa75fa> in <module>
     14             stroke_color="transparent",
     15             palette="sunset",
---> 16             breaks=breaks,
     17         ),
     18         Layer("SELECT * FROM mamataakella.state_bounds", "color: opacity(black, 0.5)"),

~/.local/share/virtualenvs/property_data-_sgn6fy1/lib/python3.7/site-packages/cartoframes/viz/helpers/ in color_bins_layer(source, value, title, method, bins, breaks, palette, size, opacity, stroke_color, stroke_width, description, footer, legend, popup, widget, animate)
     47         raise ValueError('Available methods are: "quantiles", "equal", "stdev".')
---> 49     func = 'buckets' if breaks else {
     50         'quantiles': 'globalQuantiles',
     51         'equal': 'globalEqIntervals',

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

My expectation is that breaks can be an ordered iterable (list, tuple, numpy array). It works fine with list and tuple, but the error above leads me to think that it’s testing for whether it’s a list or tuple (and not a string). Since numpy has such a common use in peoples workflows for calculating custom arrays, we should support it too. A the very least we need to improve the error message that it should be a list/tuple or one of the named strings.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

andy-eschcommented, Nov 4, 2019

Thanks for the response, @makella! Yeah, looks like she has the same issue of needing to convert it to a python list first.

andy-eschcommented, Nov 4, 2019

I used it because I wanted clear, evenly spaced values for the percentages. I could’ve tried method='equal' and bins=10 I guess but it felt easier to generate the bins I know I want ahead of time.

Just tried the way you suggest: Screen Shot 2019-11-04 at 2 59 35 PM

More or less the same except for the < and > for the lower/upper values.

Read more comments on GitHub >

github_iconTop Results From Across the Web

itertools — Functions creating iterators for efficient looping ...
It generates a break or new group every time the value of the key function changes (which is why it is usually necessary...
Read more >
Iterables - Python Like You Mean It
Here are some useful built-in functions that accept iterables as arguments: list , tuple , dict , set : construct a list ...
Read more >
When should I accept a parameter of Iterable<T> vs ...
You say it would be a "breaking change." What would break if (say) the ArrayList<T> constructor parameter was changed from Collection<T> to ...
Read more >
21. Iterables and iterators - Exploring JS
A value doesn't have to be an object in order to be iterable. That's because all values are coerced to objects before the...
Read more >
API Reference — more-itertools 9.0.0 documentation
By the default, the last yielded list will have fewer than n elements if the ... Break iterable into sub-iterables with n elements...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found