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

Do not mutate data when using custom text format #1352

Merged
merged 2 commits into from
Jun 18, 2024
Merged

Conversation

ahuang11
Copy link
Collaborator

@ahuang11 ahuang11 commented Jun 12, 2024

I noticed that it previously mutated the data (e.g. added a label column when data['label'] = data.apply(lambda row: template_str.format(**row), axis=1)).

This PR fixes that:

import hvplot.pandas
import pandas as pd

df = pd.DataFrame(
    {
        "City": ["Buenos Aires", "Brasilia", "Santiago", "Bogota", "Caracas"],
        "Country": ["Argentina", "Brazil", "Chile", "Colombia", "Venezuela"],
        "Latitude": [-34.58, -15.78, -33.45, 4.60, 10.48],
        "Longitude": [-58.66, -47.91, -70.66, -74.08, -66.86],
    }
)
df.hvplot.points("Longitude", "Latitude", by="City") * df.hvplot.labels(
    "Longitude", "Latitude", text="City ({Latitude:.1f}N, {Longitude:.1f}E)", by="City"
)
df
image

@ahuang11 ahuang11 requested a review from maximlt June 12, 2024 19:13
@ahuang11 ahuang11 changed the title do not mutate data Do not mutate data when using custom text format Jun 12, 2024
Copy link

codecov bot commented Jun 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.41%. Comparing base (6c96c7e) to head (5a176c8).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1352      +/-   ##
==========================================
+ Coverage   87.39%   87.41%   +0.02%     
==========================================
  Files          50       50              
  Lines        7490     7502      +12     
==========================================
+ Hits         6546     6558      +12     
  Misses        944      944              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

hvplot/converter.py Outdated Show resolved Hide resolved
Copy link
Member

@philippjfr philippjfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the correct thing to do.

@maximlt
Copy link
Member

maximlt commented Jun 18, 2024

Unrelated test failure.

@maximlt maximlt merged commit c37d795 into main Jun 18, 2024
8 of 9 checks passed
@maximlt maximlt deleted the no_mutate_data branch June 18, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants