| # `lenu - Legal Entity Name Understanding` by GLEIF and Sociovestix Labs | |
| # Written in 2022 by Sociovestix Labs | |
| # To the extent possible under law, the author(s) have dedicated all copyright | |
| # and related and neighboring rights to this software to the public domain | |
| # worldwide. This software is distributed without any warranty. | |
| # | |
| # You should have received a copy of the CC0 Public Domain Dedication along | |
| # with this software. | |
| # If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | |
| """This helper script creates the classnames variable for lenu.py""" | |
| from lenu import URL | |
| import pandas | |
| relevant_cols = [ | |
| "LEI", | |
| "Entity.LegalName", | |
| "Entity.LegalForm.EntityLegalFormCode", | |
| "Entity.LegalJurisdiction", | |
| "Entity.EntityCategory", | |
| "Entity.EntityStatus", | |
| "Registration.RegistrationStatus", | |
| ] | |
| COL_LEI, COL_NAME, COL_ELF, COL_JUR, COL_CAT, COL_ESTATUS, COL_RSTATUS = relevant_cols | |
| if __name__ == "__main__": | |
| d = pandas.read_csv( | |
| URL, | |
| compression="zip", | |
| low_memory=True, | |
| dtype=str, | |
| # the following will prevent pandas from converting words like 'NA' to NaN. We want to work with the LEI data as is. | |
| na_values=[""], | |
| keep_default_na=False, | |
| usecols=relevant_cols, | |
| ) | |
| d_issued = d[(d[COL_ESTATUS] == "ACTIVE") & (d[COL_RSTATUS] == "ISSUED")] | |
| classnames = { | |
| jur: classes | |
| for jur, classes in d_issued.groupby(COL_JUR)[COL_ELF] | |
| .unique() | |
| .apply(list) | |
| .to_dict() | |
| .items() | |
| if jur | |
| in [ | |
| "AT", | |
| "AU", | |
| "CH", | |
| "CN", | |
| "CZ", | |
| "DE", | |
| "DK", | |
| "EE", | |
| "ES", | |
| "FI", | |
| "GB", | |
| "HU", | |
| "IE", | |
| "JP", | |
| "KY", | |
| "LI", | |
| "LU", | |
| "NL", | |
| "NO", | |
| "PL", | |
| "PT", | |
| "SE", | |
| "US-CA", | |
| "US-DE", | |
| "US-MA", | |
| "US-NY", | |
| "VG", | |
| "ZA", | |
| ] # not CA, BE, FR, BG | |
| } | |
| print("Please copy the following snippet into lenu.py:") | |
| print("") | |
| print("classnames = ", classnames) | |