def ingest(cls, package="osp.fields", path="data/fields.csv"): """ Ingest fields. Args: package (str) path (str) """ reader = read_csv(package, path) for row in reader: # Sanifize field names. pf = clean_field_name(row["Primary Field"]) sf = clean_field_name(row["Secondary Field"]) # Parse abbreviations. abbrs = parse_abbrs(row["ABBRV"]) if abbrs: abbrs = filter_abbrs(abbrs) # If parent field, write row. if bool(row["Alpha Category"]): Field.create(name=pf) # Query for a parent field. field = Field.select().where(Field.name == pf).first() if field: Subfield.create(name=sf, abbreviations=abbrs, field=field)
def ingest(cls, package='osp.fields', path='data/fields.csv'): """ Ingest fields. Args: package (str) path (str) """ reader = read_csv(package, path) for row in reader: # Sanifize field names. pf = clean_field_name(row['Primary Field']) sf = clean_field_name(row['Secondary Field']) # Parse abbreviations. abbrs = parse_abbrs(row['ABBRV']) if abbrs: abbrs = filter_abbrs(abbrs) # If parent field, write row. if bool(row['Alpha Category']): Field.create(name=pf) # Query for a parent field. field = Field.select().where(Field.name == pf).first() if field: Subfield.create( name=sf, abbreviations=abbrs, field=field, )
def test_filter_abbrs(): """ filter_abbrs() should remove blacklisted abbreviations. """ filtered = filter_abbrs(['AB', 'CD', 'EF', 'GH'], ['CD', 'GH']) assert filtered == ['AB', 'EF']
def test_filter_abbrs(): """ filter_abbrs() should remove blacklisted abbreviations. """ filtered = filter_abbrs( ['AB', 'CD', 'EF', 'GH'], ['CD', 'GH'] ) assert filtered == ['AB', 'EF']