Skip to content

Commit

Permalink
Fix type errors not TypeError (#1388)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonas Markussen <[email protected]@Jonass-MacBook-Pro.local>
Co-authored-by: Håkon V. Treider <[email protected]>
  • Loading branch information
3 people authored Oct 9, 2023
1 parent e058976 commit 707cf5d
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cognite/client/_api/data_modeling/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ def histogram(

for histogram in histogram_seq:
if not isinstance(histogram, Histogram):
raise ValueError(f"Not a histogram: {histogram}")
raise TypeError(f"Not a histogram: {histogram}")

body["aggregates"] = [histogram.dump(camel_case=True) for histogram in histogram_seq]
if filter:
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_api/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def _make_columns_param(self, columns: list[str] | None) -> str | None:
if columns is None:
return None
if not isinstance(columns, list):
raise ValueError("Expected a list for argument columns")
raise TypeError("Expected a list for argument columns")
if len(columns) == 0:
return ","
else:
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_api/sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ def insert(
elif isinstance(rows, SequenceType) and (len(rows) == 0 or isinstance(rows[0], tuple)):
all_rows = [{"rowNumber": k, "values": v} for k, v in rows]
else:
raise ValueError("Invalid format for 'rows', expected a list of tuples, list of dict or dict")
raise TypeError("Invalid format for 'rows', expected a list of tuples, list of dict or dict")

base_obj = Identifier.of_either(id, external_id).as_dict()
base_obj.update(self._process_columns(column_external_ids))
Expand Down
4 changes: 2 additions & 2 deletions cognite/client/data_classes/data_modeling/ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def load(cls: type[T_DataModelingId], data: dict | T_DataModelingId | tuple[str,
return cls(*data)
elif isinstance(data, dict):
return cls(**convert_all_keys_to_snake_case(rename_and_exclude_keys(data, exclude={"type"})))
raise ValueError(f"Cannot load {data} into {cls}, invalid type={type(data)}")
raise TypeError(f"Cannot load {data} into {cls}, invalid type={type(data)}")


T_DataModelingId = TypeVar("T_DataModelingId", bound=DataModelingId)
Expand Down Expand Up @@ -73,7 +73,7 @@ def load(
return cls(*data)
elif isinstance(data, dict):
return cls(**convert_all_keys_to_snake_case(rename_and_exclude_keys(data, exclude={"type"})))
raise ValueError(f"Cannot load {data} into {cls}, invalid type={type(data)}")
raise TypeError(f"Cannot load {data} into {cls}, invalid type={type(data)}")


T_Versioned_DataModeling_Id = TypeVar("T_Versioned_DataModeling_Id", bound=VersionedDataModelingId)
Expand Down
4 changes: 2 additions & 2 deletions cognite/client/data_classes/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def count(self) -> int:
int: The number of datapoints in this time series.
Raises:
ValueError: If the time series is string as count aggregate is only supported for numeric data
RuntimeError: If the time series is string, as count aggregate is only supported for numeric data
Returns:
int: The total number of datapoints
"""
if self.is_string:
raise ValueError("String time series does not support count aggregate.")
raise RuntimeError("String time series does not support count aggregate.")

identifier = Identifier.load(self.id, self.external_id).as_dict()
dps = self._cognite_client.time_series.data.retrieve(
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/utils/_auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def split_into_chunks(collection: list | dict, chunk_size: int) -> list[list] |
collection = list(collection.items())
return [dict(collection[i : i + chunk_size]) for i in range(0, len(collection), chunk_size)]

raise ValueError(f"Can only split list or dict, not {type(collection)}")
raise TypeError(f"Can only split list or dict, not {type(collection)}")


def convert_true_match(true_match: dict | list | tuple[int | str, int | str]) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_integration/test_api/test_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def test_get_count__numeric(self, test_tss, ts_idx, exp_count):

def test_get_count__string_fails(self, test_ts_string):
assert test_ts_string.is_string is True
with pytest.raises(ValueError, match="String time series does not support count aggregate."):
with pytest.raises(RuntimeError, match="String time series does not support count aggregate."):
test_ts_string.count()

def test_get_latest(self, test_ts_numeric, test_ts_string):
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_unit/test_api/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def test_list_cols_empty(self, cognite_client, mock_raw_row_response):
assert "columns=%2C&" in mock_raw_row_response.calls[0].request.path_url + "&"

def test_list_cols_str_not_supported(self, cognite_client, mock_raw_row_response):
with pytest.raises(ValueError):
with pytest.raises(TypeError):
cognite_client.raw.rows.list(db_name="db1", table_name="table1", columns="a,b")

def test_iter_single(self, cognite_client, mock_raw_row_response):
Expand Down Expand Up @@ -287,7 +287,7 @@ def test_iter_cols_empty(self, cognite_client, mock_raw_row_response):
assert "columns=%2C&" in mock_raw_row_response.calls[0].request.path_url + "&"

def test_iter_cols_str_not_supported(self, cognite_client, mock_raw_row_response):
with pytest.raises(ValueError):
with pytest.raises(TypeError):
cognite_client.raw.rows(db_name="db1", table_name="table1", columns="a,b")


Expand Down
2 changes: 1 addition & 1 deletion tests/tests_unit/test_data_classes/test_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def mock_get_first_dp_in_ts(mock_ts_by_ids_response, cognite_client):

class TestTimeSeries:
def test_get_count__string_raises(self, cognite_client, mock_ts_by_ids_response):
with pytest.raises(ValueError, match="String time series does not support count aggregate"):
with pytest.raises(RuntimeError, match="String time series does not support count aggregate"):
cognite_client.time_series.retrieve(id=1).count()

def test_get_latest(self, cognite_client, mock_get_latest_dp_in_ts):
Expand Down

0 comments on commit 707cf5d

Please sign in to comment.