Modify a series of rows in the slice [start:stop:step]. The values in the selected rows will be modified with the data given in rows. This method returns the number of rows modified. Should the modification exceed the length of the table, an IndexError is raised be
(
self,
start: int | None = None,
stop: int | None = None,
step: int | None = None,
rows: Sequence | None = None,
)
| 2463 | return SizeType(lcoords) |
| 2464 | |
| 2465 | def modify_rows( |
| 2466 | self, |
| 2467 | start: int | None = None, |
| 2468 | stop: int | None = None, |
| 2469 | step: int | None = None, |
| 2470 | rows: Sequence | None = None, |
| 2471 | ) -> int: |
| 2472 | """Modify a series of rows in the slice [start:stop:step]. |
| 2473 | |
| 2474 | The values in the selected rows will be modified with the data given in |
| 2475 | rows. This method returns the number of rows modified. Should the |
| 2476 | modification exceed the length of the table, an IndexError is raised |
| 2477 | before changing data. |
| 2478 | |
| 2479 | The possible values for the rows argument are the same as in |
| 2480 | :meth:`Table.append`. |
| 2481 | |
| 2482 | """ |
| 2483 | if step is None: |
| 2484 | step = 1 |
| 2485 | if rows is None: # Nothing to be done |
| 2486 | return SizeType(0) |
| 2487 | if start is None: |
| 2488 | start = 0 |
| 2489 | |
| 2490 | if start < 0: |
| 2491 | raise ValueError("'start' must have a positive value.") |
| 2492 | if step < 1: |
| 2493 | raise ValueError( |
| 2494 | "'step' must have a value greater or equal than 1." |
| 2495 | ) |
| 2496 | if stop is None: |
| 2497 | # compute the stop value. start + len(rows)*step does not work |
| 2498 | stop = start + (len(rows) - 1) * step + 1 |
| 2499 | |
| 2500 | start, stop, step = self._process_range(start, stop, step) |
| 2501 | if stop > self.nrows: |
| 2502 | raise IndexError( |
| 2503 | "This modification will exceed the length of " |
| 2504 | "the table. Giving up." |
| 2505 | ) |
| 2506 | # Compute the number of rows to read. |
| 2507 | nrows = len(range(start, stop, step)) |
| 2508 | if len(rows) != nrows: |
| 2509 | raise ValueError( |
| 2510 | "The value has different elements than the specified range" |
| 2511 | ) |
| 2512 | |
| 2513 | # Convert rows into a recarray |
| 2514 | recarr = self._conv_to_recarr(rows) |
| 2515 | |
| 2516 | lenrows = len(recarr) |
| 2517 | if start + lenrows > self.nrows: |
| 2518 | raise IndexError( |
| 2519 | "This modification will exceed the length of the " |
| 2520 | "table. Giving up." |
| 2521 | ) |
| 2522 |