Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: indexed access for columns and rows #1252

Merged
merged 6 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 37 additions & 25 deletions docs/api/safeds/data/tabular/containers/Column.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pipeline example {
) -> distinctValues: List<T?>

/**
* Return the column value at specified index. This WILL LATER BE equivalent to the `[]` operator (indexed access).
* Return the column value at specified index. This is equivalent to the `[]` operator (indexed access).
*
* Nonnegative indices are counted from the beginning (starting at 0), negative indices from the end (starting at
* -1).
Expand All @@ -92,6 +92,12 @@ pipeline example {
* val column = Column("test", [1, 2, 3]);
* val result = column.getValue(1); // 2
* }
*
* @example
* pipeline example {
* val column = Column("test", [1, 2, 3]);
* val result = column[1]; // 2
* }
*/
@Pure
@PythonName("get_value")
Expand Down Expand Up @@ -695,7 +701,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="126"
```sds linenums="132"
@Pure
fun all(
predicate: (cell: Cell<T>) -> satisfiesPredicate: Cell<Boolean?>,
Expand Down Expand Up @@ -754,7 +760,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="169"
```sds linenums="175"
@Pure
fun any(
predicate: (cell: Cell<T>) -> satisfiesPredicate: Cell<Boolean?>,
Expand Down Expand Up @@ -804,7 +810,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="341"
```sds linenums="347"
@Pure
@PythonName("correlation_with")
fun correlationWith(
Expand Down Expand Up @@ -858,7 +864,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="207"
```sds linenums="213"
@Pure
fun countIf(
predicate: (cell: Cell<T>) -> satisfiesPredicate: Cell<Boolean?>,
Expand Down Expand Up @@ -893,7 +899,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="360"
```sds linenums="366"
@Pure
@PythonName("distinct_value_count")
fun distinctValueCount(
Expand Down Expand Up @@ -927,7 +933,7 @@ pipeline example {

## <code class="doc-symbol doc-symbol-function"></code> `getValue` {#safeds.data.tabular.containers.Column.getValue data-toc-label='[function] getValue'}

Return the column value at specified index. This WILL LATER BE equivalent to the `[]` operator (indexed access).
Return the column value at specified index. This is equivalent to the `[]` operator (indexed access).

Nonnegative indices are counted from the beginning (starting at 0), negative indices from the end (starting at
-1).
Expand All @@ -952,10 +958,16 @@ pipeline example {
val result = column.getValue(1); // 2
}
```
```sds
pipeline example {
val column = Column("test", [1, 2, 3]);
val result = column[1]; // 2
}
```

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="83"
```sds linenums="89"
@Pure
@PythonName("get_value")
fun getValue(
Expand Down Expand Up @@ -996,7 +1008,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="389"
```sds linenums="395"
@Pure
fun idness() -> idness: Float
```
Expand All @@ -1022,7 +1034,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="403"
```sds linenums="409"
@Pure
fun max() -> max: T?
```
Expand Down Expand Up @@ -1050,7 +1062,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="419"
```sds linenums="425"
@Pure
fun mean() -> mean: T
```
Expand Down Expand Up @@ -1079,7 +1091,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="436"
```sds linenums="442"
@Pure
fun median() -> median: T
```
Expand All @@ -1105,7 +1117,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="450"
```sds linenums="456"
@Pure
fun min() -> min: T?
```
Expand All @@ -1131,7 +1143,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="464"
```sds linenums="470"
@Pure
@PythonName("missing_value_count")
fun missingValueCount() -> missingValueCount: Int
Expand Down Expand Up @@ -1164,7 +1176,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="485"
```sds linenums="491"
@Pure
@PythonName("missing_value_ratio")
fun missingValueRatio() -> missingValueRatio: Float
Expand Down Expand Up @@ -1200,7 +1212,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="505"
```sds linenums="511"
@Pure
fun mode(
@PythonName("ignore_missing_values") ignoreMissingValues: Boolean = true,
Expand Down Expand Up @@ -1258,7 +1270,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="250"
```sds linenums="256"
@Pure
fun none(
predicate: (cell: Cell<T>) -> satisfiesPredicate: Cell<Boolean?>,
Expand Down Expand Up @@ -1296,7 +1308,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="272"
```sds linenums="278"
@Pure
fun rename(
@PythonName("new_name") newName: String
Expand Down Expand Up @@ -1330,7 +1342,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="527"
```sds linenums="533"
@Pure
fun stability() -> stability: Float
```
Expand Down Expand Up @@ -1358,7 +1370,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="544"
```sds linenums="550"
@Pure
@PythonName("standard_deviation")
fun standardDeviation() -> standardDeviation: Float
Expand All @@ -1385,7 +1397,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="309"
```sds linenums="315"
@Pure
@PythonName("summarize_statistics")
fun summarizeStatistics() -> statistics: Table
Expand All @@ -1412,7 +1424,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="576"
```sds linenums="582"
@Pure
@PythonName("to_list")
fun toList() -> values: List<T>
Expand Down Expand Up @@ -1440,7 +1452,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="592"
```sds linenums="598"
@Pure
@PythonName("to_table")
fun toTable() -> table: Table
Expand Down Expand Up @@ -1482,7 +1494,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="293"
```sds linenums="299"
@Pure
fun transform<R>(
transformer: (cell: Cell<T>) -> transformedCell: Cell<R>
Expand Down Expand Up @@ -1512,7 +1524,7 @@ pipeline example {

??? quote "Stub code in `Column.sdsstub`"

```sds linenums="562"
```sds linenums="568"
@Pure
fun variance() -> variance: Float
```
28 changes: 20 additions & 8 deletions docs/api/safeds/data/tabular/containers/Row.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This class cannot be instantiated directly. It is only used for arguments of cal
attr ^schema: Schema

/**
* Get the value of the specified column. This WILL LATER BE equivalent to using the `[]` operator (indexed access).
* Get the value of the specified column. This is equivalent to the `[]` operator (indexed access).
*
* @param name The name of the column.
*
Expand All @@ -39,14 +39,20 @@ This class cannot be instantiated directly. It is only used for arguments of cal
* pipeline example {
* val table = Table({"col1": [1, 2], "col2": [3, 4]});
* val result = table.removeRows((row) -> row.getValue("col1") == 1);
* }
*
* @example
* pipeline example {
* val table = Table({"col1": [1, 2], "col2": [3, 4]});
* val result = table.removeRows((row) -> row["col1"] == 1);
* // Table({"col1": [2], "col2": [4]})
* }
*/
@Pure
@PythonName("get_value")
fun getValue(
name: String
) -> value: Cell<Any>
) -> value: Cell

/**
* Get the type of the specified column.
Expand Down Expand Up @@ -112,7 +118,7 @@ Get the type of the specified column.

??? quote "Stub code in `Row.sdsstub`"

```sds linenums="52"
```sds linenums="58"
@Pure
@PythonName("get_column_type")
fun getColumnType(
Expand All @@ -122,7 +128,7 @@ Get the type of the specified column.

## <code class="doc-symbol doc-symbol-function"></code> `getValue` {#safeds.data.tabular.containers.Row.getValue data-toc-label='[function] getValue'}

Get the value of the specified column. This WILL LATER BE equivalent to using the `[]` operator (indexed access).
Get the value of the specified column. This is equivalent to the `[]` operator (indexed access).

**Parameters:**

Expand All @@ -134,26 +140,32 @@ Get the value of the specified column. This WILL LATER BE equivalent to using th

| Name | Type | Description |
|------|------|-------------|
| `value` | [`Cell<Any>`][safeds.data.tabular.containers.Cell] | The value of the column. |
| `value` | [`Cell<Any?>`][safeds.data.tabular.containers.Cell] | The value of the column. |

**Examples:**

```sds hl_lines="3"
pipeline example {
val table = Table({"col1": [1, 2], "col2": [3, 4]});
val result = table.removeRows((row) -> row.getValue("col1") == 1);
}
```
```sds
pipeline example {
val table = Table({"col1": [1, 2], "col2": [3, 4]});
val result = table.removeRows((row) -> row["col1"] == 1);
// Table({"col1": [2], "col2": [4]})
}
```

??? quote "Stub code in `Row.sdsstub`"

```sds linenums="39"
```sds linenums="45"
@Pure
@PythonName("get_value")
fun getValue(
name: String
) -> value: Cell<Any>
) -> value: Cell
```

## <code class="doc-symbol doc-symbol-function"></code> `hasColumn` {#safeds.data.tabular.containers.Row.hasColumn data-toc-label='[function] hasColumn'}
Expand All @@ -174,7 +186,7 @@ Check if the row has a column with the specified name.

??? quote "Stub code in `Row.sdsstub`"

```sds linenums="65"
```sds linenums="71"
@Pure
@PythonName("has_column")
fun hasColumn(
Expand Down
Loading