Skip to content

Commit

Permalink
Merge branch 'main' into jonmmease/jupyter_chart_renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mattijn authored Dec 22, 2023
2 parents 7bb0f85 + 5540ed9 commit efbf618
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 13 deletions.
2 changes: 1 addition & 1 deletion altair/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def check_data_type(data: DataType) -> None:
# Private utilities
# ==============================================================================
def _compute_data_hash(data_str: str) -> str:
return hashlib.md5(data_str.encode()).hexdigest()
return hashlib.sha256(data_str.encode()).hexdigest()[:32]


def _data_to_json_string(data: DataType) -> str:
Expand Down
2 changes: 1 addition & 1 deletion altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _dataset_name(values: Union[dict, list, core.InlineDataset]) -> str:
if values == [{}]:
return "empty"
values_json = json.dumps(values, sort_keys=True)
hsh = hashlib.md5(values_json.encode()).hexdigest()
hsh = hashlib.sha256(values_json.encode()).hexdigest()[:32]
return "data-" + hsh


Expand Down
3 changes: 3 additions & 0 deletions doc/releases/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ Version 5.3.0 (unreleased month day, year)
Enhancements
~~~~~~~~~~~~
- Add "jupyter" renderer which uses JupyterChart for rendering (#3283). See :ref:`renderers` for more information.
- Support restrictive FIPS-compliant environment (#3291)

Bug Fixes
~~~~~~~~~

Backward-Incompatible Changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Changed hash function from ``md5`` to a truncated ``sha256`` non-cryptograhic hash (#3291)

Version 5.2.0 (released Nov 28, 2023)
-------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion sphinxext/altairgallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def save_example_pngs(examples, image_dir, make_thumbnails=True):
filename = example["name"] + (".svg" if example["use_svg"] else ".png")
image_file = os.path.join(image_dir, filename)

example_hash = hashlib.md5(example["code"].encode()).hexdigest()
example_hash = hashlib.sha256(example["code"].encode()).hexdigest()[:32]
hashes_match = hashes.get(filename, "") == example_hash

if hashes_match and os.path.exists(image_file):
Expand Down
4 changes: 2 additions & 2 deletions sphinxext/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ def dict_hash(dct):
serialized = json.dumps(dct, sort_keys=True)

try:
m = hashlib.md5(serialized)
m = hashlib.sha256(serialized)[:32]
except TypeError:
m = hashlib.md5(serialized.encode())
m = hashlib.sha256(serialized.encode())[:32]

return m.hexdigest()
23 changes: 23 additions & 0 deletions tests/examples_arguments_syntax/histogram_gradient_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Histogram with Gradient Color
-----------------------------
This example shows how to make a histogram with gradient color.
The low-high IMDB rating is represented with the color scheme `pinkyellowgreen`.
"""
# category: distributions
import altair as alt
from vega_datasets import data

source = data.movies.url

alt.Chart(source).mark_bar().encode(
alt.X("IMDB_Rating:Q",
bin=alt.Bin(maxbins=20),
scale=alt.Scale(domain=[1, 10])
),
alt.Y('count()'),
alt.Color("IMDB_Rating:Q",
bin=alt.Bin(maxbins=20),
scale=alt.Scale(scheme='pinkyellowgreen')
)
)
17 changes: 17 additions & 0 deletions tests/examples_methods_syntax/histogram_gradient_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Histogram with Gradient Color
-----------------------------
This example shows how to make a histogram with gradient color.
The low-high IMDB rating is represented with the color scheme `pinkyellowgreen`.
"""
# category: distributions
import altair as alt
from vega_datasets import data

source = data.movies.url

alt.Chart(source).mark_bar().encode(
alt.X("IMDB_Rating:Q").bin(maxbins=20).scale(domain=[1, 10]),
alt.Y('count()'),
alt.Color("IMDB_Rating:Q").bin(maxbins=20).scale(scheme='pinkyellowgreen')
)
9 changes: 1 addition & 8 deletions tests/vegalite/v5/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,7 @@ def test_save_html(basic_chart, inline):

def test_to_url(basic_chart):
share_url = basic_chart.to_url()
expected_vegalite_encoding = (
"N4Igxg9gdgZglgcxALlANzgUwO4tJKAFzigFcJSBnAdTgBNCALFAZgAY2AacaYsiygAlMiRoVYcAvpO5"
"0AhoTl4QUOQFtMKEPMUBaMACY5LTAA4AnACM55ugFY6ARgBspgOz2zh03Wfs5bCwsIDIganIATgDWyoQ"
"AngAOmsgg1hEh3JhQkHQkSKggAB7K8JgANnRaStzxSVpQEGokcmUZIHElWBValiA1ickgAI6kckRwisR"
"omtLcACSUYIyY4VpihAmUyAD029MIcgB0CBOMpJaHcBDbi8vhe5gHumUTmHt2hy6HLIcAVpTQPraBRyS"
"iYQiUZQ6OT6IwmCzWWwOFzuTymby+fyBYLIADaoCUKQAgkDesgDKYZAStAAhUkoOx2KkgQkgADC9OQABY"
"WMzWQARTnmRx8rQAUU5phFnGpKQAYpy7LyZSytABxTmOcyilKCSVuHUgACSioMkgAutIgA"
)
expected_vegalite_encoding = "N4Igxg9gdgZglgcxALlANzgUwO4tJKAFzigFcJSBnAdTgBNCALFAZgAY2AacaYsiygAlMiRoVYcAvpO50AhoTl4QUOQFtMKEPMUBaAOwA2ABwAWFi1NyTcgEb7TtuabAswc-XTZhMczLdNDAEYQGRA1OQAnAGtlQgBPAAdNZBAnSNDuTChIOhIkVBAAD2V4TAAbOi0lbgTkrSgINRI5csyQeNKsSq1bEFqklJAAR1I5IjhFYjRNaW4AEkowRkwIrTFCRMpkAHodmYQ5ADoEScZSWyO4CB2llYj9zEPdcsnMfYBWI6DDI5YjgBWlGg-W0CjklEwhEoyh0cgMJnMlmsxjsDicLjcHi8Pj8AWCKAA2qAlKkAIKgvrIABMxhkJK0ACFKSgPh96SBSSAAMIs5DmDlcgAifIAnEFBVoAKJ84wSzgM1IAMT5HxYktSAHE+UFRRqQIJZfp9QBJVXUyQAXWkQA"

assert (
share_url
Expand Down

0 comments on commit efbf618

Please sign in to comment.