4646
4747class BitsetDtype (ExtensionDtype ):
4848 """
49- A Bitset is represented by a fixed-width string, whose characters are each a uint8.
50- Elements of the set map 1:1 to these characters.
49+ A Bitset is represented by a fixed-width string, whose characters are each a uint8. Elements of the set map 1:1 to
50+ these characters.
5151
52- If the elements set is indexed starting from 0, then:
53- - The quotient of these indices (modulo 8) is the character within the string that contains the bit representing the element,
54- - The remainder (modulo 8) is the index within said character that represents the element itself.
52+ If the elements set is indexed starting from 0, then: - The quotient of these indices (modulo 8) is the character
53+ within the string that contains the bit representing the element, - The remainder (modulo 8) is the index within
54+ said character that represents the element itself.
5555
5656 The element map takes an element of the bitset as a key, and returns a tuple whose first element is the
57- corresponding string-character index, and the latter the uint8 representation of the element within that
58- string character.
57+ corresponding string-character index, and the latter the uint8 representation of the element within that string
58+ character.
5959 """
6060 _element_map : Dict [ElementType , Tuple [int , np .uint8 ]]
6161 _elements : Tuple [ElementType ]
@@ -71,7 +71,7 @@ def construct_from_string(cls, string: str) -> BitsetDtype:
7171 """
7272 Construct an instance of this class by passing in a string of the form
7373 that str(<instance of this class>) produces.
74-
74+
7575 That is, given a string of the form
7676 bitset(#elements): e1, e2, e3, ...
7777
@@ -101,7 +101,8 @@ def construct_from_string(cls, string: str) -> BitsetDtype:
101101 iterable_values = tuple (s .strip () for s in string .split ("," ))
102102 if n_elements is not None and len (iterable_values ) != n_elements :
103103 raise ValueError (
104- f"Requested bitset with { n_elements } elements, but provided { len (iterable_values )} elements: { iterable_values } "
104+ f"Requested bitset with { n_elements } elements, "
105+ f"but provided { len (iterable_values )} elements: { iterable_values } "
105106 )
106107 return BitsetDtype (s .strip () for s in string .split ("," ))
107108
@@ -351,7 +352,7 @@ def _uint8_view(self) -> NDArray[np.bytes_]:
351352 Each row ``i`` of this view corresponds to a bitset stored in this array.
352353 The value at index ``i, j`` in this view is the ``uint8`` that represents
353354 character ``j`` in ``self._data[i]``, which can have bitwise operations
354- performed on it.
355+ performed on it.
355356 """
356357 return self ._data .view (self ._uint8_view_format )
357358
@@ -463,17 +464,17 @@ def __cast_to_uint8(self, other: CastableForPandasOps) -> NDArray[np.uint8]:
463464
464465 Scalar elements:
465466 Cast to single-element sets, then treated as set.
466-
467+
467468 Sets:
468469 Are converted to the (array of) uint8s that represents the set.
469-
470+
470471 ``np.ndarray``s of ``np.uint8``
471472 Are returned if they have the same number of columns as ``self._uint8_view``.
472-
473+
473474 ``np.ndarray``s of ``np.dtype("Sx")``
474475 If ``x`` corresponds to the same fixed-width as ``self.dtype.np_array_dtype``, are cast
475476 to the corresponding ``np.uint8`` view, like ``self._uint8_view`` is from ``self._data``.
476-
477+
477478 BitsetArrays
478479 Return their ``_uint8_view`` attribute.
479480 """
@@ -508,13 +509,17 @@ def __cast_to_uint8(self, other: CastableForPandasOps) -> NDArray[np.uint8]:
508509 cast = self .dtype .as_uint8_array (other )
509510 return cast
510511
511- def __comparison_op (self , other : CastableForPandasOps , op : Callable [[Set [ElementType ], Set [ElementType ]], bool ]) -> BooleanArray :
512+ def __comparison_op (
513+ self ,
514+ other : CastableForPandasOps ,
515+ op : Callable [[Set [ElementType ], Set [ElementType ]], bool ],
516+ ) -> BooleanArray :
512517 """
513518 Abstract method for strict and non-strict comparison operations.
514519
515520 Notably, __eq__ does not redirect here since it is more efficient for us to convert
516521 the single value to a bytestring and use numpy array comparison.
517-
522+
518523 For the other set comparison methods however, it's easier as a first implementation
519524 for us to convert to sets and run the set operations. If there was a Pythonic way
520525 of doing "bitwise less than" and "bitwise greater than", we could instead take the
@@ -678,7 +683,8 @@ def copy(self) -> BitsetArray:
678683
679684 def isna (self ) -> NDArray :
680685 """
681- TODO: This isn't a great way to express missing data, but equally a bitset doesn't really ever contain missing data...
686+ TODO: This isn't a great way to express missing data, but equally a bitset doesn't really ever contain
687+ missing data...
682688 """
683689 return np .isnan (self ._data )
684690
0 commit comments