Exemplo n.º 1
0
 def _first_valid_object(data_frame, column_name):
     """
     Returns the first object in a pandas DataFrame column that does not represent a missing type (None, NaN or NaT).
     """
     for cell in data_frame[column_name]:
         if not is_missing(cell):
             return cell
     return None
Exemplo n.º 2
0
 def _scan_column_for_type(data_frame, column_name):
     """
     Get the type of a column (fails if multiple types are found). Numpy scalar types are converted to dtypes.
     """
     col_type = None
     for cell in data_frame[column_name]:
         if not is_missing(cell):
             if col_type is not None:
                 if not types_are_equivalent(type(cell), col_type):
                     raise ValueError('More than one type in column ' + str(column_name) + '. Found '
                                      + col_type.__name__ + ' and ' + type(cell).__name__)
             else:
                 col_type = type(cell)
     col_type = Serializer._convert_to_dtype_if_numpy_type(col_type)
     return col_type
Exemplo n.º 3
0
 def _scan_list_column_for_element_type(data_frame, column_name):
     """
     Get the type of a list column (fails if multiple types are found). Numpy scalar types are converted to dtypes.
     """
     col_type = None
     for list_cell in data_frame[column_name]:
         if list_cell is not None:
             for cell in list_cell:
                 if not is_missing(cell):
                     if col_type is not None:
                         if not types_are_equivalent(type(cell), col_type):
                             raise ValueError('More than one type in column ' + str(column_name) + '. Found '
                                              + col_type.__name__ + ' and ' + type(cell).__name__)
                     else:
                         col_type = type(cell)
     if col_type == list or col_type == set:
         raise ValueError('Output table contains a nested collection. Nested collections are not yet supported.')
     col_type = Serializer._convert_to_dtype_if_numpy_type(col_type)
     return col_type