1212
1313from probables .blooms .bloom import BloomFilter
1414from probables .constants import UINT32_T_MAX , UINT64_T_MAX
15- from probables .exceptions import InitializationError
15+ from probables .exceptions import InitializationError , SimilarityError
1616from probables .hashes import HashFuncT , HashResultsT , KeyT
1717from probables .utilities import is_hex_string , is_valid_file , resolve_path
1818
@@ -208,7 +208,7 @@ def remove_alt(self, hashes: HashResultsT, num_els: int = 1) -> int:
208208 self .elements_added -= to_remove
209209 return min_val - to_remove
210210
211- def intersection (self , second : "CountingBloomFilter" ) -> Union [ "CountingBloomFilter" , None ] : # type: ignore
211+ def intersection (self , second : "CountingBloomFilter" ) -> "CountingBloomFilter" : # type: ignore
212212 """Take the intersection of two Counting Bloom Filters
213213
214214 Args:
@@ -217,17 +217,16 @@ def intersection(self, second: "CountingBloomFilter") -> Union["CountingBloomFil
217217 CountingBloomFilter: The new Counting Bloom Filter containing the union
218218 Raises:
219219 TypeError: When second is not a :class:`CountingBloomFilter`
220+ SimilarityError: When second is not of the same size (false_positive_rate and est_elements)
220221 Note:
221222 The elements_added property will be set to the estimated number of unique elements \
222- added as found in estimate_elements()
223- Note:
224- If `second` is not of the same size (false_positive_rate and est_elements) then \
225- this will return `None`"""
223+ added as found in estimate_elements()"""
226224 if not _verify_not_type_mismatch (second ):
227225 raise TypeError (MISMATCH_MSG )
228226
229227 if self ._verify_bloom_similarity (second ) is False :
230- return None
228+ raise SimilarityError ("Counting Bloom Filters are not similar enough to calculate similarity" )
229+
231230 res = CountingBloomFilter (
232231 est_elements = self .estimated_elements ,
233232 false_positive_rate = self .false_positive_rate ,
@@ -241,7 +240,7 @@ def intersection(self, second: "CountingBloomFilter") -> Union["CountingBloomFil
241240 res .elements_added = res .estimate_elements ()
242241 return res
243242
244- def jaccard_index (self , second : "CountingBloomFilter" ) -> Union [ float , None ] : # type:ignore
243+ def jaccard_index (self , second : "CountingBloomFilter" ) -> float : # type: ignore
245244 """Take the Jaccard Index of two Counting Bloom Filters
246245
247246 Args:
@@ -250,15 +249,14 @@ def jaccard_index(self, second: "CountingBloomFilter") -> Union[float, None]: #
250249 float: A numeric value between 0 and 1 where 1 is identical and 0 means completely different
251250 Raises:
252251 TypeError: When second is not a :class:`CountingBloomFilter`
252+ SimilarityError: When second is not of the same size (false_positive_rate and est_elements)
253253 Note:
254- The Jaccard Index is based on the unique set of elements added and not the number of each element added
255- Note:
256- If `second` is not of the same size (false_positive_rate and est_elements) then this will return `None`"""
254+ The Jaccard Index is based on the unique set of elements added and not the number of each element added"""
257255 if not _verify_not_type_mismatch (second ):
258256 raise TypeError (MISMATCH_MSG )
259257
260258 if self ._verify_bloom_similarity (second ) is False :
261- return None
259+ raise SimilarityError ( "Counting Bloom Filters are not similar enough to calculate similarity" )
262260
263261 count_union = 0
264262 count_inter = 0
@@ -271,7 +269,7 @@ def jaccard_index(self, second: "CountingBloomFilter") -> Union[float, None]: #
271269 return 1.0
272270 return count_inter / count_union
273271
274- def union (self , second : "CountingBloomFilter" ) -> Union [ "CountingBloomFilter" , None ] : # type:ignore
272+ def union (self , second : "CountingBloomFilter" ) -> "CountingBloomFilter" : # type:ignore
275273 """Return a new Countiong Bloom Filter that contains the union of
276274 the two
277275
@@ -281,16 +279,16 @@ def union(self, second: "CountingBloomFilter") -> Union["CountingBloomFilter", N
281279 CountingBloomFilter: The new Counting Bloom Filter containing the union
282280 Raises:
283281 TypeError: When second is not a :class:`CountingBloomFilter`
282+ SimilarityError: When second is not of the same size (false_positive_rate and est_elements)
284283 Note:
285284 The elements_added property will be set to the estimated number of unique elements added as \
286- found in estimate_elements()
287- Note:
288- If `second` is not of the same size (false_positive_rate and est_elements) then this will return `None`"""
285+ found in estimate_elements()"""
289286 if not _verify_not_type_mismatch (second ):
290287 raise TypeError (MISMATCH_MSG )
291288
292289 if self ._verify_bloom_similarity (second ) is False :
293- return None
290+ raise SimilarityError ("Counting Bloom Filters are not similar enough to calculate similarity" )
291+
294292 res = CountingBloomFilter (
295293 est_elements = self .estimated_elements ,
296294 false_positive_rate = self .false_positive_rate ,
0 commit comments