Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/pandas/core/indexes/frozen.py : 49%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2frozen (immutable) data structures to support MultiIndexing
4These are used for:
6- .names (FrozenList)
8"""
10from typing import Any
12from pandas.core.base import PandasObject
14from pandas.io.formats.printing import pprint_thing
17class FrozenList(PandasObject, list):
18 """
19 Container that doesn't allow setting item *but*
20 because it's technically non-hashable, will be used
21 for lookups, appropriately, etc.
22 """
24 # Side note: This has to be of type list. Otherwise,
25 # it messes up PyTables type checks.
27 def union(self, other) -> "FrozenList":
28 """
29 Returns a FrozenList with other concatenated to the end of self.
31 Parameters
32 ----------
33 other : array-like
34 The array-like whose elements we are concatenating.
36 Returns
37 -------
38 FrozenList
39 The collection difference between self and other.
40 """
41 if isinstance(other, tuple):
42 other = list(other)
43 return type(self)(super().__add__(other))
45 def difference(self, other) -> "FrozenList":
46 """
47 Returns a FrozenList with elements from other removed from self.
49 Parameters
50 ----------
51 other : array-like
52 The array-like whose elements we are removing self.
54 Returns
55 -------
56 FrozenList
57 The collection difference between self and other.
58 """
59 other = set(other)
60 temp = [x for x in self if x not in other]
61 return type(self)(temp)
63 # TODO: Consider deprecating these in favor of `union` (xref gh-15506)
64 __add__ = __iadd__ = union
66 def __getitem__(self, n):
67 if isinstance(n, slice):
68 return type(self)(super().__getitem__(n))
69 return super().__getitem__(n)
71 def __radd__(self, other):
72 if isinstance(other, tuple):
73 other = list(other)
74 return type(self)(other + list(self))
76 def __eq__(self, other: Any) -> bool:
77 if isinstance(other, (tuple, FrozenList)):
78 other = list(other)
79 return super().__eq__(other)
81 __req__ = __eq__
83 def __mul__(self, other):
84 return type(self)(super().__mul__(other))
86 __imul__ = __mul__
88 def __reduce__(self):
89 return type(self), (list(self),)
91 def __hash__(self):
92 return hash(tuple(self))
94 def _disabled(self, *args, **kwargs):
95 """
96 This method will not function because object is immutable.
97 """
98 raise TypeError(f"'{type(self).__name__}' does not support mutable operations.")
100 def __str__(self) -> str:
101 return pprint_thing(self, quote_strings=True, escape_chars=("\t", "\r", "\n"))
103 def __repr__(self) -> str:
104 return f"{type(self).__name__}({str(self)})"
106 __setitem__ = __setslice__ = __delitem__ = __delslice__ = _disabled
107 pop = append = extend = remove = sort = insert = _disabled