Skip to content

Commit 262b9e6

Browse files
Apply suggestions from code review
Co-authored-by: Alexander <47296670+Marsmaennchen221@users.noreply.github.com>
1 parent 8982880 commit 262b9e6

File tree

3 files changed

+34
-58
lines changed

3 files changed

+34
-58
lines changed

src/safeds/data/tabular/containers/_table.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,12 +1730,12 @@ def time_columns(self, target_name: str, time_name: str, feature_names: list[str
17301730
time_name : str
17311731
Name of the time column.
17321732
feature_names : list[str] | None
1733-
Names of the feature columns. If None, all columns except the target column are used.
1733+
Names of the feature columns. If None, all columns except the target and time columns are used.
17341734
17351735
Returns
17361736
-------
17371737
time_series : TimeSeries
1738-
A new tagged table with the given target and feature names.
1738+
A new time series with the given target, time and feature names.
17391739
17401740
Raises
17411741
------
@@ -1750,8 +1750,6 @@ def time_columns(self, target_name: str, time_name: str, feature_names: list[str
17501750
>>> table = Table.from_dict({"time": ["01.01", "01.02", "01.03"], "price": [1.10, 1.19, 1.79], "amount_bought": [74, 72, 51]})
17511751
>>> tagged_table = table.time_columns(target_name="amount_bought",time_name = "time", feature_names=["price"])
17521752
"""
1753-
from ._time_series import TimeSeries
1754-
17551753
return TimeSeries._from_table_to_time_series(self, target_name, time_name, feature_names)
17561754

17571755
def transform_column(self, name: str, transformer: Callable[[Row], Any]) -> Table:

src/safeds/data/tabular/containers/_tagged_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def filter_rows(self, query: Callable[[Row], bool]) -> TaggedTable:
396396
Returns
397397
-------
398398
result : TaggedTable
399-
A table containing only the rows to match the query.
399+
A new tagged table containing only the rows to match the query.
400400
"""
401401
return TaggedTable._from_table(
402402
super().filter_rows(query),

src/safeds/data/tabular/containers/_time_series.py

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _from_tagged_table(
5656
The tagged table.
5757
time_name: str
5858
Name of the time column.
59-
Retruns
59+
Returns
6060
-------
6161
time_series : TimeSeries
6262
the created time series
@@ -94,7 +94,6 @@ def _from_tagged_table(
9494
return result
9595

9696
@staticmethod
97-
# idk if this method should exist, because we cant use it like the Method in TaggedTable, but the Method is static and this seem to doesnt get checked by the megalinter.
9897
def _from_table_to_time_series(
9998
table: Table,
10099
target_name: str,
@@ -112,16 +111,16 @@ def _from_table_to_time_series(
112111
time_name: str
113112
Name of the date column.
114113
feature_names : list[str] | None
115-
Names of the feature columns. If None, all columns except the target column are used.
116-
Retruns
114+
Names of the feature columns. If None, all columns except the target and time columns are used.
115+
Returns
117116
-------
118117
time_series : TimeSeries
119118
the created time series
120119
121120
Raises
122121
------
123122
UnknownColumnNameError
124-
If target_name matches none of the column names.
123+
If target_name or time_name matches none of the column names.
125124
Value Error
126125
If no feature columns are specified
127126
@@ -153,7 +152,7 @@ def __init__(
153152
feature_names: list[str] | None = None,
154153
):
155154
"""
156-
Create a tagged table from a mapping of column names to their values.
155+
Create a time series from a mapping of column names to their values.
157156
158157
Parameters
159158
----------
@@ -164,7 +163,7 @@ def __init__(
164163
time_name : str
165164
Name of the time column
166165
feature_names : list[str] | None
167-
Names of the feature columns. If None, all columns except the target column are used.
166+
Names of the feature columns. If None, all columns except the target and time columns are used.
168167
169168
Raises
170169
------
@@ -214,35 +213,14 @@ def time(self) -> Column:
214213
"""
215214
return self._time
216215

217-
# ------------------------------------------------------------------------------------------------------------------
218-
# Specific methods from time series class:
219-
# ------------------------------------------------------------------------------------------------------------------
220-
221-
# def _create_moving_average(self, window_size: int) -> Column:
222-
# calculate the windows and the moving average of a timeserties, this function for now only has intern use
223-
# some unexpected behavior while casting to series agains, because it addds NAN values
224-
# return Column._from_pandas_series(pd.Series(self.target._data.rolling(window_size).mean()))
225-
# pass
226-
# def plot_moving_average(self, window_size: int) -> Image:
227-
# this method should plot the moving average of a time series
228-
# pass
229-
230-
# def show_time_series(self) -> Image:
231-
# this method should plot the time series
232-
# pass
233-
234-
# def decompose_time_series(self) -> Image:
235-
# this Method should show a plot of a decomposed time series
236-
# pass
237-
238216
# ------------------------------------------------------------------------------------------------------------------
239217
# Overriden methods from TaggedTable class:
240218
# ------------------------------------------------------------------------------------------------------------------
241219
def _as_table(self: TimeSeries) -> Table:
242220
"""
243221
Return a new `Table` with the tagging removed.
244222
245-
The original table is not modified.
223+
The original time series is not modified.
246224
247225
Parameters
248226
----------
@@ -252,7 +230,7 @@ def _as_table(self: TimeSeries) -> Table:
252230
Returns
253231
-------
254232
table: Table
255-
The table as an untagged Table, i.e. without the information about which columns are features, target or time.
233+
The time series as an untagged Table, i.e. without the information about which columns are features, target or time.
256234
257235
"""
258236
return Table.from_columns(super().to_columns())
@@ -261,7 +239,7 @@ def add_column(self, column: Column) -> TimeSeries:
261239
"""
262240
Return a new `TimeSeries` with the provided column attached at the end, as neither target nor feature column.
263241
264-
The original table is not modified.
242+
The original time series is not modified.
265243
266244
Parameters
267245
----------
@@ -271,7 +249,7 @@ def add_column(self, column: Column) -> TimeSeries:
271249
Returns
272250
-------
273251
result : TimeSeries
274-
The table with the column attached as neither target nor feature column.
252+
The time series with the column attached as neither target nor feature column.
275253
276254
Raises
277255
------
@@ -299,7 +277,7 @@ def add_column_as_feature(self, column: Column) -> TimeSeries:
299277
Returns
300278
-------
301279
result : TimeSeries
302-
The table with the attached feature column.
280+
The time series with the attached feature column.
303281
304282
Raises
305283
------
@@ -345,7 +323,7 @@ def add_columns(self, columns: list[Column] | Table) -> TimeSeries:
345323
"""
346324
Return a new `TimeSeries` with multiple added columns, as neither target nor feature columns.
347325
348-
The original table is not modified.
326+
The original time series is not modified.
349327
350328
Parameters
351329
----------
@@ -360,9 +338,9 @@ def add_columns(self, columns: list[Column] | Table) -> TimeSeries:
360338
Raises
361339
------
362340
DuplicateColumnNameError
363-
If at least one column name from the provided column list already exists in the table.
341+
If at least one column name from the provided column list already exists in the time series.
364342
ColumnSizeError
365-
If at least one of the column sizes from the provided column list does not match the table.
343+
If at least one of the column sizes from the provided column list does not match the time series.
366344
"""
367345
return TimeSeries._from_tagged_table(
368346
super().add_columns(columns),
@@ -373,7 +351,7 @@ def add_row(self, row: Row) -> TimeSeries:
373351
"""
374352
Return a new `TimeSeries` with an extra Row attached.
375353
376-
The original table is not modified.
354+
The original time series is not modified.
377355
378356
Parameters
379357
----------
@@ -388,15 +366,15 @@ def add_row(self, row: Row) -> TimeSeries:
388366
Raises
389367
------
390368
UnknownColumnNameError
391-
If the row has different column names than the table.
369+
If the row has different column names than the time series.
392370
"""
393371
return TimeSeries._from_tagged_table(super().add_row(row), time_name=self.time.name)
394372

395373
def add_rows(self, rows: list[Row] | Table) -> TimeSeries:
396374
"""
397375
Return a new `TimeSeries` with multiple extra Rows attached.
398376
399-
The original table is not modified.
377+
The original time series is not modified.
400378
401379
Parameters
402380
----------
@@ -406,12 +384,12 @@ def add_rows(self, rows: list[Row] | Table) -> TimeSeries:
406384
Returns
407385
-------
408386
result : TimeSeries
409-
A new time series which combines the original table and the given rows.
387+
A new time series which combines the original time series and the given rows.
410388
411389
Raises
412390
------
413391
UnknownColumnNameError
414-
If at least one of the rows have different column names than the table.
392+
If at least one of the rows have different column names than the time series.
415393
"""
416394
return TimeSeries._from_tagged_table(super().add_rows(rows), time_name=self.time.name)
417395

@@ -440,7 +418,7 @@ def keep_only_columns(self, column_names: list[str]) -> TimeSeries:
440418
"""
441419
Return a new `TimeSeries` with only the given column(s).
442420
443-
The original table is not modified.
421+
The original time series is not modified.
444422
445423
Parameters
446424
----------
@@ -457,7 +435,7 @@ def keep_only_columns(self, column_names: list[str]) -> TimeSeries:
457435
UnknownColumnNameError
458436
If any of the given columns does not exist.
459437
IllegalSchemaModificationError
460-
If none of the given columns is the target column or any of the feature columns.
438+
If none of the given columns is the target or time column or any of the feature columns.
461439
"""
462440
if self.target.name not in column_names:
463441
raise IllegalSchemaModificationError("Must keep the target column.")
@@ -479,9 +457,9 @@ def keep_only_columns(self, column_names: list[str]) -> TimeSeries:
479457

480458
def remove_columns(self, column_names: list[str]) -> TimeSeries:
481459
"""
482-
Return a new `TimeSeries` with the given column(s) removed from the table.
460+
Return a new `TimeSeries` with the given column(s) removed from the time series.
483461
484-
The original table is not modified.
462+
The original time series is not modified.
485463
486464
Parameters
487465
----------
@@ -526,7 +504,7 @@ def remove_columns_with_missing_values(self) -> TimeSeries:
526504
"""
527505
Return a new `TimeSeries` with every column that misses values removed.
528506
529-
The original table is not modified.
507+
The original time series is not modified.
530508
531509
Returns
532510
-------
@@ -561,7 +539,7 @@ def remove_columns_with_non_numerical_values(self) -> TimeSeries:
561539
"""
562540
Return a new `TimeSeries` with every column that contains non-numerical values removed.
563541
564-
The original table is not modified.
542+
The original time series is not modified.
565543
566544
Returns
567545
-------
@@ -665,9 +643,9 @@ def rename_column(self, old_name: str, new_name: str) -> TimeSeries:
665643
Parameters
666644
----------
667645
old_name : str
668-
The old name of the target column.
646+
The old name of the column.
669647
new_name : str
670-
The new name of the target column.
648+
The new name of the column.
671649
672650
Returns
673651
-------
@@ -705,7 +683,7 @@ def replace_column(self, old_column_name: str, new_columns: list[Column]) -> Tim
705683
becomes the new target or time column. If the column to be replaced is a feature column, the new columns that replace it
706684
all become feature columns.
707685
708-
The order of columns is kept. The original table is not modified.
686+
The order of columns is kept. The original time series is not modified.
709687
710688
Parameters
711689
----------
@@ -717,7 +695,7 @@ def replace_column(self, old_column_name: str, new_columns: list[Column]) -> Tim
717695
Returns
718696
-------
719697
result : TimeSeries
720-
A time series with the old column replaced by the new column.
698+
A time series with the old column replaced by the new columns.
721699
722700
Raises
723701
------
@@ -728,7 +706,7 @@ def replace_column(self, old_column_name: str, new_columns: list[Column]) -> Tim
728706
ColumnSizeError
729707
If the size of the column does not match the amount of rows.
730708
IllegalSchemaModificationError
731-
If the target column would be removed or replaced by more than one column.
709+
If the target or time column would be removed or replaced by more than one column.
732710
"""
733711
if old_column_name == self.time.name:
734712
if len(new_columns) != 1:
@@ -830,7 +808,7 @@ def sort_columns(
830808
831809
If no comparator is given, the columns will be sorted alphabetically by their name.
832810
833-
The original table is not modified.
811+
The original time series is not modified.
834812
835813
Parameters
836814
----------

0 commit comments

Comments
 (0)