Skip to content

Commit

Permalink
change ValueError to IndexError in slice_shots
Browse files Browse the repository at this point in the history
also update tests for this error
  • Loading branch information
aeddins-ibm committed Jul 11, 2024
1 parent c2b0039 commit c4becd9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion qiskit/primitives/containers/bit_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def slice_shots(self, indices: int | Sequence[int]) -> "BitArray":
indices = (indices,)
for index in indices:
if index < 0 or index >= self.num_shots:
raise ValueError(
raise IndexError(
f"index {index} is out of bounds for the number of shots {self.num_shots}."
)
arr = self._array
Expand Down
4 changes: 2 additions & 2 deletions test/python/primitives/containers/test_bit_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,9 @@ def test_slice_shots(self):
self.assertEqual(ba2.get_bitstrings((i, j, k)), expected)

with self.subTest("errors"):
with self.assertRaisesRegex(ValueError, "index -1 is out of bounds"):
with self.assertRaisesRegex(IndexError, "index -1 is out of bounds"):
_ = ba.slice_shots(-1)
with self.assertRaisesRegex(ValueError, "index 10 is out of bounds"):
with self.assertRaisesRegex(IndexError, "index 10 is out of bounds"):
_ = ba.slice_shots(10)

def test_expectation_values(self):
Expand Down

0 comments on commit c4becd9

Please sign in to comment.