33from linearmodels .compat .pandas import ANNUAL_FREQ
44
55from collections import defaultdict
6- from typing import NamedTuple , TypeVar , cast
6+ from typing import Literal , NamedTuple , TypeVar , cast
77
88import numpy as np
99import numpy .random
@@ -122,15 +122,12 @@ def preconditioner(
122122def dummy_matrix (
123123 cats : linearmodels .typing .data .ArrayLike ,
124124 * ,
125- output_format : str = "csc" ,
126- drop : str = "first" ,
125+ output_format : Literal [ "csc" , "csr" , "coo" ] = "csc" ,
126+ drop : Literal [ "first" , "last" ] = "first" ,
127127 drop_all : bool = False ,
128128 precondition : bool = True ,
129129) -> tuple [
130- sp .csc_matrix
131- | sp .csr_matrix
132- | sp .coo_matrix
133- | linearmodels .typing .data .Float64Array ,
130+ sp .csc_matrix | sp .csr_matrix | sp .coo_matrix ,
134131 linearmodels .typing .data .Float64Array ,
135132]:
136133 """
@@ -146,7 +143,6 @@ def dummy_matrix(
146143 * "csc" - sparse matrix in compressed column form
147144 * "csr" - sparse matrix in compressed row form
148145 * "coo" - sparse matrix in coordinate form
149- * "array" - dense numpy ndarray
150146
151147 drop: {"first", "last"}
152148 Exclude either the first or last category. This only applies when
@@ -199,7 +195,7 @@ def dummy_matrix(
199195 data ["cols" ].append (cols )
200196 total_dummies += ncategories - (i > 0 )
201197
202- if output_format in ( "csc" , "array" ) :
198+ if output_format == "csc" :
203199 fmt = sp .csc_matrix
204200 elif output_format == "csr" :
205201 fmt = sp .csr_matrix
@@ -213,9 +209,6 @@ def dummy_matrix(
213209 (np .concatenate (data ["rows" ]), np .concatenate (data ["cols" ])),
214210 )
215211 )
216- if output_format == "array" :
217- out = out .toarray ()
218-
219212 if precondition :
220213 out , cond = preconditioner (out , copy = False )
221214 else :
0 commit comments