Skip to content

Commit 2155f99

Browse files
committed
Improved naming [skip ci]
1 parent 60990c2 commit 2155f99

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

pgvector/bit.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
class Bit:
88
def __init__(self, value: bytes | str | list[bool] | np.ndarray[tuple[int], np.dtype[np.bool | np.uint8]]) -> None:
99
if isinstance(value, bytes):
10-
_len = 8 * len(value)
11-
_data = value
10+
length = 8 * len(value)
11+
data = value
1212
else:
1313
if isinstance(value, str):
1414
value = [v != '0' for v in value]
@@ -30,10 +30,10 @@ def __init__(self, value: bytes | str | list[bool] | np.ndarray[tuple[int], np.d
3030
if value.ndim != 1:
3131
raise ValueError('expected ndim to be 1')
3232

33-
_len = len(value)
34-
_data = np.packbits(value).tobytes()
33+
length = len(value)
34+
data = np.packbits(value).tobytes()
3535

36-
self._value = pack('>i', _len) + _data
36+
self._value = pack('>i', length) + data
3737

3838
def __repr__(self) -> str:
3939
return f'Bit({self.to_text()})'
@@ -43,18 +43,18 @@ def __eq__(self, other: object) -> bool:
4343
return self.to_binary() == other.to_binary()
4444
return False
4545

46-
def _len(self):
47-
_len, = unpack_from('>i', self._value)
48-
return _len
46+
def _length(self):
47+
length, = unpack_from('>i', self._value)
48+
return length
4949

5050
def to_list(self) -> list[bool]:
5151
return self.to_numpy().tolist()
5252

5353
def to_numpy(self) -> np.ndarray[tuple[int], np.dtype[np.bool]]:
54-
return np.unpackbits(np.frombuffer(self._value[4:], dtype=np.uint8), count=self._len()).astype(bool)
54+
return np.unpackbits(np.frombuffer(self._value[4:], dtype=np.uint8), count=self._length()).astype(bool)
5555

5656
def to_text(self) -> str:
57-
return ''.join(format(v, '08b') for v in self._value[4:])[:self._len()]
57+
return ''.join(format(v, '08b') for v in self._value[4:])[:self._length()]
5858

5959
def to_binary(self) -> bytes:
6060
return self._value

0 commit comments

Comments
 (0)