1 Star 4 Fork 11

王布衣 / pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
vector_logic.go 2.19 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-02-24 21:43 . 适配num新版本0.1.5
package pandas
import "gitee.com/quant1x/num"
func (this vector[T]) Logic(f func(idx int, v any) bool) []bool {
d := make([]bool, this.Len())
for i, v := range this {
d[i] = f(i, v)
}
return d
}
func (this vector[T]) Eq(x any) Series {
length := this.Len()
var b []num.DType
switch sx := x.(type) {
case Series:
b = sx.DTypes()
case int:
b = num.Repeat[num.DType](num.DType(sx), length)
case num.DType:
b = num.Repeat[num.DType](sx, length)
//case int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint, uintptr, float32, float64:
// b = Repeat[DType](DType(sx), length)
case []num.DType:
b = num.Align[num.DType](sx, num.NaN(), length)
default:
panic(num.TypeError(x))
}
a := this.DTypes()
s := num.Equal(a, b)
return vector[bool](s)
}
func (this vector[T]) Neq(x any) Series {
length := this.Len()
var b []num.DType
switch sx := x.(type) {
case Series:
b = sx.DTypes()
case int:
b = num.Repeat[num.DType](num.DType(sx), length)
case num.DType:
b = num.Repeat[num.DType](sx, length)
//case int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint, uintptr, float32, float64:
// b = Repeat[DType](DType(sx), length)
case []num.DType:
b = num.Align[num.DType](sx, num.NaN(), length)
default:
panic(num.TypeError(x))
}
a := this.DTypes()
s := num.NotEqual(a, b)
return vector[bool](s)
}
func (this vector[T]) Gt(x any) Series {
values := this.Values().([]T)
bs := num.Gt(values, x)
return vector[bool](bs)
}
func (this vector[T]) Gte(x any) Series {
values := this.Values().([]T)
bs := num.Gte(values, x)
return vector[bool](bs)
}
func (this vector[T]) Lt(x any) Series {
values := this.Values().([]T)
bs := num.Lt(values, x)
return vector[bool](bs)
}
func (this vector[T]) Lte(x any) Series {
values := this.Values().([]T)
bs := num.Lte(values, x)
return vector[bool](bs)
}
func (this vector[T]) And(x any) Series {
values := this.Values().([]T)
bs := num.And(values, x)
return vector[bool](bs)
}
func (this vector[T]) Or(x any) Series {
values := this.Values().([]T)
bs := num.Or(values, x)
return vector[bool](bs)
}
func (this vector[T]) Not() Series {
values := this.Values().([]T)
bs := num.Not(values)
return vector[bool](bs)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v1.3.7

搜索帮助

344bd9b3 5694891 D2dac590 5694891