Skip to content

Commit

Permalink
feat: replace prefix n with number_of (#250)
Browse files Browse the repository at this point in the history
### Summary of Changes

* Rename `n_columns` to `number_of_columns`
* Rename `n_rows` to `number_of_rows`

Reason: The prefix `n` is commonly used instead of `number_of`. However,
we also need to add a parameter to `AdaBoost` to set the maximum number
of learners (#171). Calling that `maximum_n_learners` doesn't look
nearly as readable to me as `maximum_number_of_learners`. And if we
don't use `n` to replace `number_of` here, we shouldn't use this
anywhere.

---------

Co-authored-by: megalinter-bot <[email protected]>
  • Loading branch information
lars-reimann and megalinter-bot authored Apr 27, 2023
1 parent 66b9f15 commit f4f44a6
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 48 deletions.
10 changes: 4 additions & 6 deletions src/safeds/data/tabular/containers/_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ def name(self) -> str:
return self._name

@property
def n_rows(self) -> int:
def number_of_rows(self) -> int:
"""
Return the number of elements in the column.
Returns
-------
n_rows : int
number_of_rows : int
The number of elements.
"""
return len(self._data)
Expand Down Expand Up @@ -334,13 +334,11 @@ def correlation_with(self, other_column: Column) -> float:
"""
if not self._type.is_numeric() or not other_column._type.is_numeric():
raise NonNumericColumnError(
f"Columns must be numerical. {self.name} is {self._type}, "
f"{other_column.name} is {other_column._type}.",
f"Columns must be numerical. {self.name} is {self._type}, {other_column.name} is {other_column._type}.",
)
if self._data.size != other_column._data.size:
raise ColumnLengthMismatchError(
f"{self.name} is of size {self._data.size}, "
f"{other_column.name} is of size {other_column._data.size}.",
f"{self.name} is of size {self._data.size}, {other_column.name} is of size {other_column._data.size}.",
)
return self._data.corr(other_column._data)

Expand Down
8 changes: 4 additions & 4 deletions src/safeds/data/tabular/containers/_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def __len__(self) -> int:
Returns
-------
n_columns : int
number_of_columns : int
The number of columns.
Examples
Expand Down Expand Up @@ -307,20 +307,20 @@ def column_names(self) -> list[str]:
return self._schema.column_names

@property
def n_columns(self) -> int:
def number_of_column(self) -> int:
"""
Return the number of columns in this row.
Returns
-------
n_columns : int
number_of_column : int
The number of columns.
Examples
--------
>>> from safeds.data.tabular.containers import Row
>>> row = Row({"a": 1, "b": 2})
>>> row.n_columns
>>> row.number_of_column
2
"""
return self._data.shape[1]
Expand Down
28 changes: 14 additions & 14 deletions src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,25 +280,25 @@ def column_names(self) -> list[str]:
return self._schema.column_names

@property
def n_columns(self) -> int:
def number_of_columns(self) -> int:
"""
Return the number of columns.
Returns
-------
n_columns : int
number_of_columns : int
The number of columns.
"""
return self._data.shape[1]

@property
def n_rows(self) -> int:
def number_of_rows(self) -> int:
"""
Return the number of rows.
Returns
-------
n_rows : int
number_of_rows : int
The number of rows.
"""
return self._data.shape[0]
Expand Down Expand Up @@ -481,8 +481,8 @@ def add_column(self, column: Column) -> Table:
if self.has_column(column.name):
raise DuplicateColumnNameError(column.name)

if column._data.size != self.n_rows:
raise ColumnSizeError(str(self.n_rows), str(column._data.size))
if column._data.size != self.number_of_rows:
raise ColumnSizeError(str(self.number_of_rows), str(column._data.size))

result = self._data.copy()
result.columns = self._schema.column_names
Expand Down Expand Up @@ -518,8 +518,8 @@ def add_columns(self, columns: list[Column] | Table) -> Table:
if column.name in result.columns:
raise DuplicateColumnNameError(column.name)

if column._data.size != self.n_rows:
raise ColumnSizeError(str(self.n_rows), str(column._data.size))
if column._data.size != self.number_of_rows:
raise ColumnSizeError(str(self.number_of_rows), str(column._data.size))

result[column.name] = column._data
return Table(result)
Expand Down Expand Up @@ -792,8 +792,8 @@ def replace_column(self, old_column_name: str, new_column: Column) -> Table:
if new_column.name in self._schema.column_names and new_column.name != old_column_name:
raise DuplicateColumnNameError(new_column.name)

if self.n_rows != new_column._data.size:
raise ColumnSizeError(str(self.n_rows), str(new_column._data.size))
if self.number_of_rows != new_column._data.size:
raise ColumnSizeError(str(self.number_of_rows), str(new_column._data.size))

if old_column_name != new_column.name:
renamed_table = self.rename_column(old_column_name, new_column.name)
Expand Down Expand Up @@ -852,9 +852,9 @@ def slice_rows(
start = 0

if end is None:
end = self.n_rows
end = self.number_of_rows

if start < 0 or end < 0 or start >= self.n_rows or end > self.n_rows or end < start:
if start < 0 or end < 0 or start >= self.number_of_rows or end > self.number_of_rows or end < start:
raise ValueError("The given index is out of bounds")

new_df = self._data.iloc[start:end:step]
Expand Down Expand Up @@ -937,8 +937,8 @@ def split(self, percentage_in_first: float) -> tuple[Table, Table]:
if percentage_in_first <= 0 or percentage_in_first >= 1:
raise ValueError("the given percentage is not in range")
return (
self.slice_rows(0, round(percentage_in_first * self.n_rows)),
self.slice_rows(round(percentage_in_first * self.n_rows)),
self.slice_rows(0, round(percentage_in_first * self.number_of_rows)),
self.slice_rows(round(percentage_in_first * self.number_of_rows)),
)

def tag_columns(self, target_name: str, feature_names: list[str] | None = None) -> TaggedTable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
],
)
def test_should_return_the_number_of_rows(column: Column, expected: int) -> None:
assert column.n_rows == expected
assert column.number_of_rows == expected
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def test_add_column_valid(column: Column, col_type: ColumnType) -> None:
table1 = Table.from_dict({"col1": [1, 2, 1], "col2": [1, 2, 4]})
table1 = table1.add_column(column)
assert table1.n_columns == 3
assert table1.number_of_columns == 3
assert table1.get_column("col3") == column
assert isinstance(table1.schema.get_column_type("col1"), Integer)
assert isinstance(table1.schema.get_column_type("col2"), Integer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_add_columns_valid() -> None:
col3 = Column("col3", [0, -1, -2])
col4 = Column("col4", ["a", "b", "c"])
table1 = table1.add_columns([col3, col4])
assert table1.n_columns == 4
assert table1.number_of_columns == 4
assert table1.get_column("col3") == col3
assert table1.get_column("col4") == col4
assert isinstance(table1.schema.get_column_type("col1"), Integer)
Expand All @@ -22,7 +22,7 @@ def test_add_columns_table_valid() -> None:
col4 = Column("col4", ["a", "b", "c"])
table2 = Table.from_columns([col3, col4])
table1 = table1.add_columns(table2)
assert table1.n_columns == 4
assert table1.number_of_columns == 4
assert table1.get_column("col3") == col3
assert table1.get_column("col4") == col4
assert isinstance(table1.schema.get_column_type("col1"), Integer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_add_row_valid() -> None:
table1 = Table.from_dict({"col1": [1, 2, 1], "col2": [1, 2, 4]})
row = Row({"col1": 5, "col2": 6})
table1 = table1.add_row(row)
assert table1.n_rows == 4
assert table1.number_of_rows == 4
assert table1.get_row(3) == row
assert table1.schema == row._schema

Expand Down
4 changes: 2 additions & 2 deletions tests/safeds/data/tabular/containers/_table/test_add_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_add_rows_valid() -> None:
table1.schema,
)
table1 = table1.add_rows([row1, row2])
assert table1.n_rows == 5
assert table1.number_of_rows == 5
assert table1.get_row(3) == row1
assert table1.get_row(4) == row2
assert table1.schema == row1._schema
Expand Down Expand Up @@ -52,7 +52,7 @@ def test_add_rows_table_valid() -> None:
)
table2 = Table.from_rows([row1, row2])
table1 = table1.add_rows(table2)
assert table1.n_rows == 5
assert table1.number_of_rows == 5
assert table1.get_row(3) == row1
assert table1.get_row(4) == row2
assert table1.schema == row1._schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def test_filter_rows_valid() -> None:
result_table = table.filter_rows(lambda row: row.get_value("col1") == 1)
assert result_table.get_column("col1").get_value(0) == 1
assert result_table.get_column("col2").get_value(1) == 4
assert result_table.n_columns == 2
assert result_table.n_rows == 2
assert result_table.number_of_columns == 2
assert result_table.number_of_rows == 2


# noinspection PyTypeChecker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
(Table.from_dict({"col1": [], "col2": []}), 2),
],
)
def test_count_columns(table: Table, expected: int) -> None:
assert table.n_columns == expected
def test_number_of_columns(table: Table, expected: int) -> None:
assert table.number_of_columns == expected
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
(Table.from_dict({"col1": [1, 2], "col2": [3, 4]}), 2),
],
)
def test_count_rows(table: Table, expected: int) -> None:
assert table.n_rows == expected
def test_number_of_rows(table: Table, expected: int) -> None:
assert table.number_of_rows == expected
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_remove_rows_with_missing_values_valid() -> None:
},
)
updated_table = table.remove_rows_with_missing_values()
assert updated_table.n_rows == 2
assert updated_table.number_of_rows == 2


def test_remove_rows_with_missing_values_empty() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def test_remove_rows_with_outliers_no_outliers() -> None:
)
names = table.column_names
result = table.remove_rows_with_outliers()
assert result.n_rows == 3
assert result.n_columns == 3
assert result.number_of_rows == 3
assert result.number_of_columns == 3
assert names == table.column_names


Expand Down Expand Up @@ -54,5 +54,5 @@ def test_remove_rows_with_outliers_with_outliers() -> None:
def test_remove_rows_with_outliers_no_rows() -> None:
table = Table([], Schema({"col1": RealNumber()}))
result = table.remove_rows_with_outliers()
assert result.n_rows == 0
assert result.n_columns == 1
assert result.number_of_rows == 0
assert result.number_of_columns == 1
2 changes: 1 addition & 1 deletion tests/safeds/data/tabular/containers/_table/test_rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_rename_valid(name_from: str, name_to: str, column_one: str, column_two:
renamed_table = table.rename_column(name_from, name_to)
assert renamed_table.schema.has_column(column_one)
assert renamed_table.schema.has_column(column_two)
assert renamed_table.n_columns == 2
assert renamed_table.number_of_columns == 2


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ def test_sort_columns_valid(query: Callable[[Column, Column], int], col1: int, c
assert table_sorted_columns[1] == columns[col2]
assert table_sorted_columns[2] == columns[col3]
assert table_sorted_columns[3] == columns[col4]
assert table_sorted.n_columns == 4
assert table_sorted.n_rows == table1.n_rows
assert table_sorted.number_of_columns == 4
assert table_sorted.number_of_rows == table1.number_of_rows
2 changes: 1 addition & 1 deletion tests/safeds/data/tabular/containers/_table/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def test_create_empty_table() -> None:
table = Table([], Schema({"col1": RealNumber()}))
col = table.get_column("col1")
assert col.n_rows == 0
assert col.number_of_rows == 0
assert isinstance(col.type, RealNumber)
assert col.name == "col1"

Expand Down
4 changes: 2 additions & 2 deletions tests/safeds/data/tabular/containers/test_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_should_return_the_column_names(self, row: Row, expected: list[str]) ->
assert row.column_names == expected


class TestNColumns:
class TestNumberOfColumns:
@pytest.mark.parametrize(
("row", "expected"),
[
Expand All @@ -294,7 +294,7 @@ class TestNColumns:
],
)
def test_should_return_the_number_of_columns(self, row: Row, expected: int) -> None:
assert row.n_columns == expected
assert row.number_of_column == expected


class TestGetValue:
Expand Down

0 comments on commit f4f44a6

Please sign in to comment.