2
2
3
3
import sys
4
4
from abc import ABCMeta , abstractmethod
5
- from collections .abc import MutableSequence
5
+ from collections .abc import Generator , Iterable , Mapping , MutableSequence
6
6
from enum import Enum
7
7
from typing import (
8
8
Any ,
9
9
Callable ,
10
- Dict ,
11
- Generator ,
12
- Iterable ,
13
- List ,
14
- Mapping ,
15
10
Optional ,
16
- Set ,
17
- Tuple ,
18
- Type ,
19
11
TypeVar ,
20
12
Union ,
21
13
cast ,
38
30
FormulaSpec : TypeAlias = Union [
39
31
"Formula" ,
40
32
str ,
41
- List [Union [str , Term ]],
42
- Set [Union [str , Term ]],
43
- Dict [str , "FormulaSpec" ],
44
- Tuple ["FormulaSpec" , ...],
33
+ list [Union [str , Term ]],
34
+ set [Union [str , Term ]],
35
+ dict [str , "FormulaSpec" ],
36
+ tuple ["FormulaSpec" , ...],
45
37
Structured ["FormulaSpec" ],
46
38
]
47
39
_SelfType = TypeVar ("_SelfType" , bound = "Formula" )
@@ -281,7 +273,7 @@ def get_model_matrix(
281
273
self ,
282
274
data : Any ,
283
275
context : Optional [Mapping [str , Any ]] = None ,
284
- drop_rows : Optional [Set [int ]] = None ,
276
+ drop_rows : Optional [set [int ]] = None ,
285
277
** spec_overrides : Any ,
286
278
) -> Union [ModelMatrix , Structured [ModelMatrix ]]:
287
279
"""
@@ -302,7 +294,7 @@ def get_model_matrix(
302
294
303
295
@property
304
296
@abstractmethod
305
- def required_variables (self ) -> Set [Variable ]:
297
+ def required_variables (self ) -> set [Variable ]:
306
298
"""
307
299
The set of variables required to be in the data to materialize this
308
300
formula.
@@ -504,7 +496,7 @@ def get_model_matrix(
504
496
self ,
505
497
data : Any ,
506
498
context : Optional [Mapping [str , Any ]] = None ,
507
- drop_rows : Optional [Set [int ]] = None ,
499
+ drop_rows : Optional [set [int ]] = None ,
508
500
** spec_overrides : Any ,
509
501
) -> Union [ModelMatrix , Structured [ModelMatrix ]]:
510
502
"""
@@ -529,7 +521,7 @@ def get_model_matrix(
529
521
)
530
522
531
523
@property
532
- def required_variables (self ) -> Set [Variable ]:
524
+ def required_variables (self ) -> set [Variable ]:
533
525
"""
534
526
The set of variables required in the data order to materialize this
535
527
formula.
@@ -542,7 +534,7 @@ def required_variables(self) -> Set[Variable]:
542
534
evaluation context rather than the data context.
543
535
"""
544
536
545
- variables : List [Variable ] = [
537
+ variables : list [Variable ] = [
546
538
variable
547
539
for term in self .__terms
548
540
for factor in term .factors
@@ -605,11 +597,11 @@ def _map(
605
597
self ,
606
598
func : Union [
607
599
Callable [[SimpleFormula ], Any ],
608
- Callable [[SimpleFormula , Tuple [Union [str , int ], ...]], Any ],
600
+ Callable [[SimpleFormula , tuple [Union [str , int ], ...]], Any ],
609
601
],
610
602
recurse : bool = True ,
611
- as_type : Optional [Type [Structured ]] = None ,
612
- _context : Tuple [Union [str , int ], ...] = (),
603
+ as_type : Optional [type [Structured ]] = None ,
604
+ _context : tuple [Union [str , int ], ...] = (),
613
605
) -> Any :
614
606
try :
615
607
return func (self , ()) # type: ignore
@@ -629,7 +621,7 @@ def _flatten(self) -> Generator[SimpleFormula, None, None]:
629
621
as_of = (1 , 1 ),
630
622
removed_in = (2 , 0 ),
631
623
)
632
- def _to_dict (self ) -> Dict [str , SimpleFormula ]:
624
+ def _to_dict (self ) -> dict [str , SimpleFormula ]:
633
625
return {"root" : self }
634
626
635
627
@deprecated (
@@ -726,7 +718,7 @@ def get_model_matrix(
726
718
self ,
727
719
data : Any ,
728
720
context : Optional [Mapping [str , Any ]] = None ,
729
- drop_rows : Optional [Set [int ]] = None ,
721
+ drop_rows : Optional [set [int ]] = None ,
730
722
** spec_overrides : Any ,
731
723
) -> Union [ModelMatrix , Structured [ModelMatrix ]]:
732
724
"""
@@ -751,7 +743,7 @@ def get_model_matrix(
751
743
)
752
744
753
745
@property
754
- def required_variables (self ) -> Set [Variable ]:
746
+ def required_variables (self ) -> set [Variable ]:
755
747
"""
756
748
The set of variables required in the data order to materialize this
757
749
formula.
@@ -764,7 +756,7 @@ def required_variables(self) -> Set[Variable]:
764
756
evaluation context rather than the data context.
765
757
"""
766
758
767
- variables : List [Variable ] = []
759
+ variables : list [Variable ] = []
768
760
769
761
# Recurse through formula to collect all variables
770
762
self ._map (
@@ -797,7 +789,7 @@ def differentiate( # pylint: disable=redefined-builtin
797
789
)
798
790
799
791
# Ensure pickling never includes context
800
- def __getstate__ (self ) -> Tuple [None , Dict [str , Any ]]:
792
+ def __getstate__ (self ) -> tuple [None , dict [str , Any ]]:
801
793
slots = self .__slots__ + Structured .__slots__
802
794
return (
803
795
None ,
0 commit comments