Example #1
0
        public void TestFill()
        {
            // arrange
            var sparkContext = new SparkContext("", "");

            // test fill with double value
            mockDataFrameNaFunctionsProxy.Setup(m => m.Fill(It.IsAny <double>(), It.IsAny <string[]>())).Returns(mockDataFrameProxy.Object);
            var dataFrame = new DataFrame(mockDataFrameProxy.Object, sparkContext);
            var f         = new DataFrameNaFunctions(mockDataFrameNaFunctionsProxy.Object, dataFrame, sparkContext);

            var          cols        = new[] { "col1", "col2" };
            const double doubleValue = 0.001;
            var          df          = f.Fill(doubleValue, cols);

            // verify
            Assert.IsNotNull(df);
            Assert.AreEqual(df.DataFrameProxy, dataFrame.DataFrameProxy);
            Assert.AreNotSame(dataFrame, df);
            mockDataFrameNaFunctionsProxy.Verify(m => m.Fill(doubleValue, cols), Times.Once);

            // test fill with string value
            mockDataFrameNaFunctionsProxy.Reset();
            mockDataFrameNaFunctionsProxy.Setup(m => m.Fill(It.IsAny <string>(), It.IsAny <string[]>())).Returns(mockDataFrameProxy.Object);
            dataFrame = new DataFrame(mockDataFrameProxy.Object, sparkContext);
            f         = new DataFrameNaFunctions(mockDataFrameNaFunctionsProxy.Object, dataFrame, sparkContext);
            const string strValue = "UNKNOWN";

            df = f.Fill(strValue, cols);

            Assert.IsNotNull(df);
            Assert.AreEqual(df.DataFrameProxy, dataFrame.DataFrameProxy);
            Assert.AreNotSame(dataFrame, df);
            mockDataFrameNaFunctionsProxy.Verify(m => m.Fill(strValue, cols), Times.Once);

            // test fill with dictonary
            mockDataFrameNaFunctionsProxy.Reset();
            mockDataFrameNaFunctionsProxy.Setup(m => m.Fill(It.IsAny <Dictionary <string, object> >())).Returns(mockDataFrameProxy.Object);
            dataFrame = new DataFrame(mockDataFrameProxy.Object, sparkContext);
            f         = new DataFrameNaFunctions(mockDataFrameNaFunctionsProxy.Object, dataFrame, sparkContext);
            var valueDict = new Dictionary <string, object>()
            {
                { "col1", -1 },
                { "col2", "UNKNOWN" }
            };

            df = f.Fill(valueDict);

            // verify
            Assert.IsNotNull(df);
            Assert.AreEqual(df.DataFrameProxy, dataFrame.DataFrameProxy);
            Assert.AreNotSame(dataFrame, df);
            mockDataFrameNaFunctionsProxy.Verify(m => m.Fill(valueDict), Times.Once);
        }
        public void TestFill()
        {
            // arrange
            var sparkContext = new SparkContext("", "");

            // test fill with double value
            mockDataFrameNaFunctionsProxy.Setup(m => m.Fill(It.IsAny<double>(), It.IsAny<string[]>())).Returns(mockDataFrameProxy.Object);
            var dataFrame = new DataFrame(mockDataFrameProxy.Object, sparkContext);
            var f = new DataFrameNaFunctions(mockDataFrameNaFunctionsProxy.Object, dataFrame, sparkContext);

            var cols = new[] { "col1", "col2" };
            const double doubleValue = 0.001;
            var df = f.Fill(doubleValue, cols);

            // verify
            Assert.IsNotNull(df);
            Assert.AreEqual(df.DataFrameProxy, dataFrame.DataFrameProxy);
            Assert.AreNotSame(dataFrame, df);
            mockDataFrameNaFunctionsProxy.Verify(m => m.Fill(doubleValue, cols), Times.Once);

            // test fill with string value
            mockDataFrameNaFunctionsProxy.Reset();
            mockDataFrameNaFunctionsProxy.Setup(m => m.Fill(It.IsAny<string>(), It.IsAny<string[]>())).Returns(mockDataFrameProxy.Object);
            dataFrame = new DataFrame(mockDataFrameProxy.Object, sparkContext);
            f = new DataFrameNaFunctions(mockDataFrameNaFunctionsProxy.Object, dataFrame, sparkContext);
            const string strValue = "UNKNOWN";
            df = f.Fill(strValue, cols);

            Assert.IsNotNull(df);
            Assert.AreEqual(df.DataFrameProxy, dataFrame.DataFrameProxy);
            Assert.AreNotSame(dataFrame, df);
            mockDataFrameNaFunctionsProxy.Verify(m => m.Fill(strValue, cols), Times.Once);

            // test fill with dictonary
            mockDataFrameNaFunctionsProxy.Reset();
            mockDataFrameNaFunctionsProxy.Setup(m => m.Fill(It.IsAny<Dictionary<string,object>>())).Returns(mockDataFrameProxy.Object);
            dataFrame = new DataFrame(mockDataFrameProxy.Object, sparkContext);
            f = new DataFrameNaFunctions(mockDataFrameNaFunctionsProxy.Object, dataFrame, sparkContext);
            var valueDict = new Dictionary<string, object>()
            {
                {"col1", -1},
                {"col2", "UNKNOWN"}
            };
            df = f.Fill(valueDict);

            // verify
            Assert.IsNotNull(df);
            Assert.AreEqual(df.DataFrameProxy, dataFrame.DataFrameProxy);
            Assert.AreNotSame(dataFrame, df);
            mockDataFrameNaFunctionsProxy.Verify(m => m.Fill(valueDict), Times.Once);
        }
        public void TestDataFrameNaFunctionSignatures()
        {
            DataFrameNaFunctions dfNaFuncs = _df.Na();

            var emptyColumn = new string[] { };
            var validColumn = new string[] { "age" };

            DataFrame df = dfNaFuncs.Drop("any");

            df = dfNaFuncs.Drop("all");
            df = dfNaFuncs.Drop(emptyColumn);
            df = dfNaFuncs.Drop(validColumn);
            df = dfNaFuncs.Drop("any", emptyColumn);
            df = dfNaFuncs.Drop("all", validColumn);
            df = dfNaFuncs.Drop(20);
            df = dfNaFuncs.Drop(20, emptyColumn);
            df = dfNaFuncs.Drop(20, validColumn);

            df = dfNaFuncs.Fill(100L);
            df = dfNaFuncs.Fill(100.0);
            df = dfNaFuncs.Fill("hello");
            df = dfNaFuncs.Fill(false);
            df = dfNaFuncs.Fill(100L, emptyColumn);
            df = dfNaFuncs.Fill(100L, validColumn);
            df = dfNaFuncs.Fill(100.0, emptyColumn);
            df = dfNaFuncs.Fill(100.0, validColumn);
            df = dfNaFuncs.Fill("hello", emptyColumn);
            df = dfNaFuncs.Fill("hello", validColumn);
            df = dfNaFuncs.Fill(true, emptyColumn);
            df = dfNaFuncs.Fill(true, validColumn);
            df = dfNaFuncs.Fill(new Dictionary <string, int>()
            {
                { "age", 10 }
            });
            df = dfNaFuncs.Fill(new Dictionary <string, long>()
            {
                { "age", 10L }
            });
            df = dfNaFuncs.Fill(new Dictionary <string, double>()
            {
                { "age", 10.0 }
            });
            df = dfNaFuncs.Fill(new Dictionary <string, string>()
            {
                { "age", "name" }
            });
            df = dfNaFuncs.Fill(new Dictionary <string, bool>()
            {
                { "age", false }
            });

            var doubleReplacement = new Dictionary <double, double>()
            {
                { 1.0, 5.0 }
            };
            var boolReplacement = new Dictionary <bool, bool>()
            {
                { true, false }
            };
            var stringReplacement = new Dictionary <string, string>()
            {
                { "a", "b" }
            };

            df = dfNaFuncs.Replace("age", doubleReplacement);
            df = dfNaFuncs.Replace("age", boolReplacement);
            df = dfNaFuncs.Replace("age", stringReplacement);
            df = dfNaFuncs.Replace(emptyColumn, doubleReplacement);
            df = dfNaFuncs.Replace(validColumn, doubleReplacement);
            df = dfNaFuncs.Replace(emptyColumn, boolReplacement);
            df = dfNaFuncs.Replace(validColumn, boolReplacement);
            df = dfNaFuncs.Replace(emptyColumn, stringReplacement);
            df = dfNaFuncs.Replace(validColumn, stringReplacement);
        }