Declaring simple metric in python script (for local use only)


I was testing out some python code (that I had worked on in a notebook) and provisioned it to remixed ItemFacilityInventoryParams type as a function in the .py file. It provisions just fine, but gets upset when I actually try to use it in the console. The python code has a SimpleMetric and TSDecl object which is only used locally in the function. I understand this is probably not best practice (i.e. should declare simple metric within the python script, should probably be declared with the other metrics)–but in general, is it not possible to do this (to declare a simple metric in a python function and use it within that function)?

I’m mainly interested in doing this because it helps with initial prototyping (I don’t have to change it in 10 places for the initial test).

Error in console:
Error executing command ~py-pipeline2/bin/python/tmp/ Traceback (most recent call last): File “tmp/” line #### in <module> _c3_result=mycoolthing_test(sku_ids = c3_inputs.get(‘sku_ids’),starttime=_c3_inputs.get(‘starttime’),endtime=c3_inputs.get(‘endtime’)) File “tmp/” line ####, in mycoolthing_test value=”latestQuantity.value” TypeError: ‘C3Type’ object is not callable

In ItemFacilityInventoryParams.c3typ:
mycoolthing_test: function(sku_ids: ![string], starttime: !string, endtime: !string): [double]

def mycoolthing_test(sku_ids,starttime,endtime):
import pandas as pd
import numpy as np

    #tried with and without these
#from helper_functions import from_dataset, get_c3, from_dataset
#c3 = get_c3(url="", tenant="tenant", tag="tag")

tsDeclObject3 = c3.TSDecl(
     data= "itemPurchaseOrderHistories",
     treatment= "SUM",
     overlapHandling= "MAX",
     start= "promisedReceivedDate.value",
     value= "latestQuantity.value"

purchase_orders_perID = c3.SimpleMetric(
    id = "purchase_orders_perID_ItemFacility",
    name = "purchase_orders_perID",
    srcType = "ItemFacilityInventoryParams",
    tsDecl = tsDeclObject3

    #put dummy output here, for testing
return means

Call made to console:
var res2 = ItemFacilityInventoryParams.mycoolthing_test(["",""],“2018-01-01”,“2019-01-01”)




This is due to a difference in the way the c3 object is instantiated depending on the “connector” used in your runtime environment, c3ShowFunk(ActionRuntime,"connector"). Currently, the default is “C3FastConnection” which uses pyc3. The connector being used in Jupyter is either “remote” or “remote-types” and is the recommended way for interacting with c3 . The py-pipeline2 runtime does not specify a connector and therefore uses the C3FastConnection. You will need to define a new runtime in your package.json and specify the “connector” as “remote” or “remote-types”.