File size: 2,192 Bytes
829c4ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# `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",
            "LU",
            "NL",
            "NO",
            "PL",
            "SE",
            "US-CA",
            "US-DE",
            "US-NY",
            "VG",
            "LI",
            "ZA",
        ]  # not CA, BE, FR, BG
    }

    print("Please copy the following snippet into lenu.py:")
    print("")
    print("classnames = ", classnames)