Пример #1
0
        public static void Initialize(Codecs codecs)
        {
            // .Net -> Python
            codecs.Register <sbyte[]>(a => EncodeFast(a, Encode));
            codecs.Register <short[]>(a => EncodeFast(a, Encode));
            codecs.Register <int[]>(a => EncodeFast(a, Encode));
            codecs.Register <long[]>(a => EncodeFast(a, Encode));
            codecs.Register <bool[]>(a => EncodeFast(a, Encode));
            codecs.Register <byte[]>(a => EncodeFast(a, Encode));
            codecs.Register <ushort[]>(a => EncodeFast(a, Encode));
            codecs.Register <uint[]>(a => EncodeFast(a, Encode));
            codecs.Register <ulong[]>(a => EncodeFast(a, Encode));
            codecs.Register <float[]>(a => EncodeFast(a, Encode));
            codecs.Register <double[]>(a => EncodeFast(a, Encode));
            codecs.Register <DateTime[]>(a => EncodeFast(a, Encode));
            codecs.Register <TimeSpan[]>(a => EncodeFast(a, Encode));
            codecs.Register <string[]>(a => EncodeSafe(a));

            // Python -> .Net
            codecs.Register("<class 'numpy.ndarray'>", Decode);
            codecs.Register("<class 'numpy.bool_'>", p => p.As <bool>());
            codecs.Register("<class 'numpy.uint8'>", p => p.As <byte>());
            codecs.Register("<class 'numpy.uint16'>", p => p.As <ushort>());
            codecs.Register("<class 'numpy.uint32'>", p => p.As <uint>());
            codecs.Register("<class 'numpy.uint64'>", p => p.As <ulong>());
            codecs.Register("<class 'numpy.int8'>", p => p.As <sbyte>());
            codecs.Register("<class 'numpy.int16'>", p => p.As <short>());
            codecs.Register("<class 'numpy.int32'>", p => p.As <int>());
            codecs.Register("<class 'numpy.int64'>", p => p.As <long>());
            codecs.Register("<class 'numpy.float32'>", p => p.As <float>());
            codecs.Register("<class 'numpy.float64'>", p => p.As <double>());
        }
Пример #2
0
        public static void Initialize(Codecs codecs)
        {
            // .Net -> Python
            codecs.Register <Dictionary <string, Array> >(Encode);

            // Python -> .Net
            codecs.Register("<class 'pandas.core.frame.DataFrame'>", DecodeDataFrame);
            codecs.Register("<class 'pandas.core.series.Series'>", DecodeSeries);
            codecs.Register("<class 'pandas._libs.tslibs.timestamps.Timestamp'>", DecodeTimestamp);
            codecs.Register("<class 'pandas._libs.tslibs.timedeltas.TimeDelta'>", DateTimeCodec.DecodeTimeDelta);
        }
Пример #3
0
        public static void Initialize(Codecs codecs)
        {
            // .Net -> Python
            codecs.Register <DateTime>(EncodeDateTime);
            codecs.Register <TimeSpan>(EncodeTimeSpan);

            // Python -> .Net
            codecs.Register("<class 'datetime.date'>", DecodeDate);
            codecs.Register("<class 'datetime.datetime'>", DecodeDateTime);
            codecs.Register("<class 'datetime.time'>", DecodeTime);
            codecs.Register("<class 'datetime.timedelta'>", DecodeTimeDelta);
        }
Пример #4
0
        private static PyObject Encode(Dictionary <string, Array> data)
        {
            using (var scope = Py.CreateScope())
            {
                dynamic pandas = scope.Import("pandas");
                var     pyDict = new PyDict();
                foreach (var pair in data)
                {
                    var series = pandas.Series(Codecs.Encode(pair.Value));
                    if (pair.Value is string[])
                    {
                        series = series.astype("string");
                    }

                    pyDict.SetItem(pair.Key, series);
                }

                return(pandas.DataFrame(pyDict));
            }
        }