Repository: Qiskit/qiskit

Issue:
Error printing empty `PauliList`
### Environment


- **Qiskit Terra version**:
  tag v0.19.0
- **Python version**:
 3.9 
- **Operating system**: 
 Linux

### What is happening?

```python
import numpy as np
from qiskit.quantum_info import SparsePauliOp, PauliList

x = np.array([], dtype=bool)
z = np.array([], dtype=bool)

pauli_list = PauliList.from_symplectic(x, z)

# Exception is raised
try:
    print(pauli_list)
except ZeroDivisionError as err:
    print(f"Can't print pauli_list: {err}")

# No problem printing SparsePauliOp
print(SparsePauliOp(pauli_list))
```
prints
```
Can't print pauli_list: integer division or modulo by zero
SparsePauliOp([''],
              coeffs=[1.+0.j])
```

Part of the stack trace:
```
~/code/github/Qiskit/oneenv/qiskit-terra/qiskit/quantum_info/operators/symplectic/pauli_list.py in _truncated_str(self, show_class)
    194         stop = self._num_paulis
    195         if self.__truncate__:
--> 196             max_paulis = self.__truncate__ // self.num_qubits
    197             if self._num_paulis > max_paulis:
    198                 stop = max_paulis
```


### How can we reproduce the issue?

Enter the code above

### What should happen?

No error should be thrown.

### Any suggestions?

check before dividing by zero


Discussion:
Hi! I was able to reproduce this bug and was interested in resolving this issue. So I'm a little confused by the resolution, so we want to check before dividing by 0 but we don't want an error to be thrown?
@amyels To clarify a bit. The purpose of this code
https://github.com/Qiskit/qiskit-terra/blob/a6cb1a37f52fd98f90d0685d1fdcba447a5345b7/qiskit/quantum_info/operators/symplectic/pauli_list.py#L193-L198

Is to set `stop` to a small number to avoid printing too much output.  Initially it is set here
https://github.com/Qiskit/qiskit-terra/blob/a6cb1a37f52fd98f90d0685d1fdcba447a5345b7/qiskit/quantum_info/operators/symplectic/pauli_list.py#L194

And if you check the case at hand, an empty `PauliList`, you will see that `self._num_paulis == 1`. So `stop` is initially small enough. If you change line 195 to read:
```python
        if self.__truncate__ and self.num_qubits > 0:
```
then you avoid dividing by zero. And `stop` is already `1`, so you don't need to do anything more. The bottom line is that it looks like the single change above is enough to fix the problem. You might also look through the code to convince yourself (I did not look just now) that the condition `self.num_qubits == 0` and `self._num_paulis > 2000` (the default truncate limit) does not happen.

Resolving patch:
diff --git a/qiskit/quantum_info/operators/symplectic/pauli_list.py b/qiskit/quantum_info/operators/symplectic/pauli_list.py
--- a/qiskit/quantum_info/operators/symplectic/pauli_list.py
+++ b/qiskit/quantum_info/operators/symplectic/pauli_list.py
@@ -192,7 +192,7 @@ def __str__(self):
 
     def _truncated_str(self, show_class):
         stop = self._num_paulis
-        if self.__truncate__:
+        if self.__truncate__ and self.num_qubits > 0:
             max_paulis = self.__truncate__ // self.num_qubits
             if self._num_paulis > max_paulis:
                 stop = max_paulis


Test patch:
diff --git a/test/python/quantum_info/operators/symplectic/test_pauli_list.py b/test/python/quantum_info/operators/symplectic/test_pauli_list.py
--- a/test/python/quantum_info/operators/symplectic/test_pauli_list.py
+++ b/test/python/quantum_info/operators/symplectic/test_pauli_list.py
@@ -80,6 +80,14 @@ class TestPauliListInit(QiskitTestCase):
     def test_array_init(self):
         """Test array initialization."""
         # Matrix array initialization
+
+        with self.subTest(msg="Empty array"):
+            x = np.array([], dtype=bool).reshape((1, 0))
+            z = np.array([], dtype=bool).reshape((1, 0))
+            pauli_list = PauliList.from_symplectic(x, z)
+            np.testing.assert_equal(pauli_list.z, z)
+            np.testing.assert_equal(pauli_list.x, x)
+
         with self.subTest(msg="bool array"):
             z = np.array([[False], [True]])
             x = np.array([[False], [True]])