diff --git a/cognite/client/_api/data_modeling/instances.py b/cognite/client/_api/data_modeling/instances.py index 4d6fe60243..0763fc274f 100644 --- a/cognite/client/_api/data_modeling/instances.py +++ b/cognite/client/_api/data_modeling/instances.py @@ -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: diff --git a/cognite/client/_api/raw.py b/cognite/client/_api/raw.py index a4352df7b2..6965a94ffb 100644 --- a/cognite/client/_api/raw.py +++ b/cognite/client/_api/raw.py @@ -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: diff --git a/cognite/client/_api/sequences.py b/cognite/client/_api/sequences.py index 9a8d1f1861..6399595932 100644 --- a/cognite/client/_api/sequences.py +++ b/cognite/client/_api/sequences.py @@ -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)) diff --git a/cognite/client/data_classes/data_modeling/ids.py b/cognite/client/data_classes/data_modeling/ids.py index 2e591a9fb0..3d2195a04a 100644 --- a/cognite/client/data_classes/data_modeling/ids.py +++ b/cognite/client/data_classes/data_modeling/ids.py @@ -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) @@ -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) diff --git a/cognite/client/data_classes/time_series.py b/cognite/client/data_classes/time_series.py index 2ac973ee02..4777bd67e9 100644 --- a/cognite/client/data_classes/time_series.py +++ b/cognite/client/data_classes/time_series.py @@ -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( diff --git a/cognite/client/utils/_auxiliary.py b/cognite/client/utils/_auxiliary.py index 3b7961b835..001c496ff8 100644 --- a/cognite/client/utils/_auxiliary.py +++ b/cognite/client/utils/_auxiliary.py @@ -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: diff --git a/tests/tests_integration/test_api/test_time_series.py b/tests/tests_integration/test_api/test_time_series.py index 9d0634e359..30873293ae 100644 --- a/tests/tests_integration/test_api/test_time_series.py +++ b/tests/tests_integration/test_api/test_time_series.py @@ -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): diff --git a/tests/tests_unit/test_api/test_raw.py b/tests/tests_unit/test_api/test_raw.py index 47386472a4..b47d6effb7 100644 --- a/tests/tests_unit/test_api/test_raw.py +++ b/tests/tests_unit/test_api/test_raw.py @@ -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): @@ -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") diff --git a/tests/tests_unit/test_data_classes/test_time_series.py b/tests/tests_unit/test_data_classes/test_time_series.py index 2860c4b34e..ebff91ec2b 100644 --- a/tests/tests_unit/test_data_classes/test_time_series.py +++ b/tests/tests_unit/test_data_classes/test_time_series.py @@ -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):