Skip to content

Commit

Permalink
Deprecating instead of renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Bidek56 committed Jan 17, 2024
1 parent ce9a738 commit 05647a6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
27 changes: 27 additions & 0 deletions polars/lazy/expr/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,31 @@ export interface StringNamespace extends StringFunctions<Expr> {
* ```
*/
extract(pat: string | RegExp, groupIndex: number): Expr;
/**
* Parse string values as JSON.
* Throw errors if encounter invalid JSON strings.
* @params Not implemented ATM
* @returns DF with struct
* @deprecated @since 0.8.4 @use {@link jsonDecode}
* @example
* >>> df = pl.DataFrame( {json: ['{"a":1, "b": true}', null, '{"a":2, "b": false}']} )
* >>> df.select(pl.col("json").str.jsonExtract())
* shape: (3, 1)
* ┌─────────────┐
* │ json │
* │ --- │
* │ struct[2] │
* ╞═════════════╡
* │ {1,true} │
* │ {null,null} │
* │ {2,false} │
* └─────────────┘
* See Also
* ----------
* jsonPathMatch : Extract the first match of json string with provided JSONPath expression.
*/
jsonExtract(dtype?: DataType, inferSchemaLength?: number): Expr;
/**
* Parse string values as JSON.
* Throw errors if encounter invalid JSON strings.
Expand Down Expand Up @@ -343,6 +367,9 @@ export const ExprStringFunctions = (_expr: any): StringNamespace => {
extract(pat: string | RegExp, groupIndex: number) {
return wrap("strExtract", regexToString(pat), groupIndex);
},
jsonExtract(dtype?: DataType, inferSchemaLength?: number) {
return wrap("strJsonDecode", dtype, inferSchemaLength);
},
jsonDecode(dtype?: DataType, inferSchemaLength?: number) {
return wrap("strJsonDecode", dtype, inferSchemaLength);
},
Expand Down
10 changes: 10 additions & 0 deletions polars/series/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,13 @@ export interface Series
nullEqual?: boolean,
strict?: boolean,
): boolean;
/**
* __Set masked values__
* @param filter Boolean mask
* @param value value to replace masked values with
* @deprecated @since 0.8.4 @use {@link scatter}
*/
setAtIdx(indices: number[] | Series, value: any): void;
/**
* __Set masked values__
* @param filter Boolean mask
Expand Down Expand Up @@ -1602,6 +1609,9 @@ export function _Series(_s: any): Series {
clip(...args) {
return expr_op("clip", ...args);
},
setAtIdx(indices, value) {
_s.scatter(indices, value);
},
scatter(indices, value) {
indices = Series.isSeries(indices)
? indices.cast(DataType.UInt32)
Expand Down
21 changes: 20 additions & 1 deletion polars/series/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,25 @@ export interface StringNamespace extends StringFunctions<Series> {
/***
* Parse string values as JSON.
* @returns Utf8 array. Contain null if original value is null or the `jsonPath` return nothing.
* @deprecated @since 0.8.4 @use {@link jsonDecode}
* @example
* s = pl.Series("json", ['{"a":1, "b": true}', null, '{"a":2, "b": false}']);
* s.str.json_decode().as("json");
* s.str.jsonExtract().as("json");
* shape: (3,)
* Series: 'json' [struct[2]]
* [
* {1,true}
* {null,null}
* {2,false}
* ]
*/
jsonExtract(dtype?: DataType, inferSchemaLength?: number): Series;
/***
* Parse string values as JSON.
* @returns Utf8 array. Contain null if original value is null or the `jsonPath` return nothing.
* @example
* s = pl.Series("json", ['{"a":1, "b": true}', null, '{"a":2, "b": false}']);
* s.str.jsonDecode().as("json");
* shape: (3,)
* Series: 'json' [struct[2]]
* [
Expand Down Expand Up @@ -300,6 +316,9 @@ export const SeriesStringFunctions = (_s: any): StringNamespace => {
extract(pat: string | RegExp, groupIndex: number) {
return wrap("strExtract", regexToString(pat), groupIndex);
},
jsonExtract(dtype?: DataType, inferSchemaLength?: number) {
return wrap("strJsonDecode", dtype, inferSchemaLength);
},
jsonDecode(dtype?: DataType, inferSchemaLength?: number) {
return wrap("strJsonDecode", dtype, inferSchemaLength);
},
Expand Down

0 comments on commit 05647a6

Please sign in to comment.