@@ -43,6 +43,9 @@ def __init__(
43
43
def columns (self ) -> list [str ]:
44
44
return self .dataframe .columns .tolist ()
45
45
46
+ def _dispatch_to_lazy (self , method : str , * args : Any , ** kwargs : Any ) -> Self :
47
+ return getattr (self .lazy (), method )(* args , ** kwargs ).collect ()
48
+
46
49
def __repr__ (self ) -> str : # pragma: no cover
47
50
header = f" Standard DataFrame (api_version={ self .api_version } ) "
48
51
length = len (header )
@@ -100,42 +103,40 @@ def select(
100
103
self ,
101
104
* exprs : IntoExpr | Iterable [IntoExpr ],
102
105
** named_exprs : IntoExpr ,
103
- ) -> DataFrameT :
104
- return self .lazy (). select ( * exprs , ** named_exprs ). collect ( )
106
+ ) -> Self :
107
+ return self ._dispatch_to_lazy ( " select" , * exprs , ** named_exprs )
105
108
106
109
def filter (
107
110
self ,
108
111
* predicates : IntoExpr | Iterable [IntoExpr ],
109
- ) -> DataFrameT :
110
- return self .lazy (). filter ( * predicates ). collect ( )
112
+ ) -> Self :
113
+ return self ._dispatch_to_lazy ( " filter" , * predicates )
111
114
112
115
def with_columns (
113
116
self ,
114
117
* exprs : IntoExpr | Iterable [IntoExpr ],
115
118
** named_exprs : IntoExpr ,
116
- ) -> DataFrameT :
117
- return self .lazy (). with_columns ( * exprs , ** named_exprs ). collect ( )
119
+ ) -> Self :
120
+ return self ._dispatch_to_lazy ( " with_columns" , * exprs , ** named_exprs )
118
121
119
122
def sort (
120
123
self ,
121
124
by : str | Iterable [str ],
122
125
* more_by : str ,
123
126
descending : bool | Iterable [bool ] = False ,
124
- ) -> DataFrameT :
125
- return self .lazy (). sort ( by , * more_by , descending = descending ). collect ( )
127
+ ) -> Self :
128
+ return self ._dispatch_to_lazy ( " sort" , by , * more_by , descending = descending )
126
129
127
130
def join (
128
131
self ,
129
- other : DataFrameT ,
132
+ other : Self ,
130
133
* ,
131
134
how : Literal ["left" , "inner" , "outer" ] = "inner" ,
132
135
left_on : str | list [str ],
133
136
right_on : str | list [str ],
134
- ) -> DataFrameT :
135
- return (
136
- self .lazy ()
137
- .join (other .lazy (), how = how , left_on = left_on , right_on = right_on )
138
- .collect ()
137
+ ) -> Self :
138
+ return self ._dispatch_to_lazy (
139
+ "join" , other .lazy (), how = how , left_on = left_on , right_on = right_on
139
140
)
140
141
141
142
def lazy (self ) -> LazyFrame :
@@ -145,14 +146,14 @@ def lazy(self) -> LazyFrame:
145
146
implementation = self ._implementation ,
146
147
)
147
148
148
- def head (self , n : int ) -> DataFrameT :
149
- return self .lazy (). head ( n ). collect ( )
149
+ def head (self , n : int ) -> Self :
150
+ return self ._dispatch_to_lazy ( " head" , n )
150
151
151
- def unique (self , subset : list [str ]) -> DataFrameT :
152
- return self .lazy (). unique ( subset ). collect ( )
152
+ def unique (self , subset : list [str ]) -> Self :
153
+ return self ._dispatch_to_lazy ( " unique" , subset )
153
154
154
- def rename (self , mapping : dict [str , str ]) -> DataFrameT :
155
- return self .lazy (). rename ( mapping ). collect ( )
155
+ def rename (self , mapping : dict [str , str ]) -> Self :
156
+ return self ._dispatch_to_lazy ( " rename" , mapping )
156
157
157
158
def to_numpy (self ) -> Any :
158
159
return self .dataframe .to_numpy ()
@@ -301,7 +302,7 @@ def sort(
301
302
# Other
302
303
def join (
303
304
self ,
304
- other : LazyFrameT ,
305
+ other : Self ,
305
306
* ,
306
307
how : Literal ["left" , "inner" , "outer" ] = "inner" ,
307
308
left_on : str | list [str ],
@@ -332,7 +333,7 @@ def join(
332
333
)
333
334
334
335
# Conversion
335
- def collect (self ) -> DataFrameT :
336
+ def collect (self ) -> DataFrame :
336
337
return DataFrame (
337
338
self .dataframe ,
338
339
api_version = self .api_version ,
0 commit comments