Skip to content

Remove some usages of OrderedDict #20078

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

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/lines_bars_and_markers/filled_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""

import itertools
from collections import OrderedDict
from functools import partial

import numpy as np
Expand Down Expand Up @@ -188,7 +187,7 @@ def stack_hist(ax, stacked_data, sty_cycle, bottoms=None,
np.random.seed(19680801)

stack_data = np.random.randn(4, 12250)
dict_data = OrderedDict(zip((c['label'] for c in label_cycle), stack_data))
dict_data = dict(zip((c['label'] for c in label_cycle), stack_data))

###############################################################################
# Work with plain arrays
Expand Down
30 changes: 12 additions & 18 deletions lib/matplotlib/_color_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from collections import OrderedDict


BASE_COLORS = {
'b': (0, 0, 1), # blue
'g': (0, 0.5, 0), # green
Expand All @@ -14,22 +11,19 @@


# These colors are from Tableau
TABLEAU_COLORS = (
('blue', '#1f77b4'),
('orange', '#ff7f0e'),
('green', '#2ca02c'),
('red', '#d62728'),
('purple', '#9467bd'),
('brown', '#8c564b'),
('pink', '#e377c2'),
('gray', '#7f7f7f'),
('olive', '#bcbd22'),
('cyan', '#17becf'),
)
TABLEAU_COLORS = {
'tab:blue': '#1f77b4',
'tab:orange': '#ff7f0e',
'tab:green': '#2ca02c',
'tab:red': '#d62728',
'tab:purple': '#9467bd',
'tab:brown': '#8c564b',
'tab:pink': '#e377c2',
'tab:gray': '#7f7f7f',
'tab:olive': '#bcbd22',
'tab:cyan': '#17becf',
}

# Normalize name to "tab:<name>" to avoid name collisions.
TABLEAU_COLORS = OrderedDict(
('tab:' + name, value) for name, value in TABLEAU_COLORS)

# This mapping of color names -> hex values is taken from
# a survey run by Randall Munroe see:
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections import OrderedDict, namedtuple
from collections import namedtuple
from functools import wraps
import inspect
import logging
Expand Down Expand Up @@ -1683,8 +1683,7 @@ def setp(obj, *args, file=None, **kwargs):
if len(args) % 2:
raise ValueError('The set args must be string, value pairs')

# put args into ordereddict to maintain order
funcvals = OrderedDict((k, v) for k, v in zip(args[::2], args[1::2]))
funcvals = dict(zip(args[::2], args[1::2]))
ret = [o.update(funcvals) for o in objs] + [o.set(**kwargs) for o in objs]
return list(cbook.flatten(ret))

Expand Down
8 changes: 3 additions & 5 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""

import codecs
import collections
from datetime import datetime
from enum import Enum
from functools import total_ordering
Expand Down Expand Up @@ -682,15 +681,14 @@ def __init__(self, filename, metadata=None):
self._soft_mask_states = {}
self._soft_mask_seq = (Name(f'SM{i}') for i in itertools.count(1))
self._soft_mask_groups = []
# reproducible writeHatches needs an ordered dict:
self.hatchPatterns = collections.OrderedDict()
self.hatchPatterns = {}
self._hatch_pattern_seq = (Name(f'H{i}') for i in itertools.count(1))
self.gouraudTriangles = []

self._images = collections.OrderedDict() # reproducible writeImages
self._images = {}
self._image_seq = (Name(f'I{i}') for i in itertools.count(1))

self.markers = collections.OrderedDict() # reproducible writeMarkers
self.markers = {}
self.multi_byte_charprocs = {}

self.paths = []
Expand Down
7 changes: 3 additions & 4 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections import OrderedDict
import base64
import datetime
import gzip
Expand Down Expand Up @@ -287,10 +286,10 @@ def __init__(self, width, height, svgwriter, basename=None, image_dpi=72,
self._groupd = {}
self.basename = basename
self._image_counter = itertools.count()
self._clipd = OrderedDict()
self._clipd = {}
self._markers = {}
self._path_collection_id = 0
self._hatchd = OrderedDict()
self._hatchd = {}
self._has_gouraud = False
self._n_gradients = 0

Expand Down Expand Up @@ -1174,7 +1173,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
writer.start('text')

# Sort the characters by font, and output one tspan for each.
spans = OrderedDict()
spans = {}
for font, fontsize, thetext, new_x, new_y in glyphs:
style = generate_css({
'font-size': short_float_fmt(fontsize) + 'px',
Expand Down
4 changes: 1 addition & 3 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections import OrderedDict
import copy
import os
from pathlib import Path
Expand Down Expand Up @@ -460,8 +459,7 @@ def test_rcparams_reset_after_fail():
with mpl.rc_context(rc={'text.usetex': False}):
assert mpl.rcParams['text.usetex'] is False
with pytest.raises(KeyError):
with mpl.rc_context(rc=OrderedDict([('text.usetex', True),
('test.blah', True)])):
with mpl.rc_context(rc={'text.usetex': True, 'test.blah': True}):
pass
assert mpl.rcParams['text.usetex'] is False

Expand Down
4 changes: 1 addition & 3 deletions lib/matplotlib/tests/test_style.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections import OrderedDict
from contextlib import contextmanager
import gc
from pathlib import Path
Expand Down Expand Up @@ -138,10 +137,9 @@ def test_context_with_union_of_dict_and_namedstyle():
def test_context_with_badparam():
original_value = 'gray'
other_value = 'blue'
d = OrderedDict([(PARAM, original_value), ('badparam', None)])
with style.context({PARAM: other_value}):
assert mpl.rcParams[PARAM] == other_value
x = style.context([d])
x = style.context({PARAM: original_value, 'badparam': None})
Copy link
Member

@QuLogic QuLogic Apr 26, 2021

Choose a reason for hiding this comment

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

Do you need x, or can it just go in the with?

Copy link
Member Author

Choose a reason for hiding this comment

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

I suppose this was written to check that the error occurs when entering the context, and not when creating it.

with pytest.raises(KeyError):
with x:
pass
Expand Down
4 changes: 2 additions & 2 deletions tutorials/colors/colormaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
import matplotlib.pyplot as plt
from matplotlib import cm
from colorspacious import cspace_converter
from collections import OrderedDict

cmaps = OrderedDict()

cmaps = {}

###############################################################################
# Sequential
Expand Down