8000 Support "I" and "O" in CUSIP number · Dj0ulo/python-stdnum@1364e19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1364e19

Browse files
committed
Support "I" and "O" in CUSIP number
It is unclear why these letters were considered invalid at the time of the implementation. This also reduces the test set a bit while still covering most cases. Closes arthurdejong#337
1 parent f972894 commit 1364e19

File tree

2 files changed

+9
-114
lines changed

2 files changed

+9
-114
lines changed

stdnum/cusip.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# cusip.py - functions for handling CUSIP numbers
22
#
3-
# Copyright (C) 2015-2017 Arthur de Jong
3+
# Copyright (C) 2015-2022 Arthur de Jong
44
#
55
# This library is free software; you can redistribute it and/or
66
# modify it under the terms of the GNU Lesser General Public
@@ -49,8 +49,7 @@ def compact(number):
4949
return clean(number, ' ').strip().upper()
5050

5151

52-
# O and I are not valid but are accounted for in the check digit calculation
53-
_alphabet = '0123456789ABCDEFGH JKLMN PQRSTUVWXYZ*@#'
52+
_alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*@#'
5453

5554

5655
def calc_check_digit(number):

tests/test_cusip.doctest

Lines changed: 7 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test_cusip.doctest - more detailed doctests for the stdnum.cusip module
22

3-
Copyright (C) 2015 Arthur de Jong
3+
Copyright (C) 2015-2022 Arthur de Jong
44

55
This library is free software; you can redistribute it and/or
66
modify it under the terms of the GNU Lesser General Public
@@ -25,223 +25,119 @@ tries to validate a number of numbers that have been found online.
2525
>>> from stdnum.exceptions import *
2626

2727

28-
Number should not use O (capital o) or I (capital 1) to avoid confusion with
28+
Previously it was thought that O (capital o) or I (capital 1) were not allowed but
29+
apparently
2930
0 and 1:
3031

31-
>>> cusip.validate('0O141T575')
32-
Traceback (most recent call last):
33-
...
34-
InvalidFormat: ...
35-
>>> cusip.validate('257I32103')
36-
Traceback (most recent call last):
37-
...
38-
InvalidFormat: ...
32+
>>> cusip.validate('FDIC90903')
33+
'FDIC90903'
3934

4035

4136
These have been found online and should all be valid numbers.
4237

4338
>>> numbers = '''
4439
...
45-
... 00078H125
46-
... 00080Y348
47-
... 00141H409
48-
... 00141M572
49-
... 00141T577
5040
... 00141V267
51-
... 00142F832
5241
... 00142K500
53-
... 00170J862
54-
... 00170K109
5542
... 00170M873
5643
... 00758M261
5744
... 024524746
58-
... 024932808
5945
... 024934408
6046
... 025081704
61-
... 025081860
62-
... 02631C817
6347
... 068278704
6448
... 068278878
65-
... 06828M405
6649
... 101156602
67-
... 119804102
68-
... 12628J600
6950
... 140543828
7051
... 192476109
71-
... 19765J830
72-
... 19765N401
73-
... 19765Y852
7452
... 207267105
7553
... 23336W809
7654
... 23337G134
77-
... 23337R502
78-
... 23338F713
79-
... 245908660
80-... 245917505
8155
... 24610B859
8256
... 25155T528
8357
... 25156A668
8458
... 25157M778
85-
... 25159K309
86-
... 25159L745
8759
... 25264S403
8860
... 254939424
89-
... 257132100
90-
... 258618701
91-
... 261967103
9261
... 261967822
9362
... 261986566
9463
... 265458513
9564
... 265458570
9665
... 269858817
97-
... 277902565
98-
... 277905436
9966
... 29372R208
10067
... 313923302
101-
... 314172743
102-
... 315792598
103-
... 315805325
104-
... 315807651
10568
... 315911875
10669
... 315920579
107-
... 316069103
108-
... 31607A208
109-
... 316146257
110-
... 316175850
111-
... 31638R204
112-
... 316390277
113-
... 316390335
11470
... 316390640
115-
... 316390681
11671
... 320600109
117-
... 320604606
11872
... 320917107
119-
... 353496854
120-
... 353535107
12173
... 354128704
12274
... 354723769
123-
... 36158T506
12475
... 409902624
12576
... 416649507
126-
... 416649606
12777
... 425888104
128-
... 42588P825
129-
... 42588P882
130-
... 44929K630
13178
... 461418691
13279
... 465898682
13380
... 469785109
13481
... 471023531
13582
... 47803M663
136-
... 4812A4427
13783
... 4812C0548
138-
... 52106N335
13984
... 52106N442
140-
... 52106N632
141-
... 52106N657
14285
... 543912604
143-
... 543913305
144-
... 552984601
145-
... 552986309
146-
... 552986853
147-
... 557492428
14886
... 56063J849
149-
... 56063U851
150-
... 56166Y438
15187
... 561709692
15288
... 561717661
15389
... 57056B ZW1
154-
... 575719109
15590
... 592905756
156-
... 61744J499
157-
... 640917209
15891
... 640917407
159-
... 64122M506
16092
... 643642200
161-
... 647108414
16293
... 648018828
163-
... 650914203
164-
... 66537Y165
16594
... 67065R408
16695
... 67065R812
167-
... 670678762
16896
... 670690767
16997
... 670700608
170-
... 670725738
171-
... 670729599
17298
... 670729730
173-
... 680029667
174-
... 68583W507
17599
... 704329101
176-
... 70472Q302
177100
... 70472Q880
178-
... 72200Q232
179-
... 72201F383
180-
... 72201F458
181-
... 72201M800
182101
... 72201T664
183102
... 72201U430
184-
... 741481105
185-
... 741486104
186-
... 74149P390
187103
... 74149P648
188104
... 74149P689
189-
... 74149P820
190105
... 742935521
191106
... 742935547
192-
... 74316P207
193107
... 743185373
194108
... 743185464
195109
... 74318Q864
196-
... 74683L508
197110
... 749255121
198-
... 74972H200
199111
... 74972H283
200-
... 74972H390
201112
... 74972H598
202-
... 74972K666
203113
... 76628T496
204114
... 77956H302
205-
... 783554470
206115
... 783554728
207116
... 784924458
208117
... 803431105
209118
... 803431410
210-
... 829334101
211119
... 82980D400
212120
... 884116872
213121
... 890085327
214-
... 890085871
215-
... 89354D874
216-
... 904504560
217122
... 904504586
218123
... 912810EQ7
219-
... 912828C24
220124
... 912828EG1
221125
... 912828HA1
222-
... 912828KD1
223-
... 912828UA6
224126
... 920461209
225127
... 92646A252
226-
... 92913K645
227128
... 92913K884
228129
... 92913L775
229-
... 92913R822
230130
... 92914A661
231131
... 93208V106
232-
... 936793306
233-
... 936793504
234-
... 94975P686
235132
... 94984B108
236133
... 94984B538
237134
... 949915177
238135
... 949915557
239136
... 957904584
240-
... 969251719
241-
... 969251834
242137
... 984281204
138+
... FDIC99375
139+
... FDIC99425
243140
... Y0488F100
244-
... Y27257149
245141
... Y44425117
246142
...
247143
... '''

0 commit comments

Comments
 (0)
0