Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/firestore_v1/vector.py: 53%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

19 statements  

1# -*- coding: utf-8 -*- 

2# Copyright 2024 Google LLC 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15 

16import collections 

17from typing import Sequence 

18 

19 

20class Vector(collections.abc.Sequence): 

21 r"""A class to represent Firestore Vector in python. 

22 

23 Underlying object will be converted to a map representation in Firestore API. 

24 """ 

25 

26 _value: Sequence[float] = () 

27 

28 def __init__(self, value: Sequence[float]): 

29 self._value = tuple([float(v) for v in value]) 

30 

31 def __getitem__(self, arg): 

32 return self._value[arg] 

33 

34 def __len__(self): 

35 return len(self._value) 

36 

37 def __eq__(self, other: object) -> bool: 

38 if not isinstance(other, Vector): 

39 return False 

40 return self._value == other._value 

41 

42 def __repr__(self): 

43 return f"Vector<{str(self._value)[1:-1]}>" 

44 

45 def to_map_value(self): 

46 return {"__type__": "__vector__", "value": self._value}