Пример #1
0
        /// <summary>
        /// Registers custom encoders and decoders with the Python.NET runtime
        /// </summary>
        private static void InitializeEncoders()
        {
            var shared   = new object[] { new BigIntegerEncoderDecoder(), new ListEncoderDecoder() };
            var encoders = shared.Cast <IPyObjectEncoder>().ToArray();
            var decoders = shared.Cast <IPyObjectDecoder>().Concat(new IPyObjectDecoder[]
            {
                new DictionaryDecoder()
            }).ToArray();

            Array.ForEach(encoders, e => PyObjectConversions.RegisterEncoder(e));
            Array.ForEach(decoders, d => PyObjectConversions.RegisterDecoder(d));
        }
Пример #2
0
        private void Setup(bool force = false)
        {
            if (_isInitialized && !force) return;
            _isInitialized = true;

            DateTimeCodec.Initialize(this);
            NumpyCodec.Initialize(this);
            PandasCodec.Initialize(this);

            PyObjectConversions.RegisterEncoder(this);
            PyObjectConversions.RegisterDecoder(this);
        }
Пример #3
0
        public void ExceptionEncoded()
        {
            PyObjectConversions.RegisterEncoder(new ValueErrorCodec());
            void CallMe() => throw new ValueErrorWrapper(TestExceptionMessage);

            var callMeAction = new Action(CallMe);

            using var scope = Py.CreateScope();
            scope.Exec(@"
def call(func):
  try:
    func()
  except ValueError as e:
    return str(e)
");
            var    callFunc = scope.Get("call");
            string message  = callFunc.Invoke(callMeAction.ToPython()).As <string>();

            Assert.AreEqual(TestExceptionMessage, message);
        }
Пример #4
0
 public static void Register()
 {
     PyObjectConversions.RegisterEncoder(Instance);
     PyObjectConversions.RegisterDecoder(Instance);
 }