Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def read_manual_references(path):
"""
Read manual references (overrides) in JSON CSL specified by a pathlib.Path.
Returns a standard_citation to citeproc dictionary.
"""
if not path.is_file():
return dict()
with path.open() as read_file:
csl_items = json.load(read_file)
manual_refs = dict()
for csl_item in csl_items:
standard_citation = csl_item.pop('standard_citation')
csl_item['id'] = get_citation_id(standard_citation)
manual_refs[standard_citation] = csl_item
return manual_refs
if args.citation_tags_path.is_file():
tag_df = pandas.read_table(args.citation_tags_path)
na_rows_df = tag_df[tag_df.isnull().any(axis='columns')]
if not na_rows_df.empty:
logging.error(f'{args.citation_tags_path} contains rows with missing values:\n{na_rows_df}\nThis error can be caused by using spaces rather than tabs to delimit fields.\nProceeding to reread TSV with delim_whitespace=True.') # noqa: E501
tag_df = pandas.read_table(args.citation_tags_path, delim_whitespace=True)
tag_df['string'] = '@tag:' + tag_df.tag
for citation in tag_df.citation:
is_valid_citation_string('@' + citation)
citation_df = citation_df.merge(tag_df[['string', 'citation']], how='left')
else:
citation_df['citation'] = None
logging.info(f'missing {args.citation_tags_path} file: no citation tags set')
citation_df.citation.fillna(citation_df.string.astype(str).str.lstrip('@'), inplace=True)
citation_df['standard_citation'] = citation_df.citation.map(standardize_citation)
citation_df['citation_id'] = citation_df.standard_citation.map(get_citation_id)
citation_df = citation_df.sort_values(['standard_citation', 'citation'])
citation_df.to_csv(args.citations_path, sep='\t', index=False)
check_collisions(citation_df)
check_multiple_citation_strings(citation_df)
return citation_df