11from __future__ import annotations
22import polars as pl
3- from polars .utils .udfs import _get_shared_lib_location
4- from ._utils import pl_plugin , StrOrExpr
3+ from ._utils import pl_plugin
54
6- _lib = _get_shared_lib_location (__file__ )
75
8-
9- def cusip_extract_all (x : StrOrExpr ) -> pl .Expr :
6+ def cusip_extract_all (x : pl .Series | pl .Expr ) -> pl .Expr :
107 """
118 Returns a struct containing country_code, issue_num, issuer_num, check_digit,
129 or null, if it cannot be parsed.
@@ -15,106 +12,98 @@ def cusip_extract_all(x: StrOrExpr) -> pl.Expr:
1512 """
1613 return pl_plugin (
1714 args = [x ],
18- lib = _lib ,
1915 symbol = "pl_cusip_full" ,
2016 is_elementwise = True ,
2117 )
2218
2319
24- def cusip_issue_num (x : StrOrExpr ) -> pl .Expr :
20+ def cusip_issue_num (x : pl . Series | pl . Expr ) -> pl .Expr :
2521 """
2622 Returns the issue number from the CUSIP, or null if it cannot be parsed.
2723 """
2824 return pl_plugin (
2925 args = [x ],
30- lib = _lib ,
3126 symbol = "pl_cusip_issue_num" ,
3227 is_elementwise = True ,
3328 )
3429
3530
36- def cusip_issuer_num (x : StrOrExpr ) -> pl .Expr :
31+ def cusip_issuer_num (x : pl . Series | pl . Expr ) -> pl .Expr :
3732 """
3833 Returns the issuer number from the CUSIP, or null if it cannot be parsed.
3934 """
4035 return pl_plugin (
4136 args = [x ],
42- lib = _lib ,
4337 symbol = "pl_cusip_issuer_num" ,
4438 is_elementwise = True ,
4539 )
4640
4741
48- def cusip_check_digit (x : StrOrExpr ) -> pl .Expr :
42+ def cusip_check_digit (x : pl . Series | pl . Expr ) -> pl .Expr :
4943 """
5044 Returns check digit from the CUSIP, or null if it cannot be parsed.
5145 """
5246 return pl_plugin (
5347 args = [x ],
54- lib = _lib ,
5548 symbol = "pl_cusip_check_digit" ,
5649 is_elementwise = True ,
5750 )
5851
5952
60- def cusip_country_code (x : StrOrExpr ) -> pl .Expr :
53+ def cusip_country_code (x : pl . Series | pl . Expr ) -> pl .Expr :
6154 """
6255 Returns the country code from the CUSIP, or null if it cannot be parsed.
6356 """
6457 return pl_plugin (
6558 args = [x ],
66- lib = _lib ,
6759 symbol = "pl_cusip_country_code" ,
6860 is_elementwise = True ,
6961 )
7062
7163
72- def cusip_payload (x : StrOrExpr ) -> pl .Expr :
64+ def cusip_payload (x : pl . Series | pl . Expr ) -> pl .Expr :
7365 """
7466 Returns the payload (CUSIP ex. check digit) from the CUSIP, or null if it
7567 cannot be parsed.
7668 """
7769 return pl_plugin (
7870 args = [x ],
79- lib = _lib ,
8071 symbol = "pl_cusip_payload" ,
8172 is_elementwise = True ,
8273 )
8374
8475
85- def cusip_is_private_issue (x : StrOrExpr ) -> pl .Expr :
76+ def cusip_is_private_issue (x : pl . Series | pl . Expr ) -> pl .Expr :
8677 """
8778 Returns true if the issue number is reserved for private use.
8879 """
8980 return pl_plugin (
9081 args = [x ],
91- lib = _lib ,
9282 symbol = "pl_cusip_is_private_issue" ,
9383 is_elementwise = True ,
9484 )
9585
9686
97- def cusip_has_private_issuer (x : StrOrExpr ) -> pl .Expr :
87+ def cusip_has_private_issuer (x : pl . Series | pl . Expr ) -> pl .Expr :
9888 """
9989 Returns true if the issuer is reserved for private use.
10090 """
10191 return pl_plugin (
10292 args = [x ],
103- lib = _lib ,
10493 symbol = "pl_cusip_has_private_issuer" ,
10594 is_elementwise = True ,
10695 )
10796
10897
109- def cusip_is_private_use (x : StrOrExpr ) -> pl .Expr :
98+ def cusip_is_private_use (x : pl . Series | pl . Expr ) -> pl .Expr :
11099 """
111100 Returns True if either the issuer or issue number is reserved for
112101 private use.
113102 """
114- return pl_plugin (args = [x ], lib = _lib , symbol = "pl_cusip_is_private_use" , is_elementwise = True )
103+ return pl_plugin (args = [x ], symbol = "pl_cusip_is_private_use" , is_elementwise = True )
115104
116105
117- def cusip_is_cins (x : StrOrExpr ) -> pl .Expr :
106+ def cusip_is_cins (x : pl . Series | pl . Expr ) -> pl .Expr :
118107 """
119108 Returns true if this CUSIP number is actually a
120109 CUSIP International Numbering System (CINS) number,
@@ -123,10 +112,10 @@ def cusip_is_cins(x: StrOrExpr) -> pl.Expr:
123112
124113 Null if unable to parse.
125114 """
126- return pl_plugin (args = [x ], lib = _lib , symbol = "pl_cusip_is_cins" , is_elementwise = True )
115+ return pl_plugin (args = [x ], symbol = "pl_cusip_is_cins" , is_elementwise = True )
127116
128117
129- def cusip_is_cins_base (x : StrOrExpr ) -> pl .Expr :
118+ def cusip_is_cins_base (x : pl . Series | pl . Expr ) -> pl .Expr :
130119 """
131120 Returns true if this CUSIP identifier is actually a CUSIP International
132121 Numbering System (CINS) identifier (with the further restriction that
@@ -135,10 +124,10 @@ def cusip_is_cins_base(x: StrOrExpr) -> pl.Expr:
135124
136125 Null if unable to parse.
137126 """
138- return pl_plugin (args = [x ], lib = _lib , symbol = "pl_cusip_is_cins_base" , is_elementwise = True )
127+ return pl_plugin (args = [x ], symbol = "pl_cusip_is_cins_base" , is_elementwise = True )
139128
140129
141- def cusip_is_cins_extended (x : StrOrExpr ) -> pl .Expr :
130+ def cusip_is_cins_extended (x : pl . Series | pl . Expr ) -> pl .Expr :
142131 """
143132 Returns true if this CUSIP identifier is actually a CUSIP International
144133 Numbering System (CINS) identifier (with the further restriction that
@@ -147,92 +136,4 @@ def cusip_is_cins_extended(x: StrOrExpr) -> pl.Expr:
147136
148137 Null if unable to parse.
149138 """
150- return pl_plugin (args = [x ], lib = _lib , symbol = "pl_cusip_is_cins_extended" , is_elementwise = True )
151-
152-
153- @pl .api .register_expr_namespace ("cusip" )
154- class CusipExt :
155- """
156- This class contains tools for parsing CUSIP/CINS and Extended CINS format data.
157-
158- Polars Namespace: cusip
159-
160- Example: pl.col("cusip_cins_string").cusip.country_code()
161- """
162-
163- def __init__ (self , expr : pl .Expr ):
164- self ._expr : pl .Expr = expr
165-
166- def extract_all (self ) -> pl .Expr :
167- return self ._expr .register_plugin (
168- lib = _lib ,
169- symbol = "pl_cusip_full" ,
170- is_elementwise = True ,
171- )
172-
173- def issue_num (self ) -> pl .Expr :
174- return self ._expr .register_plugin (
175- lib = _lib ,
176- symbol = "pl_cusip_issue_num" ,
177- is_elementwise = True ,
178- )
179-
180- def issuer_num (self ) -> pl .Expr :
181- return self ._expr .register_plugin (
182- lib = _lib ,
183- symbol = "pl_cusip_issuer_num" ,
184- is_elementwise = True ,
185- )
186-
187- def check_digit (self ) -> pl .Expr :
188- return self ._expr .register_plugin (
189- lib = _lib ,
190- symbol = "pl_cusip_check_digit" ,
191- is_elementwise = True ,
192- )
193-
194- def country_code (self ) -> pl .Expr :
195- return self ._expr .register_plugin (
196- lib = _lib ,
197- symbol = "pl_cusip_country_code" ,
198- is_elementwise = True ,
199- )
200-
201- def payload (self ) -> pl .Expr :
202- return self ._expr .register_plugin (
203- lib = _lib ,
204- symbol = "pl_cusip_payload" ,
205- is_elementwise = True ,
206- )
207-
208- def is_private_issue (self ) -> pl .Expr :
209- return self ._expr .register_plugin (
210- lib = _lib ,
211- symbol = "pl_cusip_is_private_issue" ,
212- is_elementwise = True ,
213- )
214-
215- def has_private_issuer (self ) -> pl .Expr :
216- return self ._expr .register_plugin (
217- lib = _lib ,
218- symbol = "pl_cusip_has_private_issuer" ,
219- is_elementwise = True ,
220- )
221-
222- def is_private_use (self ) -> pl .Expr :
223- return self ._expr .register_plugin (
224- lib = _lib , symbol = "pl_cusip_is_private_use" , is_elementwise = True
225- )
226-
227- def is_cins (self ) -> pl .Expr :
228- return self ._expr .register_plugin (lib = _lib , symbol = "pl_cusip_is_cins" , is_elementwise = True )
229-
230- def is_cins_base (self ) -> pl .Expr :
231- return self ._expr .register_plugin (
232- lib = _lib , symbol = "pl_cusip_is_cins_base" , is_elementwise = True
233- )
234-
235- def is_cins_extended (self ) -> pl .Expr :
236- return self ._expr .register_plugin (
237- lib = _lib , symbol = "pl_cusip_is_cins_extended" , is_elementwise = True
238- )
139+ return pl_plugin (args = [x ], symbol = "pl_cusip_is_cins_extended" , is_elementwise = True )
0 commit comments