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

Remove the use of Pandas' iloc() in WorldMapViz #7379

Merged
merged 1 commit into from
May 28, 2019

Conversation

elukey
Copy link
Contributor

@elukey elukey commented Apr 25, 2019

This commit changed the value of df[metric]
when the same metric is used in a World Map panel for both bubble size
and an axis (either X or Y). This change removes the use of .iloc that is not needed anymore (and causes exceptions while rendering world maps).

Should fix #7006

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

WorldMap charts, using the the same metric for X/Y axis and bubble size, are not working anymore from 0.29+ due to commit. If I add the following snipped to the WorldMapViz in superset/viz.py everything works as expected again:

        qry['metrics'] = [
            self.form_data['metric'], self.form_data['secondary_metric']]

The .iloc functionality in WorldMap is not needed anymore.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TEST PLAN

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

@codecov-io
Copy link

codecov-io commented Apr 25, 2019

Codecov Report

Merging #7379 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #7379   +/-   ##
=======================================
  Coverage   65.26%   65.26%           
=======================================
  Files         430      430           
  Lines       21077    21077           
  Branches     2338     2338           
=======================================
  Hits        13756    13756           
  Misses       7205     7205           
  Partials      116      116
Impacted Files Coverage Δ
superset/viz.py 71.56% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 598526a...cdf93f9. Read the comment docs.

@elukey elukey force-pushed the master-world-map branch 2 times, most recently from 5964c5d to c171afb Compare April 27, 2019 06:31
When the same metric is used in a World Map panel for both bubble size
and an axis (either X or Y), it currently breaks the rendering.

The change in behavior was introduced in:
apache@71e0c07#diff-f451672348fc6071e8d627778bdc4e96L1730

The use of .iloc() is not needed anymore since the code that used
to duplicate the metric is not there anymore.

Should fix apache#7006
@elukey elukey force-pushed the master-world-map branch from c171afb to cdf93f9 Compare May 2, 2019 06:35
@elukey elukey changed the title Add condition in WorldMapViz before using Pandas' iloc Remove the use of Pandas' iloc() in WorldMapViz May 2, 2019
@elukey
Copy link
Contributor Author

elukey commented May 2, 2019

@mistercrunch I think I finally found a good explanation of what broke the world map visualization. The change in my opinion is to remove the use of .iloc, from my tests it is the simplest solution and it solves all my visualization issues.

@elukey
Copy link
Contributor Author

elukey commented May 9, 2019

@mistercrunch if you have time for a review, I'd be really happy :)

elukey added a commit to wikimedia/incubator-superset that referenced this pull request May 15, 2019
@elukey
Copy link
Contributor Author

elukey commented May 18, 2019

Anybody up for a review? It has been a long time :(

@mistercrunch
Copy link
Member

iloc was introduced because pandas' behavior changed when dealing with multiple columns with the same key. Before it would return the first one, now it returns a dataframe which broke things.

Does this work when the same metric is used twice?

@elukey
Copy link
Contributor Author

elukey commented May 20, 2019

iloc was introduced because pandas' behavior changed when dealing with multiple columns with the same key. Before it would return the first one, now it returns a dataframe which broke things.

Does this work when the same metric is used twice?

I am running superset 0.32 with some extra patches, including this one, and charts using worlmap with the same metric reused as bubble size work fine now.

I have checked a couple of times the pandas' changelog to spot any new feature that could have changed its behavior, but found none. After checking git blame for WorldMapViz though, I noticed that the following bit in the commit that I have indicated seems now the responsible for the need of .iloc or not:

    def query_obj(self):
        qry = super(WorldMapViz, self).query_obj()
-        qry['metrics'] = [
-            self.form_data['metric'], self.form_data['secondary_metric']]
        qry['groupby'] = [self.form_data['entity']]
        return qry

@mistercrunch
Copy link
Member

What version of pandas are you using? Current master says pandas==0.23.4

@elukey
Copy link
Contributor Author

elukey commented May 21, 2019

What version of pandas are you using? Current master says pandas==0.23.4

I am using 0.23.4 indeed, this is my pip freeze:

pip freeze | egrep 'pandas|numpy'
numpy==1.15.2
pandas==0.23.4

@elukey
Copy link
Contributor Author

elukey commented May 21, 2019

@mistercrunch there is more context in the related GH issue: #7006 (comment)

@elukey
Copy link
Contributor Author

elukey commented May 27, 2019

Any news? :)

@villebro
Copy link
Member

@elukey I was able to replicate the problem on master, i.e. when choosing the same metric twice (color and bubble size), the error Too many indexers would show up. After applying your fix the problem went away without causing adverse side-effects that I could tell. If we want to be on the safe side, we could check if df[metric] is a DataFrame and call iloc on that. But I agree that there shouldn't be duplicate columns anymore, so it might very well just introduce unnecessary clutter into the codebase. So all in all LGTM.

@elukey
Copy link
Contributor Author

elukey commented May 28, 2019

@mistercrunch thoughts? :)

@mistercrunch mistercrunch merged commit b21f8ec into apache:master May 28, 2019
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XS 🚢 0.34.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

World map viz not working in 0.29rc7/0.31.0rc18/0.32
4 participants