Skip to content

Commit

Permalink
fixed UnknownError
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerhardsa0 committed Feb 27, 2024
1 parent 177c52e commit 7437360
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 23 deletions.
32 changes: 10 additions & 22 deletions src/safeds/data/tabular/containers/_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,20 +948,14 @@ def plot_time_series_lineplot(self, y_column_name: str | None = None,
self._data.index.name = "index"
if y_column_name is None:
y_column_name = self.target.name
else:
if y_column_name not in self._data.columns:
raise UnknownColumnNameError([y_column_name])
if x_column_name is None:
x_column_name = "index"
else:
if not self.get_column(x_column_name).type.is_numeric():
raise NonNumericColumnError("The time series plotted column contains non-numerical columns.")
if not self.has_column(x_column_name) or not self.has_column(y_column_name):
similar_columns_x = self._get_similar_columns(x_column_name)
similar_columns_y = self._get_similar_columns(y_column_name)
raise UnknownColumnNameError(
([x_column_name] if not self.has_column(x_column_name) else [])
+ ([y_column_name] if not self.has_column(y_column_name) else []),
(similar_columns_x if not self.has_column(x_column_name) else [])
+ (similar_columns_y if not self.has_column(y_column_name) else []),
)
if x_column_name not in self._data.columns:
raise UnknownColumnNameError([x_column_name])
if not self.get_column(y_column_name).type.is_numeric():
raise NonNumericColumnError("The time series plotted column contains non-numerical columns.")

Expand Down Expand Up @@ -1029,20 +1023,14 @@ def plot_time_series_scatterplot(
self._data.index.name = "index"
if y_column_name is None:
y_column_name = self.target.name
else:
if y_column_name not in self._data.columns:
raise UnknownColumnNameError([y_column_name])
if x_column_name is None:
x_column_name = "index"
else:
if not self.get_column(x_column_name).type.is_numeric():
raise NonNumericColumnError("The time series plotted column contains non-numerical columns.")
if not self.has_column(x_column_name) or not self.has_column(y_column_name):
similar_columns_x = self._get_similar_columns(x_column_name)
similar_columns_y = self._get_similar_columns(y_column_name)
raise UnknownColumnNameError(
([x_column_name] if not self.has_column(x_column_name) else [])
+ ([y_column_name] if not self.has_column(y_column_name) else []),
(similar_columns_x if not self.has_column(x_column_name) else [])
+ (similar_columns_y if not self.has_column(y_column_name) else []),
)
if x_column_name not in self._data.columns:
raise UnknownColumnNameError([x_column_name])
if not self.get_column(y_column_name).type.is_numeric():
raise NonNumericColumnError("The time series plotted column contains non-numerical columns.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_should_raise_if_column_contains_non_numerical_values() -> None:
r" non-numerical columns."
),
):
table.plot_time_series_lineplot()
table.plot_time_series_lineplot( x_column_name="target")


@pytest.mark.parametrize(
Expand Down Expand Up @@ -227,3 +227,40 @@ def test_should_raise_error_optional_parameter_y(
match=error_msg,
):
time_series.plot_time_series_lineplot(y_column_name=name)
def test_should_raise_if_column_does_not_exist_x() -> None:
table = TimeSeries(
{
"time": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"feature_1": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"target": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
},
target_name="target",
time_name="time",
feature_names=None,
)
with pytest.raises(
UnknownColumnNameError,
match=(
"Could not find column\(s\) '2'."
),
):
table.plot_time_series_lineplot( x_column_name="target", y_column_name="2")

def test_should_raise_if_column_does_not_exist_y() -> None:
table = TimeSeries(
{
"time": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"feature_1": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"target": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
},
target_name="target",
time_name="time",
feature_names=None,
)
with pytest.raises(
UnknownColumnNameError,
match=(
"Could not find column\(s\) '2'."
),
):
table.plot_time_series_lineplot( x_column_name="2", y_column_name="target")
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,41 @@ def test_should_raise_error_optional_parameter_y(
match=error_msg,
):
time_series.plot_time_series_scatterplot(y_column_name=name)

def test_should_raise_if_column_does_not_exist_x() -> None:
table = TimeSeries(
{
"time": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"feature_1": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"target": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
},
target_name="target",
time_name="time",
feature_names=None,
)
with pytest.raises(
UnknownColumnNameError,
match=(
"Could not find column\(s\) '2'."
),
):
table.plot_time_series_scatterplot( x_column_name="target", y_column_name="2")

def test_should_raise_if_column_does_not_exist_y() -> None:
table = TimeSeries(
{
"time": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"feature_1": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"target": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
},
target_name="target",
time_name="time",
feature_names=None,
)
with pytest.raises(
UnknownColumnNameError,
match=(
"Could not find column\(s\) '2'."
),
):
table.plot_time_series_scatterplot( x_column_name="2", y_column_name="target")

0 comments on commit 7437360

Please sign in to comment.