Skip to content

Commit

Permalink
Clarify the usage of fork
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdemartini committed Sep 29, 2020
1 parent a705160 commit b6d84b2
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 50 deletions.
11 changes: 5 additions & 6 deletions docs/packages/data-mate/data-frame.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ export class DataFrame {
config: DataTypeConfig;

/**
* Create a fork of the DataFrame
* Create a new DataFrame with the same metadata but with different data
*/
fork(columns: Column[]): DataFrame;


/**
* Get a column, or columns by name, returns a new DataFrame
*/
Expand Down Expand Up @@ -224,9 +223,9 @@ export class Column {
config: DataTypeFieldConfig;

/**
* Create a fork of the Column
* Create a new Column with the same metadata but with different data
*/
fork(vector?: Vector): Column;
fork(vector: Vector): Column;

/**
* Transform the values with in a column.
Expand Down Expand Up @@ -377,9 +376,9 @@ export abstract class Vector {
get(index: number, json?: boolean): any;

/**
* Create a fork of the Vector
* Create a new Vector with the same metadata but with different data
*/
fork(data?: Data): Vector;
fork(data: Data): Vector;

/**
* Create a new Vector with the range of values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class AggregationFrame<T extends Record<string, any>> {
for (const c of this.columns) {
columns.push(c);
if (c === col) {
const newCol = c.fork();
const newCol = c.fork(c.vector);
newCol.name = as;
columns.push(newCol);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/data-mate/src/column/Column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ export class Column<T = unknown> {
}

/**
* Create a fork of the Column
* Create a new Column with the same metadata but with different data
*/
fork(vector?: Vector<T>): Column<T> {
return new Column<T>(vector ?? this.vector, {
fork(vector: Vector<T>): Column<T> {
return new Column<T>(vector, {
name: this.name,
version: this.version,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/data-mate/src/data-frame/DataFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ export class DataFrame<
}

/**
* Create a fork of the DataFrame
* Create a new DataFrame with the same metadata but with different data
*/
fork<R extends Record<string, unknown> = T>(
columns = this.columns
columns: Column<any>[]|readonly Column<any>[]
): DataFrame<R> {
return new DataFrame<R>(columns, {
name: this.name,
Expand Down Expand Up @@ -323,7 +323,7 @@ export class DataFrame<
): DataFrame<Omit<T, K> & Record<R, T[K]>> {
return this.fork(this.columns.map((col): Column<any> => {
if (col.name !== name) return col;
const newCol = col.fork();
const newCol = col.fork(col.vector);
newCol.name = renameTo;
return newCol;
}));
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/ListVector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Vector, VectorOptions } from './Vector';
import { VectorType } from './interfaces';
import { Data, VectorType } from './interfaces';

export class ListVector<T = unknown> extends Vector<Vector<T>> {
static valueToJSON(value: Vector<any>): any {
Expand All @@ -13,7 +13,7 @@ export class ListVector<T = unknown> extends Vector<Vector<T>> {
});
}

fork(data = this.data): ListVector<T> {
fork(data: Data<Vector<T>>): ListVector<T> {
return new ListVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/Vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ export abstract class Vector<T = unknown> {
}

/**
* Create a fork of the Vector
* Create a new Vector with the same metadata but with different data
*/
abstract fork(data?: Data<T>): Vector<T>;
abstract fork(data: Data<T>): Vector<T>;

/**
* Create a new Vector with the range of values
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/types/AnyVector.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Vector, VectorOptions } from '../Vector';
import { VectorType } from '../interfaces';
import { Data, VectorType } from '../interfaces';

export class AnyVector extends Vector<any> {
constructor(options: VectorOptions<any>) {
super(VectorType.Any, options);
}

fork(data = this.data): AnyVector {
fork(data: Data<any>): AnyVector {
return new AnyVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/types/BigIntVector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bigIntToJSON } from '@terascope/utils';
import { Vector, VectorOptions } from '../Vector';
import { VectorType } from '../interfaces';
import { Data, VectorType } from '../interfaces';

export class BigIntVector extends Vector<bigint> {
static valueToJSON(value: bigint): any {
Expand All @@ -14,7 +14,7 @@ export class BigIntVector extends Vector<bigint> {
});
}

fork(data = this.data): BigIntVector {
fork(data: Data<bigint>): BigIntVector {
return new BigIntVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/types/BooleanVector.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Vector, VectorOptions } from '../Vector';
import { VectorType } from '../interfaces';
import { Data, VectorType } from '../interfaces';

export class BooleanVector extends Vector<boolean> {
constructor(options: VectorOptions<boolean>) {
super(VectorType.Boolean, options);
}

fork(data = this.data): BooleanVector {
fork(data: Data<boolean>): BooleanVector {
return new BooleanVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/types/DateVector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-classes-per-file */
import { Vector, VectorOptions } from '../Vector';
import { VectorType } from '../interfaces';
import { Data, VectorType } from '../interfaces';

/**
* The internal date storage format
Expand Down Expand Up @@ -43,7 +43,7 @@ export class DateVector extends Vector<DateValue> {
});
}

fork(data = this.data): DateVector {
fork(data: Data<DateValue>): DateVector {
return new DateVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/types/FloatVector.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Vector, VectorOptions } from '../Vector';
import { VectorType } from '../interfaces';
import { Data, VectorType } from '../interfaces';

export class FloatVector extends Vector<number> {
constructor(options: VectorOptions<number>) {
super(VectorType.Float, options);
}

fork(data = this.data): FloatVector {
fork(data: Data<number>): FloatVector {
return new FloatVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
10 changes: 5 additions & 5 deletions packages/data-mate/src/vector/types/GeoJSONVector.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { GeoPoint } from '@terascope/types';
import { GeoShape } from '@terascope/types';
import { Vector, VectorOptions } from '../Vector';
import { VectorType } from '../interfaces';
import { Data, VectorType } from '../interfaces';

export class GeoJSONVector extends Vector<GeoPoint> {
constructor(options: VectorOptions<GeoPoint>) {
export class GeoJSONVector extends Vector<GeoShape> {
constructor(options: VectorOptions<GeoShape>) {
super(VectorType.GeoJSON, options);
}

fork(data = this.data): GeoJSONVector {
fork(data: Data<GeoShape>): GeoJSONVector {
return new GeoJSONVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/types/GeoPointVector.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { GeoPoint } from '@terascope/types';
import { Vector, VectorOptions } from '../Vector';
import { VectorType } from '../interfaces';
import { Data, VectorType } from '../interfaces';

export class GeoPointVector extends Vector<GeoPoint> {
constructor(options: VectorOptions<GeoPoint>) {
super(VectorType.GeoPoint, options);
}

fork(data = this.data): GeoPointVector {
fork(data: Data<GeoPoint>): GeoPointVector {
return new GeoPointVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/types/IPRangeVector.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Vector, VectorOptions } from '../Vector';
import { VectorType } from '../interfaces';
import { Data, VectorType } from '../interfaces';

export class IPRangeVector extends Vector<string> {
constructor(options: VectorOptions<string>) {
super(VectorType.IPRange, options);
}

fork(data = this.data): IPRangeVector {
fork(data: Data<string>): IPRangeVector {
return new IPRangeVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/types/IPVector.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Vector, VectorOptions } from '../Vector';
import { VectorType } from '../interfaces';
import { Data, VectorType } from '../interfaces';

export class IPVector extends Vector<string> {
constructor(options: VectorOptions<string>) {
super(VectorType.IP, options);
}

fork(data = this.data): IPVector {
fork(data: Data<string>): IPVector {
return new IPVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/types/IntVector.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Vector, VectorOptions } from '../Vector';
import { VectorType } from '../interfaces';
import { Data, VectorType } from '../interfaces';

export class IntVector extends Vector<number> {
constructor(options: VectorOptions<number>) {
super(VectorType.Int, options);
}

fork(data = this.data): IntVector {
fork(data: Data<number>): IntVector {
return new IntVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/types/ObjectVector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Vector, VectorOptions } from '../Vector';
import { VectorType } from '../interfaces';
import { Data, VectorType } from '../interfaces';

/**
* @todo we need an to serialize to JSON correctly
Expand All @@ -11,7 +11,7 @@ export class ObjectVector<
super(VectorType.Object, options);
}

fork(data = this.data): ObjectVector<T> {
fork(data: Data<T>): ObjectVector<T> {
return new ObjectVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/vector/types/StringVector.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Vector, VectorOptions } from '../Vector';
import { VectorType } from '../interfaces';
import { Data, VectorType } from '../interfaces';

export class StringVector extends Vector<string> {
constructor(options: VectorOptions<string>) {
super(VectorType.String, options);
}

fork(data = this.data): StringVector {
fork(data: Data<string>): StringVector {
return new StringVector({
valueToJSON: this.valueToJSON,
config: this.config,
Expand Down
6 changes: 3 additions & 3 deletions packages/data-mate/test/column/column-boolean-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Column (Boolean Types)', () => {
});

it('should have the same id when forked with the same vector', () => {
expect(col.fork().id).toEqual(col.id);
expect(col.fork(col.vector).id).toEqual(col.id);
});

it('should NOT have the same id when forked with a different vector', () => {
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('Column (Boolean Types)', () => {
});

it('should have the same id when forked with the same vector', () => {
expect(col.fork().id).toEqual(col.id);
expect(col.fork(col.vector).id).toEqual(col.id);
});

it('should NOT have the same id when forked with a different vector', () => {
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('Column (Boolean Types)', () => {
});

it('should have the same id when forked with the same vector', () => {
expect(col.fork().id).toEqual(col.id);
expect(col.fork(col.vector).id).toEqual(col.id);
});

it('should NOT have the same id when forked with a different vector', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/data-mate/test/column/column-date-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Column (Date Types)', () => {
});

it('should have the same id when forked with the same vector', () => {
expect(col.fork().id).toEqual(col.id);
expect(col.fork(col.vector).id).toEqual(col.id);
});

it('should NOT have the same id when forked with a different vector', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/data-mate/test/column/column-string-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Column (String Types)', () => {
});

it('should have the same id when forked with the same vector', () => {
expect(col.fork().id).toEqual(col.id);
expect(col.fork(col.vector).id).toEqual(col.id);
});

it('should NOT have the same id when forked with a different vector', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/data-mate/test/data-frame-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('DataFrame', () => {
name: 'Billy'
}
]);
const resultFrame = dataFrame.fork();
const resultFrame = dataFrame.fork(dataFrame.columns);
expect(resultFrame.id).toEqual(dataFrame.id);
});

Expand Down

0 comments on commit b6d84b2

Please sign in to comment.