Skip to content

Commit 566f1ef

Browse files
committed
[astropy#10888] Motivated in part astropy#11094, this removes all use of OrderedDict
from astropy.modeling, which works fine now without it. _ModelMeta.__prepare__ is no longer necessary since class dicts are ordered by default by order in the class body.
1 parent c9a7318 commit 566f1ef

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

‎astropy/modeling/core.py‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import types
2323
import warnings
2424

25-
from collections import defaultdict, OrderedDict, deque
25+
from collections import defaultdict, deque
2626
from inspect import signature
2727
from itertools import chain
2828

@@ -69,9 +69,6 @@ class _ModelMeta(abc.ABCMeta):
6969
Currently just handles auto-generating the param_names list based on
7070
Parameter descriptors declared at the class-level of Model subclasses.
7171
"""
72-
@classmethod
73-
def __prepare__(mcls, name, bases):
74-
return OrderedDict()
7572

7673
_is_dynamic = False
7774
"""
@@ -134,7 +131,7 @@ def __init__(cls, name, bases, members):
134131
super(_ModelMeta, cls).__init__(name, bases, members)
135132
cls._create_inverse_property(members)
136133
cls._create_bounding_box_property(members)
137-
pdict = OrderedDict()
134+
pdict = {}
138135
for base in bases:
139136
for tbase in base.__mro__:
140137
if issubclass(tbase, Model):
@@ -3121,7 +3118,7 @@ def _map_parameters(self):
31213118
return
31223119
if self._leaflist is None:
31233120
self._make_leaflist()
3124-
self._parameters_ = OrderedDict()
3121+
self._parameters_ = {}
31253122
param_map = {}
31263123
self._param_names = []
31273124
for lindex, leaf in enumerate(self._leaflist):
@@ -3709,22 +3706,23 @@ def _custom_model_wrapper(func, fit_deriv=None):
37093706
else:
37103707
output_names = ('x',)
37113708

3712-
params = OrderedDict((param.name, Parameter(param.name,
3713-
default=param.default)) for param in params)
3709+
params = {param.name: Parameter(param.name, default=param.default)
3710+
for param in params}
37143711

37153712
mod = find_current_module(2)
37163713
if mod:
37173714
modname = mod.__name__
37183715
else:
37193716
modname = '__main__'
37203717

3721-
members = OrderedDict([
3722-
('__module__', str(modname)),
3723-
('__doc__', func.__doc__),
3724-
('n_inputs', len(inputs)),
3718+
members = {
3719+
'__module__': str(modname),
3720+
'__doc__': func.__doc__,
3721+
'n_inputs': len(inputs),
37253722
# tuple(x.name for x in inputs)),
3726-
('n_outputs', len(output_names)),
3727-
('evaluate', staticmethod(func))])
3723+
'n_outputs': len(output_names),
3724+
'evaluate': staticmethod(func)
3725+
}
37283726

37293727
if fit_deriv is not None:
37303728
members['fit_deriv'] = staticmethod(fit_deriv)

‎astropy/modeling/tests/test_models_quantities.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
# pylint: disable=invalid-name, no-member
3-
from collections import OrderedDict
43

54
import pytest
65
import numpy as np
@@ -217,9 +216,9 @@ def test_models_evaluate_without_units(model):
217216
m = model['class'](**model['parameters'])
218217
for args in model['evaluation']:
219218
if len(args) == 2:
220-
kwargs = OrderedDict(zip(('x', 'y'), args))
219+
kwargs = dict(zip(('x', 'y'), args))
221220
else:
222-
kwargs = OrderedDict(zip(('x', 'y', 'z'), args))
221+
kwargs = dict(zip(('x', 'y', 'z'), args))
223222
if kwargs['x'].unit.is_equivalent(kwargs['y'].unit):
224223
kwargs['x'] = kwargs['x'].to(kwargs['y'].unit)
225224
mnu = m.without_units_for_data(**kwargs)

0 commit comments

Comments
 (0)