Commit f131581
committed
SparseArray(fix[append]): Handle empty array case
why: Calling append() on an empty SparseArray crashed with ValueError
because max() on an empty sequence raises an exception.
what:
- Use max(self.keys(), default=-1) to return -1 for empty arrays
- First append now correctly adds at index 0
- Add doctest demonstrating empty array append behavior1 parent 862177d commit f131581
1 file changed
+9
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
128 | 130 | | |
129 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
130 | 137 | | |
131 | 138 | | |
132 | 139 | | |
| |||
135 | 142 | | |
136 | 143 | | |
137 | 144 | | |
138 | | - | |
| 145 | + | |
139 | 146 | | |
140 | 147 | | |
141 | 148 | | |
| |||
0 commit comments