astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v5.2.1 »
- Data Tables (`astropy.table`) »
- SortedArray

# SortedArray

class astropy.table.SortedArray(data, row_index, unique=False)

  Bases: `object`

  Implements a sorted array container using a list of numpy arrays.

  Parameters:
    data `Table`

      Sorted columns of the original table

    row_index `Column` `object`

      Row numbers corresponding to data columns

    unique bool

      Whether the values of the index must be unique. Defaults to False.

  Attributes Summary

  `cols` |

  Methods Summary

  `add`(key, row) | Add a new entry to the sorted array.
  `find`(key) | Find all rows matching the given key.
  `find_pos`(key, data[, exact]) | Return the index of the largest key in data greater than or equal to the given key, data pair.
  `items`() | Retrieve all array items as a list of pairs of the form [(key, [row 1, row 2, ...]), ...]
  `range`(lower, upper, bounds) | Find values in the given range.
  `remove`(key, data) | Remove the given entry from the sorted array.
  `replace_rows`(row_map) | Replace all rows with the values they map to in the given dictionary.
  `shift_left`(row) | Decrement all row numbers greater than the input row.
  `shift_right`(row) | Increment all row numbers greater than or equal to the input row.
  `sort`() | Make row order align with key order.
  `sorted_data`() | Return rows in sorted order.

  Attributes Documentation

  cols

  Methods Documentation

  add(key, row)

    Add a new entry to the sorted array.

    Parameters:
      key `python:tuple`

        Column values at the given row

      row `python:int`

        Row number

  find(key)

    Find all rows matching the given key.

    Parameters:
      key `python:tuple`

        Column values

    Returns:
      matching_rows `python:list`

        List of rows matching the input key

  find_pos(key, data, exact=False)

    Return the index of the largest key in data greater than or equal to the given key, data pair.

    Parameters:
      key `python:tuple`

        Column key

      data `python:int`

        Row number

      exact bool

        If True, return the index of the given key in data or -1 if the key is not present.

  items()

    Retrieve all array items as a list of pairs of the form [(key, [row 1, row 2, …]), …]

  range(lower, upper, bounds)

    Find values in the given range.

    Parameters:
      lower `python:tuple`

        Lower search bound

      upper `python:tuple`

        Upper search bound

      bounds(2,) `python:tuple` of bool

        Indicates whether the search should be inclusive or exclusive with respect to the endpoints. The first argument corresponds to an inclusive lower bound, and the second argument to an inclusive upper bound.

  remove(key, data)

    Remove the given entry from the sorted array.

    Parameters:
      key `python:tuple`

        Column values

      data `python:int`

        Row number

    Returns:
      successful bool

        Whether the entry was successfully removed

  replace_rows(row_map)

    Replace all rows with the values they map to in the given dictionary. Any rows not present as keys in the dictionary will have their entries deleted.

    Parameters:
      row_map `python:dict`

        Mapping of row numbers to new row numbers

  shift_left(row)

    Decrement all row numbers greater than the input row.

    Parameters:
      row `python:int`

        Input row number

  shift_right(row)

    Increment all row numbers greater than or equal to the input row.

    Parameters:
      row `python:int`

        Input row number

  sort()

    Make row order align with key order.

  sorted_data()

    Return rows in sorted order.