tlx/dynamodb/batch.py
def load_from_csv(csv_file, table):
    """ CSV must conform to the following format:
            first row:  Field names
            second row: Field types. One of: ['N', 'S']

        N.B Only works for flat data structures. i.e Maps/Lists/Sets are not supported
    """

    table = get_ddb_table(table)

    with io.open(csv_file, newline='') as csvfile:
        data = list(csv.reader(csvfile))

    field_names, types = data[0], data[1]

    # Throws KeyError if missing. Only string and number are supported for csv
    def _format_number(x):
        tmp = Decimal(x if x else 'Nan')
        if math.isnan(tmp) or math.isinf(tmp):
            # Remove Inf and Nan, DynamoDB does support them
            return None
        return tmp

    _this_func_map = {
        'N': _format_number,
        'S': lambda x: str(x),
    }

    # Decimal Conversion if string field
    try:
        ddata = [  # Not a generator for testing
            {
                k1: v1
                for k1, v1 in (
                    (k, _this_func_map[t](v))
                    for k, t, v in zip(field_names, types, d)
                )
                if v1
            }
            for d in data[2:]
        ]
    except KeyError:
        raise Exception("load_from_csv only supports Dynamo Types {}".format(list(_this_func_map)))

    batch_write(table, ddata)
 CSV must conform to the following format:
            first row:  Field names
            second row: Field types. One of: ['N', 'S']

        N.B Only works for flat data structures. i.e Maps/Lists/Sets are not supported
    
CSV must conform to the following format:
first row:  Field names
second row: Field types.

N.B Only works for flat data structures. i.e Maps/Lists/Sets are not supported
CSV must conform to the following format : first row : Field names second row : Field types . N . B Only works for flat data structures . i . e Maps / Lists / Sets are not supported
def load_from_csv(csv_file, table):
    table = get_ddb_table(table)
    with io.open(csv_file, newline='') as csvfile:
        data = list(csv.reader(csvfile))
    field_names, types = data[0], data[1]
    def _format_number(x):
        tmp = Decimal(x if x else 'Nan')
        if math.isnan(tmp) or math.isinf(tmp):
            return None
        return tmp
    _this_func_map = {
        'N': _format_number,
        'S': lambda x: str(x),
    }
    try:
        ddata = [  
            {
                k1: v1
                for k1, v1 in (
                    (k, _this_func_map[t](v))
                    for k, t, v in zip(field_names, types, d)
                )
                if v1
            }
            for d in data[2:]
        ]
    except KeyError:
        raise Exception("load_from_csv only supports Dynamo Types {}".format(list(_this_func_map)))
    batch_write(table, ddata)
def load_from_csv ( csv_file , table ) : table = get_ddb_table ( table ) with io . open ( csv_file , newline = '' ) as csvfile : data = list ( csv . reader ( csvfile ) ) field_names , types = data [ 0 ] , data [ 1 ] def _format_number ( x ) : tmp = Decimal ( x if x else 'Nan' ) if math . isnan ( tmp ) or math . isinf ( tmp ) : return None return tmp _this_func_map = { 'N' : _format_number , 'S' : lambda x : str ( x ) , } try : ddata = [ { k1 : v1 for k1 , v1 in ( ( k , _this_func_map [ t ] ( v ) ) for k , t , v in zip ( field_names , types , d ) ) if v1 } for d in data [ 2 : ] ] except KeyError : raise Exception ( "load_from_csv only supports Dynamo Types {}" . format ( list ( _this_func_map ) ) ) batch_write ( table , ddata )
CSV must conform to the following format:
first row:  Field names
second row: Field types.
CSV must conform to the following format : first row : Field names second row : Field types .
""" CSV must conform to the following format:
            first row:  Field names
            second row: Field types. One of: ['N', 'S']

        N.B Only works for flat data structures. i.e Maps/Lists/Sets are not supported
    """ # Throws KeyError if missing. Only string and number are supported for csv # Remove Inf and Nan, DynamoDB does support them # Decimal Conversion if string field # Not a generator for testing
csv_file
table