MCPcopy Create free account
hub / github.com/javascriptdata/danfojs / and

Method and

src/danfojs-base/core/series.ts:2012–2051  ·  view source on GitHub ↗

* Returns the logical AND between Series and other. Supports element wise operations and broadcasting. * @param other Series, Scalar, Array of Scalars * @example * ``` * const sf = new Series([true, true, false, false, true]); * const sf2 = new Series([true, false, true, fa

(other: any)

Source from the content-addressed store, hash-verified

2010 * ```
2011 */
2012 and(other: any): Series {
2013
2014 if (other === undefined) {
2015 throw new Error("Param Error: other cannot be undefined");
2016 }
2017 const newValues: ArrayType1D = [];
2018
2019 if (other instanceof Series) {
2020 if (this.dtypes[0] !== other.dtypes[0]) {
2021 throw new Error("Param Error: Series must be of same dtype");
2022 }
2023
2024 if (this.shape[0] !== other.shape[0]) {
2025 throw new Error("Param Error: Series must be of same shape");
2026 }
2027
2028 this.values.forEach((val, i) => {
2029 newValues.push(Boolean(val) && Boolean(other.values[i]));
2030 });
2031
2032 } else if (typeof other === "boolean") {
2033
2034 this.values.forEach((val) => {
2035 newValues.push(Boolean(val) && Boolean(other));
2036 });
2037
2038 } else if (Array.isArray(other)) {
2039
2040 this.values.forEach((val, i) => {
2041 newValues.push(Boolean(val) && Boolean(other[i]));
2042 });
2043
2044 } else {
2045 throw new Error("Param Error: other must be a Series, Scalar, or Array of Scalars");
2046 }
2047 return new Series(newValues, {
2048 index: this.index,
2049 config: { ...this.config }
2050 });
2051 }
2052
2053 /**
2054 * Returns the logical OR between Series and other. Supports element wise operations and broadcasting.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected