Skip to content

Commit

Permalink
refactor: remove freezed .when and .map
Browse files Browse the repository at this point in the history
  • Loading branch information
Desdaemon committed Dec 30, 2023
1 parent 0022ccc commit 0e140e9
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 13,235 deletions.
7 changes: 7 additions & 0 deletions packages/polars/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
targets:
$default:
builders:
freezed:
options:
map: false
when: false
4 changes: 2 additions & 2 deletions packages/polars/lib/polars.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// Dart bindings for the polars library.
library;

export 'src/wrapper/df.dart';
export 'src/wrapper/df.dart' hide SpecialEqPSeries, PExpr;
export 'src/wrapper/entry.dart';
export 'src/wrapper/expr.dart' hide SpecialEqPSeries;
export 'src/wrapper/expr.dart';
export 'src/wrapper/series.dart';

import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
Expand Down
16 changes: 16 additions & 0 deletions packages/polars/lib/src/expr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ extension ExprExt on Expr {
Expr col(String column) => Expr.column(column);
Expr cols(Iterable<String> columns) =>
Expr.columns(columns.toList(growable: false));
Expr dtypes(Iterable<DataType> dtypes) =>
Expr.dtypeColumn(dtypes.toList(growable: false));

Expr when(
Expr condition, {
Expand Down Expand Up @@ -217,3 +219,17 @@ int _assertNonNegative(int value) {
assert(value >= 0, 'Value must be non-negative.');
return value;
}

const int8 = DataType.int8();
const int16 = DataType.int16();
const int32 = DataType.int32();
const int64 = DataType.int64();
const uint8 = DataType.uint8();
const uint16 = DataType.uint16();
const uint32 = DataType.uint32();
const uint64 = DataType.uint64();
const utf8 = DataType.utf8();
const boolean = DataType.boolean();
const binary = DataType.binary();
const time = DataType.time();
const unknown = DataType.unknown();
39 changes: 34 additions & 5 deletions packages/polars/lib/src/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
}

abstract class RustLibApi extends BaseApi {
DataFrame dataFrameClone({required DataFrame that, dynamic hint});

Series dataFrameColumn(
{required DataFrame that, required String column, dynamic hint});

Expand Down Expand Up @@ -148,7 +150,8 @@ abstract class RustLibApi extends BaseApi {

LazyFrame lazyFrameCache({required LazyFrame that, dynamic hint});

Future<DataFrame> lazyFrameCollect({required LazyFrame that, dynamic hint});
Future<DataFrame> lazyFrameCollect(
{required LazyFrame that, bool streaming = false, dynamic hint});

LazyFrame lazyFrameCrossJoin(
{required LazyFrame that, required LazyFrame other, dynamic hint});
Expand Down Expand Up @@ -907,6 +910,30 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
required super.portManager,
});

@override
DataFrame dataFrameClone({required DataFrame that, dynamic hint}) {
return handler.executeSync(SyncTask(
callFfi: () {
var arg0 = cst_encode_Auto_Ref_RustOpaque_stdsyncRwLockDataFrame(that);
return wire.wire_DataFrame_clone(arg0);
},
codec: DcoCodec(
decodeSuccessData:
dco_decode_Auto_Owned_RustOpaque_stdsyncRwLockDataFrame,
decodeErrorData: null,
),
constMeta: kDataFrameCloneConstMeta,
argValues: [that],
apiImpl: this,
hint: hint,
));
}

TaskConstMeta get kDataFrameCloneConstMeta => const TaskConstMeta(
debugName: "DataFrame_clone",
argNames: ["that"],
);

@override
Series dataFrameColumn(
{required DataFrame that, required String column, dynamic hint}) {
Expand Down Expand Up @@ -1671,28 +1698,30 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
);

@override
Future<DataFrame> lazyFrameCollect({required LazyFrame that, dynamic hint}) {
Future<DataFrame> lazyFrameCollect(
{required LazyFrame that, bool streaming = false, dynamic hint}) {
return handler.executeNormal(NormalTask(
callFfi: (port_) {
var arg0 =
cst_encode_Auto_Owned_RustOpaque_stdsyncRwLockLazyFrame(that);
return wire.wire_LazyFrame_collect(port_, arg0);
var arg1 = cst_encode_bool(streaming);
return wire.wire_LazyFrame_collect(port_, arg0, arg1);
},
codec: DcoCodec(
decodeSuccessData:
dco_decode_Auto_Owned_RustOpaque_stdsyncRwLockDataFrame,
decodeErrorData: dco_decode_AnyhowException,
),
constMeta: kLazyFrameCollectConstMeta,
argValues: [that],
argValues: [that, streaming],
apiImpl: this,
hint: hint,
));
}

TaskConstMeta get kLazyFrameCollectConstMeta => const TaskConstMeta(
debugName: "LazyFrame_collect",
argNames: ["that"],
argNames: ["that", "streaming"],
);

@override
Expand Down
25 changes: 21 additions & 4 deletions packages/polars/lib/src/frb_generated.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,21 @@ class RustLibWire implements BaseWire {
late final _dart_fn_deliver_output = _dart_fn_deliver_outputPtr
.asFunction<void Function(int, ffi.Pointer<ffi.Uint8>, int, int)>();

WireSyncRust2DartDco wire_DataFrame_clone(
ffi.Pointer<ffi.Void> that,
) {
return _wire_DataFrame_clone(
that,
);
}

late final _wire_DataFrame_clonePtr = _lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<ffi.Void>)>>('wire_DataFrame_clone');
late final _wire_DataFrame_clone = _wire_DataFrame_clonePtr
.asFunction<WireSyncRust2DartDco Function(ffi.Pointer<ffi.Void>)>();

WireSyncRust2DartDco wire_DataFrame_column(
ffi.Pointer<ffi.Void> that,
ffi.Pointer<wire_cst_list_prim_u_8> column,
Expand Down Expand Up @@ -2744,19 +2759,21 @@ class RustLibWire implements BaseWire {
void wire_LazyFrame_collect(
int port_,
ffi.Pointer<ffi.Void> that,
bool streaming,
) {
return _wire_LazyFrame_collect(
port_,
that,
streaming,
);
}

late final _wire_LazyFrame_collectPtr = _lookup<
ffi
.NativeFunction<ffi.Void Function(ffi.Int64, ffi.Pointer<ffi.Void>)>>(
'wire_LazyFrame_collect');
ffi.NativeFunction<
ffi.Void Function(ffi.Int64, ffi.Pointer<ffi.Void>,
ffi.Bool)>>('wire_LazyFrame_collect');
late final _wire_LazyFrame_collect = _wire_LazyFrame_collectPtr
.asFunction<void Function(int, ffi.Pointer<ffi.Void>)>();
.asFunction<void Function(int, ffi.Pointer<ffi.Void>, bool)>();

WireSyncRust2DartDco wire_LazyFrame_cross_join(
ffi.Pointer<ffi.Void> that,
Expand Down
16 changes: 14 additions & 2 deletions packages/polars/lib/src/wrapper/df.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ class DataFrame extends RustOpaque {
RustLib.instance.api.rust_arc_decrement_strong_count_DataFramePtr,
);

DataFrame clone({dynamic hint}) => RustLib.instance.api.dataFrameClone(
that: this,
);

/// Select a single column by name.
///
/// Note: A clone of the column is returned, rather than a reference.
Series column({required String column, dynamic hint}) =>
RustLib.instance.api.dataFrameColumn(
that: this,
Expand All @@ -78,6 +84,8 @@ class DataFrame extends RustOpaque {
);

/// Select multiple columns by name.
///
/// Note: Clones of the columns are returned, rather than a reference.
VecSeries columns({required List<String> columns, dynamic hint}) =>
RustLib.instance.api.dataFrameColumns(
that: this,
Expand Down Expand Up @@ -293,9 +301,12 @@ class LazyFrame extends RustOpaque {
);

/// Executes all lazy operations and collects results into a [DataFrame].
Future<DataFrame> collect({dynamic hint}) =>
///
/// Can also optionally be run in [streaming mode](https://docs.pola.rs/user-guide/concepts/streaming).
Future<DataFrame> collect({bool streaming = false, dynamic hint}) =>
RustLib.instance.api.lazyFrameCollect(
that: this,
streaming: streaming,
);

/// Creates the [Cartesian product](https://en.wikipedia.org/wiki/Cartesian_product) from both frames,
Expand Down Expand Up @@ -448,7 +459,8 @@ class LazyFrame extends RustOpaque {
that: this,
);

/// Melt this dataframe from the wide format to the long format.
/// [Melt](https://docs.pola.rs/user-guide/transformations/melt) this
/// dataframe from the wide format to the long format.
LazyFrame melt(
{required List<String> idVars,
required List<String> valueVars,
Expand Down
Loading

0 comments on commit 0e140e9

Please sign in to comment.