Esempio n. 1
0
        public void TestBinaryOperationsWithConversions()
        {
            DataFrame df = DataFrameTests.MakeDataFrameWithTwoColumns(10);

            // Add a double to an int column
            DataFrame dfd   = df.Add(5.0f);
            var       dtype = dfd.Column(0).DataType;

            Assert.True(dtype == typeof(double));

            // Add a decimal to an int column
            DataFrame dfm = df.Add(5.0m);

            dtype = dfm.Column(0).DataType;
            Assert.True(dtype == typeof(decimal));

            // int + bool should throw
            Assert.Throws <NotSupportedException>(() => df.Add(true));

            var dataFrameColumn1 = new PrimitiveColumn <double>("Double1", Enumerable.Range(0, 10).Select(x => (double)x));

            df.SetColumn(0, dataFrameColumn1);
            // Double + comparison ops should throw
            Assert.Throws <NotSupportedException>(() => df.And(true));
        }
Esempio n. 2
0
        public void TestProjectionAndAppend()
        {
            DataFrame df = DataFrameTests.MakeDataFrameWithTwoColumns(10);

            df["Int3"] = df["Int1"] * 2 + df["Int2"];
            Assert.Equal(16, df["Int3"][2]);
        }
Esempio n. 3
0
        public void TestBinaryOperations()
        {
            DataFrame df = DataFrameTests.MakeTestTableWithTwoColumns(10);

            // Binary ops always return a copy
            Assert.Equal(5, df.Add(5)[0, 0]);
            IReadOnlyList <int> listOfInts = new List <int>()
            {
                5, 5
            };

            Assert.Equal(5, df.Add(listOfInts)[0, 0]);
            Assert.Equal(-5, df.Subtract(5)[0, 0]);
            Assert.Equal(-5, df.Subtract(listOfInts)[0, 0]);
            Assert.Equal(5, df.Multiply(5)[1, 0]);
            Assert.Equal(5, df.Multiply(listOfInts)[1, 0]);
            Assert.Equal(1, df.Divide(5)[5, 0]);
            Assert.Equal(1, df.Divide(listOfInts)[5, 0]);
            Assert.Equal(0, df.Modulo(5)[5, 0]);
            Assert.Equal(0, df.Modulo(listOfInts)[5, 0]);
            Assert.Equal(5, df.And(5)[5, 0]);
            Assert.Equal(5, df.And(listOfInts)[5, 0]);
            Assert.Equal(5, df.Or(5)[5, 0]);
            Assert.Equal(5, df.Or(listOfInts)[5, 0]);
            Assert.Equal(0, df.Xor(5)[5, 0]);
            Assert.Equal(0, df.Xor(listOfInts)[5, 0]);
            Assert.Equal(2, df.LeftShift <int>(1)[1, 0]);
            Assert.Equal(1, df.RightShift <int>(1)[2, 0]);
            Assert.Equal(true, df.Equals(5)[5, 0]);
            Assert.Equal(true, df.Equals(listOfInts)[5, 0]);
            Assert.Equal(true, df.NotEquals(5)[4, 0]);
            Assert.Equal(true, df.NotEquals(listOfInts)[4, 0]);
            Assert.Equal(true, df.GreaterThanOrEqual(5)[6, 0]);
            Assert.Equal(true, df.GreaterThanOrEqual(listOfInts)[6, 0]);
            Assert.Equal(true, df.LessThanOrEqual(5)[4, 0]);
            Assert.Equal(true, df.LessThanOrEqual(listOfInts)[4, 0]);
            Assert.Equal(false, df.GreaterThan(5)[5, 0]);
            Assert.Equal(false, df.GreaterThan(listOfInts)[5, 0]);
            Assert.Equal(false, df.LessThan(5)[5, 0]);
            Assert.Equal(false, df.LessThan(listOfInts)[5, 0]);

            // The original DF is untouched
            Assert.Equal(0, df[0, 0]);
        }