Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
6220775c
Commit
6220775c
authored
Dec 04, 2017
by
Andrea Rizzi
Browse files
Fix #1940: Bug in Quantity.__setitem__ when assigning slices
parent
07c1b86c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
2 deletions
+6
-2
wrappers/python/simtk/unit/quantity.py
wrappers/python/simtk/unit/quantity.py
+2
-2
wrappers/python/tests/TestUnits.py
wrappers/python/tests/TestUnits.py
+4
-0
No files found.
wrappers/python/simtk/unit/quantity.py
View file @
6220775c
...
...
@@ -737,8 +737,8 @@ class Quantity(object):
# Delegate slices to one-at-a time ___setitem___
if
isinstance
(
key
,
slice
):
# slice
indices
=
key
.
indices
(
len
(
self
))
for
i
in
range
(
*
indices
):
self
[
i
]
=
value
[
i
]
for
value_idx
,
self_idx
in
enumerate
(
range
(
*
indices
)
)
:
self
[
self_idx
]
=
value
[
value_idx
]
else
:
# single index
# Check unit compatibility
if
self
.
unit
.
is_dimensionless
()
and
is_dimensionless
(
value
):
...
...
wrappers/python/tests/TestUnits.py
View file @
6220775c
...
...
@@ -288,6 +288,10 @@ class TestUnits(QuantityTestCase):
# Tests that __setitem__ converts to the unit of the container
s
[
0
]
=
1
*
u
.
nanometers
self
.
assertEqual
(
s
[
0
].
_value
,
10
)
# Tests that __setitem__ handles slice assignment correctly
x
=
[
0
,
1
,
2
,
3
,
4
]
*
u
.
kelvin
x
[
2
:
4
]
=
[
-
2
,
-
3
]
*
u
.
kelvin
self
.
assertEqual
(
x
.
_value
,
[
0
,
1
,
-
2
,
-
3
,
4
])
# Tests standard unit conversions
x
=
[
1
,
2
,
3
]
*
u
.
centimeters
self
.
assertEqual
(
x
/
u
.
millimeters
,
[
10
,
20
,
30
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment