1 Star 4 Fork 11

王布衣 / pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
series_utils.go 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-02-24 21:43 . 适配num新版本0.1.5
package pandas
import (
"gitee.com/quant1x/num"
)
// Align2Series any转换成series
//
// N=-1, 即为全部
func Align2Series(x any, N int) Series {
ds := []num.DType{}
switch v := x.(type) {
//case int:
// ds = Repeat(DType(v), N)
//case []int:
// _N := Slice2DType(v)
// //nd := _N[len(_N) - 1]
// ds = Align[DType](_N, DTypeNaN, N)
//case []DType:
// ds = Align(v, DTypeNaN, N)
//case []T:
// vd := Slice2DType(v)
// ds = Align[DType](vd, DTypeNaN, N)
case nil:
ds = num.Repeat[num.DType](num.NaN(), N)
case /*nil, */ int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint, float32, float64, bool, string:
ds = num.Repeat[num.DType](num.Any2DType(v), N)
case []int8, []uint8, []int16, []uint16, []int32, []uint32, []int64, []uint64, []int, []uint, []uintptr, []float32, []float64, []bool, []string:
vd := num.Slice2DType(v)
if N == -1 {
N = len(vd)
}
ds = num.Align[num.DType](vd, num.NaN(), N)
case Series:
vd := v.DTypes()
if N == -1 {
N = len(vd)
}
ds = num.Align[num.DType](vd, num.NaN(), N)
default:
panic(num.TypeError(v))
}
return vector[num.DType](ds)
}
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v1.4.7

搜索帮助