Ejemplo n.º 1
0
        public void Sort_Index_Desc_Test()
        {
            IDataFrame df = _dataFrame;

            List <int> indexs = new List <int>();
            int        r      = new Random().Next(0, df.Columns.Size / 2);

            if (r == 0)
            {
                r = df.Columns.Size;
            }
            for (int i = 0; i < df.Columns.Size; i += r)
            {
                indexs.Add(i);
            }
            var result = df.sort_values(indexs.ToArray(), false);

            int index = indexs[0];
            var col   = result[index];

            for (int i = 0; i < result.Index.Size - 1; i++)
            {
                Assert.True(Convert.ToDecimal(col[i]) >= Convert.ToDecimal(col[i + 1]));
            }
        }
Ejemplo n.º 2
0
        public void Sort_Test()
        {
            IDataFrame df      = _dataFrame;
            int        sortNum = 2;

            #region test
            //int[] arr1 = { 5, 3, 1, 4, 1 };
            //int[] arr2 = { 6, 2, 8, 7, 9 };
            //int[] arr3 = { 9, 8, 7, 2, 1 };
            //int[] arr4 = { 1, 2, 9, 8, 7 };
            //int[] arr5 = { 2, 3, 8, 1, 9 };
            //var dict = new Dictionary<string, NDArray>
            //{
            //   { "col1",np.array(arr1,typeof(object)) },
            //   { "col2",np.array(arr2,typeof(object))},
            //   { "col3",np.array(arr3,typeof(object)) },
            //   { "col4",np.array(arr4,typeof(object)) },
            //   { "col5",np.array(arr5,typeof(object)) },
            //};

            //var pd = new Pandas();
            //var df = pd.DataFrame<string>(dict, new string[] {
            //    "row1","row2","row3","row4","row5"
            //});
            #endregion
            List <string> columns = new List <string>();
            int           r       = new Random().Next(0, df.Columns.Size / 2);
            if (r == 0)
            {
                r = df.Columns.Size;
            }
            int size = df.Columns.Size;
            for (int i = 0; i < size; i += (size / sortNum))
            {
                columns.Add(df[i].Name.ToString());
            }
            DateTime startTime = DateTime.Now;
            var      result    = df.sort_values(columns.ToArray());
            DateTime endTime   = DateTime.Now;
            var      time      = (endTime - startTime).TotalMilliseconds;
            //string sourStr = ShowDataFrameValues(df);
            //string resStr = ShowDataFrameValues(result);
            string index = columns[0];
            var    col   = result[index];

            for (int i = 0; i < result.Index.Size - 1; i++)
            {
                Assert.True(Convert.ToDecimal(col[i]) <= Convert.ToDecimal(col[i + 1]));
            }
        }
Ejemplo n.º 3
0
        public void Sort_Index_Test()
        {
            IDataFrame df = _dataFrame;

            List <int> indexs = new List <int>();
            int        r      = new Random().Next(0, df.Columns.Size / 2);

            for (int i = 0; i < df.Columns.Size; i += r)
            {
                indexs.Add(i);
            }
            //var str = ShowDataFrameValues(_dataFrame);
            var result = df.sort_values(indexs.ToArray());
            //var str2 = ShowDataFrameValues(result);
            int index = indexs[0];
            var col   = result[index];

            for (int i = 0; i < result.Index.Size - 1; i++)
            {
                Assert.True(Convert.ToDecimal(col[i]) <= Convert.ToDecimal(col[i + 1]));
            }
        }