File tree Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -149,7 +149,15 @@ where
149
149
///
150
150
/// See also [`extend`](Self::extend) for appends to the underlying memory
151
151
pub fn append ( & mut self , other : & Self ) -> PolarsResult < ( ) > {
152
- self . append_owned ( other. clone ( ) )
152
+ update_sorted_flag_before_append :: < T > ( self , other) ;
153
+ let len = self . len ( ) ;
154
+ self . length = self
155
+ . length
156
+ . checked_add ( other. length )
157
+ . ok_or_else ( || polars_err ! ( ComputeError : LENGTH_LIMIT_MSG ) ) ?;
158
+ self . null_count += other. null_count ;
159
+ new_chunks ( & mut self . chunks , & other. chunks , len) ;
160
+ Ok ( ( ) )
153
161
}
154
162
155
163
/// Append in place. This is done by adding the chunks of `other` to this [`ChunkedArray`].
Original file line number Diff line number Diff line change @@ -1168,6 +1168,34 @@ impl DataFrame {
1168
1168
Ok ( self )
1169
1169
}
1170
1170
1171
+ pub fn vstack_mut_owned ( & mut self , other : DataFrame ) -> PolarsResult < & mut Self > {
1172
+ if self . width ( ) != other. width ( ) {
1173
+ polars_ensure ! (
1174
+ self . width( ) == 0 ,
1175
+ ShapeMismatch :
1176
+ "unable to append to a DataFrame of width {} with a DataFrame of width {}" ,
1177
+ self . width( ) , other. width( ) ,
1178
+ ) ;
1179
+ self . columns = other. columns ;
1180
+ self . height = other. height ;
1181
+ return Ok ( self ) ;
1182
+ }
1183
+
1184
+ self . columns
1185
+ . iter_mut ( )
1186
+ . zip ( other. columns . into_iter ( ) )
1187
+ . try_for_each :: < _ , PolarsResult < _ > > ( |( left, right) | {
1188
+ ensure_can_extend ( & * left, & right) ?;
1189
+ let right_name = right. name ( ) . clone ( ) ;
1190
+ left. append_owned ( right) . map_err ( |e| {
1191
+ e. context ( format ! ( "failed to vstack column '{right_name}'" ) . into ( ) )
1192
+ } ) ?;
1193
+ Ok ( ( ) )
1194
+ } ) ?;
1195
+ self . height += other. height ;
1196
+ Ok ( self )
1197
+ }
1198
+
1171
1199
/// Concatenate a [`DataFrame`] to this [`DataFrame`]
1172
1200
///
1173
1201
/// If many `vstack` operations are done, it is recommended to call [`DataFrame::align_chunks_par`].
Original file line number Diff line number Diff line change @@ -815,7 +815,7 @@ where
815
815
return Err ( width_mismatch ( & acc_df, & df) ) ;
816
816
}
817
817
818
- acc_df. vstack_mut ( & df) ?;
818
+ acc_df. vstack_mut_owned ( df) ?;
819
819
}
820
820
821
821
Ok ( acc_df)
You can’t perform that action at this time.
0 commit comments