Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pdfplumber/utils/generic.py: 36%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

11 statements  

1from collections.abc import Sequence 

2from typing import TYPE_CHECKING, Any, Dict, Hashable, List, Union 

3 

4from .._typing import T_seq 

5 

6if TYPE_CHECKING: # pragma: nocover 

7 from pandas.core.frame import DataFrame 

8 

9 

10def to_list(collection: Union[T_seq[Any], "DataFrame"]) -> List[Any]: 

11 if isinstance(collection, list): 

12 return collection 

13 elif isinstance(collection, Sequence): 

14 return list(collection) 

15 elif hasattr(collection, "to_dict"): 

16 res: List[Dict[Hashable, Any]] = collection.to_dict( 

17 "records" 

18 ) # pragma: nocover 

19 return res 

20 else: 

21 return list(collection)