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
0dab3e8f
Unverified
Commit
0dab3e8f
authored
Dec 04, 2017
by
peastman
Committed by
GitHub
Dec 04, 2017
Browse files
Merge pull request #1951 from andrrizzi/master
Fix Quantity.__setitem__ bug with slice assignment
parents
9c866ca1
6220775c
Changes
2
Hide 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 @
0dab3e8f
...
...
@@ -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 @
0dab3e8f
...
...
@@ -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