(callable: mapParam, options?: { inplace?: boolean })
| 997 | */ |
| 998 | map(callable: mapParam, options?: { inplace?: boolean }): Series |
| 999 | map(callable: mapParam, options?: { inplace?: boolean }): Series | void { |
| 1000 | const { inplace } = { inplace: false, ...options } |
| 1001 | |
| 1002 | const isCallable = utils.isFunction(callable); |
| 1003 | |
| 1004 | const data = (this.values as ArrayType1D).map((val: any, i: number) => { |
| 1005 | if (isCallable) { |
| 1006 | return (callable as Function)(val, i); |
| 1007 | } else if (utils.isObject(callable)) { |
| 1008 | if (val in callable) { |
| 1009 | //@ts-ignore |
| 1010 | return callable[val]; |
| 1011 | } else { |
| 1012 | return val |
| 1013 | } |
| 1014 | } else { |
| 1015 | throw new Error("Param Error: callable must either be a function or an object"); |
| 1016 | } |
| 1017 | }); |
| 1018 | |
| 1019 | if (inplace) { |
| 1020 | this.$setValues(data) |
| 1021 | } else { |
| 1022 | const sf = this.copy(); |
| 1023 | sf.$setValues(data) |
| 1024 | return sf; |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * Applies a function to each element of a Series |
nothing calls this directly
no test coverage detected