Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/pandas/core/indexes/frozen.py: 44%
42 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1"""
2frozen (immutable) data structures to support MultiIndexing
4These are used for:
6- .names (FrozenList)
8"""
9from __future__ import annotations
11from typing import (
12 Any,
13 NoReturn,
14)
16from pandas.core.base import PandasObject
18from pandas.io.formats.printing import pprint_thing
21class FrozenList(PandasObject, list):
22 """
23 Container that doesn't allow setting item *but*
24 because it's technically hashable, will be used
25 for lookups, appropriately, etc.
26 """
28 # Side note: This has to be of type list. Otherwise,
29 # it messes up PyTables type checks.
31 def union(self, other) -> FrozenList:
32 """
33 Returns a FrozenList with other concatenated to the end of self.
35 Parameters
36 ----------
37 other : array-like
38 The array-like whose elements we are concatenating.
40 Returns
41 -------
42 FrozenList
43 The collection difference between self and other.
44 """
45 if isinstance(other, tuple):
46 other = list(other)
47 return type(self)(super().__add__(other))
49 def difference(self, other) -> FrozenList:
50 """
51 Returns a FrozenList with elements from other removed from self.
53 Parameters
54 ----------
55 other : array-like
56 The array-like whose elements we are removing self.
58 Returns
59 -------
60 FrozenList
61 The collection difference between self and other.
62 """
63 other = set(other)
64 temp = [x for x in self if x not in other]
65 return type(self)(temp)
67 # TODO: Consider deprecating these in favor of `union` (xref gh-15506)
68 __add__ = __iadd__ = union
70 def __getitem__(self, n):
71 if isinstance(n, slice):
72 return type(self)(super().__getitem__(n))
73 return super().__getitem__(n)
75 def __radd__(self, other):
76 if isinstance(other, tuple):
77 other = list(other)
78 return type(self)(other + list(self))
80 def __eq__(self, other: Any) -> bool:
81 if isinstance(other, (tuple, FrozenList)):
82 other = list(other)
83 return super().__eq__(other)
85 __req__ = __eq__
87 def __mul__(self, other):
88 return type(self)(super().__mul__(other))
90 __imul__ = __mul__
92 def __reduce__(self):
93 return type(self), (list(self),)
95 # error: Signature of "__hash__" incompatible with supertype "list"
96 def __hash__(self) -> int: # type: ignore[override]
97 return hash(tuple(self))
99 def _disabled(self, *args, **kwargs) -> NoReturn:
100 """
101 This method will not function because object is immutable.
102 """
103 raise TypeError(f"'{type(self).__name__}' does not support mutable operations.")
105 def __str__(self) -> str:
106 return pprint_thing(self, quote_strings=True, escape_chars=("\t", "\r", "\n"))
108 def __repr__(self) -> str:
109 return f"{type(self).__name__}({str(self)})"
111 __setitem__ = __setslice__ = _disabled # type: ignore[assignment]
112 __delitem__ = __delslice__ = _disabled
113 pop = append = extend = _disabled
114 remove = sort = insert = _disabled # type: ignore[assignment]