Skip to content

make error messages more helpful when choropleth features and data don't match #4529

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

Open
afeld opened this issue Feb 23, 2024 · 4 comments
Open
Labels
feature something new P3 backlog

Comments

@afeld
Copy link
Contributor

afeld commented Feb 23, 2024

I teach a class for students that are new to coding. We use plotly, and I'm happy to have a package that gets students good-looking graphs in so little code.

I introduce plotly's choropleth maps, and have repeatedly run into the issue where the students get confused by what the featureidkey is referring to and how that relates to the locations. I do my best to explain this, but they are (understandably) confused working across CSVs and GeoJSON. One student just hit an issue where they were trying to use FIPS codes, but their locations column had leading whitespace. When the rows are unable to be matched to a feature, it fails silently.

My feature request is to provide a warning when the featureidkey and locations have zero matches.

I haven't contributed to the plotly codebase before, but I'd be open to doing so if the maintainers are open to receiving this. Presumably the place to add this check is one of the validators?

Thanks!

@alexcjohnson
Copy link
Collaborator

Thanks @afeld - I love those class notes, beautiful!

It would certainly be useful to have a warning in this case, but it's a little tricky to figure out how to make that happen. The Python-side validators are all codegen from the JavaScript schema, and anyway they aren't intended to capture interactions between different attributes. The obvious place to put this is in JavaScript where we put this all together, and some error situations already do generate messages there, though it's not clear to me if the cases you're describing would: https://github.com/plotly/plotly.js/blob/master/src/lib/geo_location_utils.js - that said even if we do get the right messages there you'll only see them in the JS console, not in Python or in the main browser window, and most Python users won't know to look there.

@afeld
Copy link
Contributor Author

afeld commented Feb 24, 2024

Thanks, and thanks for the quick response!

After a bunch of experimentation, reading source code, and some help from ChatGPT, I've learned that the file you pointed me to does have that functionality already, but it's disabled by default. It can be enabled with:

Plotly.setPlotConfig({ logging: 2 });

…but that isn't documented 🙃 Created an example in Codepen.

Screenshot 2024-02-24 at 2 53 02 AM

Unfortunately, it's not clear to me how to do that from Python/Colab. Configuration options can be passed to .show() … but logging and notifyOnLogging "should ONLY be set via Plotly.setPlotConfig". Created a corresponding example in Colab.

Thoughts?

@afeld
Copy link
Contributor Author

afeld commented Feb 24, 2024

even if we do get the right messages there you'll only see them in the JS console, not in Python or in the main browser window, and most Python users won't know to look there.

notifyOnLogging: 2 sidesteps that problem by temporarily displaying them on the map. I'd argue that should be the default setting to avoid confusion, despite the risk of causing visual noise.

@afeld
Copy link
Contributor Author

afeld commented Feb 24, 2024

Issue around allowing logging to be configured via newPlot() in JavaScript (and thus show() in Python): plotly/plotly.js#4555

@gvwilson gvwilson self-assigned this Jul 11, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added P3 backlog feature something new labels Aug 12, 2024
@gvwilson gvwilson changed the title helpful errors when choropleth features and data don't match make error messages more helpful when choropleth features and data don't match Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new P3 backlog
Projects
None yet
Development

No branches or pull requests

3 participants