| 1 |  |  | """This module defines the TabularDataInterface interface""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | from typing import Union, Iterable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | from abc import ABC, abstractmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | __all__ = ['TabularDataInterface'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class TabularDataInterface(ABC): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     """Table-like datapoints that are loaded in memory. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     Classes implementing this interface have the ability to report on various | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     elements and properties (eg rows, columns) of a table data-structure. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     @property | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     @abstractmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     def columns(self) -> Iterable: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         """List of the column identifiers.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         raise NotImplementedError | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     @property | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     @abstractmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     def rows(self) -> Iterable: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         """List of the row identifiers.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         raise NotImplementedError | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     @abstractmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     def column(self, identifier: Union[str, int]) -> Iterable: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         """Get the data inside a column of the table. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         Args: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             identifier (Union[str, int]): a primitive identifier to distinguish between the columns | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         Returns: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             Iterable: the data contained in the table's requested column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         raise NotImplementedError | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 39 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     @abstractmethod | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     def row(self, identifier: Union[str, int]) -> Iterable: | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         """Get the data inside a row of the table. | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         Args: | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |             identifier (Union[str, int]): a primitive identifier to distinguish between the rows | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         Returns: | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |             Iterable: the data contained in the table's requested row | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         """ | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         raise NotImplementedError | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     @property | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     @abstractmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     def nb_columns(self) -> int: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         """The number of the table's columns. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         Returns: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             int: the number of columns | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         raise NotImplementedError | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     @property | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     @abstractmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     def nb_rows(self) -> int: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         """The number of the table's rows. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         Returns: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             int: the number of rows | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         raise NotImplementedError | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     @abstractmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     def iterrows(self) -> Iterable: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         """Iterate over the table's rows.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         raise NotImplementedError | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     @abstractmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     def itercolumns(self) -> Iterable: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         """Iterate over the table's columns.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         raise NotImplementedError | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     @abstractmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     def __len__(self) -> int: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         """The table's length as the number of rows.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         raise NotImplementedError | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     @abstractmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     def __iter__(self) -> Iterable: | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 89 |  |  |         """Iterate over the table's rows.""" | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |         raise NotImplementedError  |