@@ -47,19 +47,26 @@ def __init__(self, metric, oldest_data_datetime=None):
47
47
Constructor for the Metric object
48
48
49
49
"""
50
- self .metric_name = metric ["metric" ]["__name__" ]
51
- self .label_config = deepcopy (metric ["metric" ])
52
- self .oldest_data_datetime = oldest_data_datetime
53
- del self .label_config ["__name__" ]
50
+ if isinstance (metric , Metric ):
51
+ # if metric is a Metric object, just copy the object and update its parameters
52
+ self .metric_name = metric .metric_name
53
+ self .label_config = metric .label_config
54
+ self .metric_values = metric .metric_values
55
+ self .oldest_data_datetime = oldest_data_datetime
56
+ else :
57
+ self .metric_name = metric ["metric" ]["__name__" ]
58
+ self .label_config = deepcopy (metric ["metric" ])
59
+ self .oldest_data_datetime = oldest_data_datetime
60
+ del self .label_config ["__name__" ]
54
61
55
- # if it is a single value metric change key name
56
- if "value" in metric :
57
- metric ["values" ] = [metric ["value" ]]
62
+ # if it is a single value metric change key name
63
+ if "value" in metric :
64
+ metric ["values" ] = [metric ["value" ]]
58
65
59
- self .metric_values = pandas .DataFrame (metric ["values" ], columns = ["ds" , "y" ]).apply (
60
- pandas .to_numeric , args = ({"errors" : "coerce" })
61
- )
62
- self .metric_values ["ds" ] = pandas .to_datetime (self .metric_values ["ds" ], unit = "s" )
66
+ self .metric_values = pandas .DataFrame (metric ["values" ], columns = ["ds" , "y" ]).apply (
67
+ pandas .to_numeric , args = ({"errors" : "coerce" })
68
+ )
69
+ self .metric_values ["ds" ] = pandas .to_datetime (self .metric_values ["ds" ], unit = "s" )
63
70
64
71
def __eq__ (self , other ):
65
72
"""
0 commit comments