Get module attributes as a dictionary or pandas object. If ``unique``, checks that the value is unique for all modules and returns only the unique value. Otherwise, returns the values for all modules. If ``as_pandas``, returns either a pd.Series (if ``unique``) or
(self, *attrs, unique=False, as_pandas=True, drop_attr_names=False)
| 123 | yield name, module |
| 124 | |
| 125 | def get_attrs(self, *attrs, unique=False, as_pandas=True, drop_attr_names=False): |
| 126 | """ |
| 127 | Get module attributes as a dictionary or pandas object. |
| 128 | |
| 129 | If ``unique``, checks that the value is unique for all modules and returns only the unique value. |
| 130 | Otherwise, returns the values for all modules. |
| 131 | |
| 132 | If ``as_pandas``, returns either a pd.Series (if ``unique``) or pd.DataFrame of attributes. |
| 133 | |
| 134 | Parameters |
| 135 | ---------- |
| 136 | attrs : str |
| 137 | Names of module attributes to return. |
| 138 | |
| 139 | unique : bool, default False |
| 140 | Whether to check for and return a single, unique value for an attribute. |
| 141 | If different modules have different values, a ``ValueError`` will be raised. |
| 142 | |
| 143 | as_pandas : bool, default True |
| 144 | Whether to return either a pd.Series or pd.DataFrame. |
| 145 | If True, the return value will be a pd.Series if ``unique`` and a pd.DataFrame otherwise. |
| 146 | If False, returns a dict. |
| 147 | |
| 148 | .. note:: |
| 149 | If only some modules have a particular attribute, ``get_attrs`` will not raise an error. |
| 150 | |
| 151 | If ``unique``, the unique value of the modules containing the value will be returned. |
| 152 | Otherwise, ``NotImplemented`` will fill in missing values. |
| 153 | |
| 154 | drop_attr_names : bool, default False |
| 155 | Whether to drop attribute names. Ignored if ``unique`` and ``len(attrs) == 1``. |
| 156 | |
| 157 | Returns |
| 158 | ------- |
| 159 | d : dict or pd.DataFrame or pd.Series |
| 160 | * Returns dict if ``as_pandas`` is False. |
| 161 | |
| 162 | * Otherwise, returns a pd.Series if ``unique`` and a pd.DataFrame otherwise. |
| 163 | |
| 164 | Raises |
| 165 | ------ |
| 166 | ValueError |
| 167 | * If ``attrs`` is empty, or |
| 168 | * ``unique`` is True and non-unique values are found. |
| 169 | |
| 170 | AttributeError |
| 171 | If no module has the particular attribute. |
| 172 | |
| 173 | .. warning:: |
| 174 | This check is not performed if both ``unique`` and ``as_pandas`` are False. |
| 175 | |
| 176 | """ |
| 177 | if not attrs: |
| 178 | raise ValueError('Missing attrs to get.') |
| 179 | |
| 180 | if unique: |
| 181 | return self._get_unique_attrs(attrs, as_pandas, drop_attr_names) |
| 182 |