Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle when requesting more bins than there are unique edges results in error #20

Closed
kuanb opened this issue Apr 21, 2017 · 5 comments

Comments

@kuanb
Copy link
Member

kuanb commented Apr 21, 2017

Right now, if you request more bins than there are unique edges, an error will be raised. I wonder if it would be reasonable to simply pick themin() of the number of unique edges or the requested argument parameter num_bins?

Example:

>>> colors = urbanaccess.plot.col_colors(
...                         df=network,
...                         col='mean',
...                         num_bins=10,
...                         cmap='spectral',
...                         start=0.1,
...                         stop=0.9)
Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "urbanaccess/plot.py", line 160, in col_colors
    categories = pd.qcut(x=col_values, q=num_bins, labels=bin_labels)
  File "/usr/local/lib/python2.7/site-packages/pandas/tools/tile.py", line 175, in qcut
    precision=precision, include_lowest=True)
  File "/usr/local/lib/python2.7/site-packages/pandas/tools/tile.py", line 194, in _bins_to_cuts
    raise ValueError('Bin edges must be unique: %s' % repr(bins))
ValueError: Bin edges must be unique: array([  0.        ,   8.15789474,  13.        ,  16.71428571,
        25.5       ,  29.66666667,  30.        ,  30.        ,
        30.6       ,  37.5       ,  86.        ])
@sablanchard
Copy link
Contributor

Thank you Kuan, that is a good idea and sounds reasonable. Would you be willing to add this to your existing plot PR #22?

@kuanb
Copy link
Member Author

kuanb commented Apr 24, 2017

Sounds good, will get to it later today!

@kuanb
Copy link
Member Author

kuanb commented Apr 27, 2017

Resolved via latest commit, the kuanb-color-cols-fix branch PR is ready to be reviewed again.

cc @pksohn @sablanchard

@kuanb
Copy link
Member Author

kuanb commented Apr 27, 2017

Example operation:

>>> color_range = col_colors(
...                         df=urbanaccess_nw.net_edges,
...                         col='mean',
...                         num_bins=16,
...                         cmap='YlOrRd',
...                         start=0.1,
...                         stop=0.9)
Too many bins requested, using max bins possible. To avoid duplicate edges, 8 bins used.

kuanb added a commit to kuanb/urbanaccess that referenced this issue Apr 27, 2017
sablanchard pushed a commit that referenced this issue May 3, 2017
* create color columns handles nan vals, prevents floats

* resolves issue #20

* rename func to _recursive_category_gen
@sablanchard
Copy link
Contributor

Fixed with PR #22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants