[docs]classFloatList(NamedList):""" List of floats. This mimics a regular Python list except that anything added to it will be coerced into a float. None values are also acceptable and are treated as missing floats. The list may also be named (see :py:class:`~NamedList`), which provides some dictionary-like functionality. """def__init__(self,data:Optional[Iterable]=None,names:Optional[Names]=None,_validate:bool=True,):""" Args: data: Some iterable object where all values can be coerced to floats or are None. Alternatively this may itself be None, which defaults to an empty list. names: Names for the list elements, defaults to an empty list. _validate: Internal use only. """if_validate:ifdataisnotNone:ifisinstance(data,FloatList):data=data._dataelse:ifisinstance(data,NamedList):data=data._dataoriginal=datadata=list(_coerce_to_float(item)foriteminoriginal)super().__init__(data,names,_validate=_validate)
[docs]defset_value(self,index:Union[int,str],value:Any,in_place:bool=False)->"FloatList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_value` after coercing ``value`` to a float."""returnsuper().set_value(index,_coerce_to_float(value),in_place=in_place)
[docs]defset_slice(self,index:SubscriptTypes,value:Sequence,in_place:bool=False)->"FloatList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.set_slice` after coercing ``value`` to floats."""returnsuper().set_slice(index,_SubscriptCoercer(value),in_place=in_place)
[docs]defsafe_insert(self,index:Union[int,str],value:Any,in_place:bool=False)->"FloatList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_insert` after coercing ``value`` to a float."""returnsuper().safe_insert(index,_coerce_to_float(value),in_place=in_place)
[docs]defsafe_append(self,value:Any,in_place:bool=False)->"FloatList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_append` after coercing ``value`` to a float."""returnsuper().safe_append(_coerce_to_float(value),in_place=in_place)
[docs]defsafe_extend(self,other:Iterable,in_place:bool=True)->"FloatList":"""Calls :py:meth:`~biocutils.NamedList.NamedList.safe_extend` after coercing elements of ``other`` to floats."""returnsuper().safe_extend((_coerce_to_float(y)foryinother),in_place=in_place)