17
17
def spec_unit_conversion (df , src_spec , dest_spec ):
18
18
"""This method must be able to evaluate multiple sources should
19
19
a channel be composed from multiple sources."""
20
- if src_spec == dest_spec :
21
- logger .info ("spec_unit_conversion: src_spec is equal to dest_spec." )
22
- return df
23
-
24
20
for k , v in src_spec .full .spec .items ():
25
21
if k in df .columns :
26
22
src_unit = v ["unit" ]
@@ -60,11 +56,38 @@ def spec_unit_conversion(df, src_spec, dest_spec):
60
56
return df
61
57
62
58
63
- def get_dtype_mapper (df_cols , dest_spec ):
59
+ def get_dtype_mapper (df_cols , dest_spec , src_nullable = False , dest_nullable = False ):
64
60
# we only need to consider the destination spec
65
61
dtype_mapper = {
66
62
k : v ["dtype" ] for k , v in dest_spec .full .spec .items () if k in df_cols
67
63
}
64
+
65
+ # convert between nullable columns and non-nullable for compatability
66
+ if dest_nullable :
67
+ for k ,v in dtype_mapper .items ():
68
+ if v == "bool" :
69
+ dtype_mapper [k ] = "boolean"
70
+ elif v == "int8" :
71
+ dtype_mapper [k ] = "Int8"
72
+ elif v == "int16" :
73
+ dtype_mapper [k ] = "Int16"
74
+ elif v == "int32" :
75
+ dtype_mapper [k ] = "Int32"
76
+ elif v == "int64" :
77
+ dtype_mapper [k ] = "Int64"
78
+ else :
79
+ for k ,v in dtype_mapper .items ():
80
+ if v == "boolean" :
81
+ dtype_mapper [k ] = "bool"
82
+ elif v == "Int8" :
83
+ dtype_mapper [k ] = "int8"
84
+ elif v == "Int16" :
85
+ dtype_mapper [k ] = "int16"
86
+ elif v == "Int32" :
87
+ dtype_mapper [k ] = "int32"
88
+ elif v == "Int64" :
89
+ dtype_mapper [k ] = "int64"
90
+
68
91
return dtype_mapper
69
92
70
93
@@ -120,7 +143,9 @@ def project_spec_keys(src_spec, dest_spec):
120
143
return projection
121
144
122
145
123
- def convert_spec (df , src_spec , dest_spec , copy = False ):
146
+ def convert_spec (df , src_spec , dest_spec , src_nullable = False , dest_nullable = False , copy = False ):
147
+ # src_nullable: whether to use nullable int types
148
+ # dest_nullable: whether to use nullable int types
124
149
if type (src_spec ) == type (dest_spec ):
125
150
logger .info ("convert_spec: src_spec is equal to dest_spec." )
126
151
return df
@@ -148,7 +173,7 @@ def convert_spec(df, src_spec, dest_spec, copy=False):
148
173
_df = _df .rename (columns = get_rename_mapper (src_spec = src_spec , dest_spec = dest_spec ))
149
174
150
175
_df = _df .astype (
151
- dtype = get_dtype_mapper (df_cols = _df .columns , dest_spec = dest_spec ),
176
+ dtype = get_dtype_mapper (df_cols = _df .columns , dest_spec = dest_spec , src_nullable = src_nullable , dest_nullable = dest_nullable ),
152
177
)
153
178
_df = _df .sort_values (dest_spec .datetime_column , ascending = True )
154
179
return _df
@@ -174,6 +199,10 @@ def dtypes_are_pandas(self, attribute, value):
174
199
"Int16" ,
175
200
"Int32" ,
176
201
"Int64" ,
202
+ "int8" ,
203
+ "int16" ,
204
+ "int32" ,
205
+ "int64" ,
177
206
"UInt8" ,
178
207
"UInt16" ,
179
208
"UInt32" ,
@@ -294,91 +323,91 @@ def __init__(self):
294
323
spec = {
295
324
STATES .AUXHEAT1 : {
296
325
"name" : "auxHeat1" ,
297
- "dtype" : "Int16 " ,
326
+ "dtype" : "int16 " ,
298
327
"channel" : CHANNELS .EQUIPMENT ,
299
328
"unit" : UNITS .SECONDS ,
300
329
},
301
330
STATES .AUXHEAT2 : {
302
331
"name" : "auxHeat2" ,
303
- "dtype" : "Int16 " ,
332
+ "dtype" : "int16 " ,
304
333
"channel" : CHANNELS .EQUIPMENT ,
305
334
"unit" : UNITS .SECONDS ,
306
335
},
307
336
STATES .AUXHEAT3 : {
308
337
"name" : "auxHeat3" ,
309
- "dtype" : "Int16 " ,
338
+ "dtype" : "int16 " ,
310
339
"channel" : CHANNELS .EQUIPMENT ,
311
340
"unit" : UNITS .SECONDS ,
312
341
},
313
342
STATES .COMPCOOL1 : {
314
343
"name" : "compCool1" ,
315
- "dtype" : "Int16 " ,
344
+ "dtype" : "int16 " ,
316
345
"channel" : CHANNELS .EQUIPMENT ,
317
346
"unit" : UNITS .SECONDS ,
318
347
},
319
348
STATES .COMPCOOL2 : {
320
349
"name" : "compCool2" ,
321
- "dtype" : "Int16 " ,
350
+ "dtype" : "int16 " ,
322
351
"channel" : CHANNELS .EQUIPMENT ,
323
352
"unit" : UNITS .SECONDS ,
324
353
},
325
354
STATES .COMPHEAT1 : {
326
355
"name" : "compHeat1" ,
327
- "dtype" : "Int16 " ,
356
+ "dtype" : "int16 " ,
328
357
"channel" : CHANNELS .EQUIPMENT ,
329
358
"unit" : UNITS .SECONDS ,
330
359
},
331
360
STATES .COMPHEAT2 : {
332
361
"name" : "compHeat2" ,
333
- "dtype" : "Int16 " ,
362
+ "dtype" : "int16 " ,
334
363
"channel" : CHANNELS .EQUIPMENT ,
335
364
"unit" : UNITS .SECONDS ,
336
365
},
337
366
STATES .DEHUMIDIFIER : {
338
367
"name" : "dehumidifier" ,
339
- "dtype" : "Int16 " ,
368
+ "dtype" : "int16 " ,
340
369
"channel" : CHANNELS .EQUIPMENT ,
341
370
"unit" : UNITS .SECONDS ,
342
371
},
343
372
STATES .ECONOMIZER : {
344
373
"name" : "economizer" ,
345
- "dtype" : "Int16 " ,
374
+ "dtype" : "int16 " ,
346
375
"channel" : CHANNELS .EQUIPMENT ,
347
376
"unit" : UNITS .SECONDS ,
348
377
},
349
378
STATES .FAN : {
350
379
"name" : "fan" ,
351
- "dtype" : "Int16 " ,
380
+ "dtype" : "int16 " ,
352
381
"channel" : CHANNELS .EQUIPMENT ,
353
382
"unit" : UNITS .SECONDS ,
354
383
},
355
384
STATES .FAN_STAGE_ONE : {
356
385
"name" : "fan1" ,
357
- "dtype" : "Int16 " ,
386
+ "dtype" : "int16 " ,
358
387
"channel" : CHANNELS .EQUIPMENT ,
359
388
"unit" : UNITS .SECONDS ,
360
389
},
361
390
STATES .FAN_STAGE_TWO : {
362
391
"name" : "fan2" ,
363
- "dtype" : "Int16 " ,
392
+ "dtype" : "int16 " ,
364
393
"channel" : CHANNELS .EQUIPMENT ,
365
394
"unit" : UNITS .SECONDS ,
366
395
},
367
396
STATES .FAN_STAGE_THREE : {
368
397
"name" : "fan3" ,
369
- "dtype" : "Int16 " ,
398
+ "dtype" : "int16 " ,
370
399
"channel" : CHANNELS .EQUIPMENT ,
371
400
"unit" : UNITS .SECONDS ,
372
401
},
373
402
STATES .HUMIDIFIER : {
374
403
"name" : "humidifier" ,
375
- "dtype" : "Int16 " ,
404
+ "dtype" : "int16 " ,
376
405
"channel" : CHANNELS .EQUIPMENT ,
377
406
"unit" : UNITS .SECONDS ,
378
407
},
379
408
STATES .VENTILATOR : {
380
409
"name" : "ventilator" ,
381
- "dtype" : "Int16 " ,
410
+ "dtype" : "int16 " ,
382
411
"channel" : CHANNELS .EQUIPMENT ,
383
412
"unit" : UNITS .SECONDS ,
384
413
},
@@ -616,73 +645,73 @@ def __init__(self):
616
645
spec = {
617
646
"auxHeat1" : {
618
647
"internal_state" : STATES .AUXHEAT1 ,
619
- "dtype" : "Int16 " ,
648
+ "dtype" : "int16 " ,
620
649
"channel" : CHANNELS .EQUIPMENT ,
621
650
"unit" : UNITS .SECONDS ,
622
651
},
623
652
"auxHeat2" : {
624
653
"internal_state" : STATES .AUXHEAT2 ,
625
- "dtype" : "Int16 " ,
654
+ "dtype" : "int16 " ,
626
655
"channel" : CHANNELS .EQUIPMENT ,
627
656
"unit" : UNITS .SECONDS ,
628
657
},
629
658
"auxHeat3" : {
630
659
"internal_state" : STATES .AUXHEAT3 ,
631
- "dtype" : "Int16 " ,
660
+ "dtype" : "int16 " ,
632
661
"channel" : CHANNELS .EQUIPMENT ,
633
662
"unit" : UNITS .SECONDS ,
634
663
},
635
664
"compCool1" : {
636
665
"internal_state" : STATES .COMPCOOL1 ,
637
- "dtype" : "Int16 " ,
666
+ "dtype" : "int16 " ,
638
667
"channel" : CHANNELS .EQUIPMENT ,
639
668
"unit" : UNITS .SECONDS ,
640
669
},
641
670
"compCool2" : {
642
671
"internal_state" : STATES .COMPCOOL2 ,
643
- "dtype" : "Int16 " ,
672
+ "dtype" : "int16 " ,
644
673
"channel" : CHANNELS .EQUIPMENT ,
645
674
"unit" : UNITS .SECONDS ,
646
675
},
647
676
"compHeat1" : {
648
677
"internal_state" : STATES .COMPHEAT1 ,
649
- "dtype" : "Int16 " ,
678
+ "dtype" : "int16 " ,
650
679
"channel" : CHANNELS .EQUIPMENT ,
651
680
"unit" : UNITS .SECONDS ,
652
681
},
653
682
"compHeat2" : {
654
683
"internal_state" : STATES .COMPHEAT2 ,
655
- "dtype" : "Int16 " ,
684
+ "dtype" : "int16 " ,
656
685
"channel" : CHANNELS .EQUIPMENT ,
657
686
"unit" : UNITS .SECONDS ,
658
687
},
659
688
"dehumidifier" : {
660
689
"internal_state" : STATES .DEHUMIDIFIER ,
661
- "dtype" : "Int16 " ,
690
+ "dtype" : "int16 " ,
662
691
"channel" : CHANNELS .EQUIPMENT ,
663
692
"unit" : UNITS .SECONDS ,
664
693
},
665
694
"economizer" : {
666
695
"internal_state" : STATES .ECONOMIZER ,
667
- "dtype" : "Int16 " ,
696
+ "dtype" : "int16 " ,
668
697
"channel" : CHANNELS .EQUIPMENT ,
669
698
"unit" : UNITS .SECONDS ,
670
699
},
671
700
"fan" : {
672
701
"internal_state" : STATES .FAN ,
673
- "dtype" : "Int16 " ,
702
+ "dtype" : "int16 " ,
674
703
"channel" : CHANNELS .EQUIPMENT ,
675
704
"unit" : UNITS .SECONDS ,
676
705
},
677
706
"humidifier" : {
678
707
"internal_state" : STATES .HUMIDIFIER ,
679
- "dtype" : "Int16 " ,
708
+ "dtype" : "int16 " ,
680
709
"channel" : CHANNELS .EQUIPMENT ,
681
710
"unit" : UNITS .SECONDS ,
682
711
},
683
712
"ventilator" : {
684
713
"internal_state" : STATES .VENTILATOR ,
685
- "dtype" : "Int16 " ,
714
+ "dtype" : "int16 " ,
686
715
"channel" : CHANNELS .EQUIPMENT ,
687
716
"unit" : UNITS .SECONDS ,
688
717
},
@@ -860,49 +889,49 @@ def __init__(self):
860
889
spec = {
861
890
"auxHeat1" : {
862
891
"internal_state" : STATES .AUXHEAT1 ,
863
- "dtype" : "Int16 " ,
892
+ "dtype" : "int16 " ,
864
893
"channel" : CHANNELS .EQUIPMENT ,
865
894
"unit" : UNITS .SECONDS ,
866
895
},
867
896
"auxHeat2" : {
868
897
"internal_state" : STATES .AUXHEAT2 ,
869
- "dtype" : "Int16 " ,
898
+ "dtype" : "int16 " ,
870
899
"channel" : CHANNELS .EQUIPMENT ,
871
900
"unit" : UNITS .SECONDS ,
872
901
},
873
902
"auxHeat3" : {
874
903
"internal_state" : STATES .AUXHEAT3 ,
875
- "dtype" : "Int16 " ,
904
+ "dtype" : "int16 " ,
876
905
"channel" : CHANNELS .EQUIPMENT ,
877
906
"unit" : UNITS .SECONDS ,
878
907
},
879
908
"compCool1" : {
880
909
"internal_state" : STATES .COMPCOOL1 ,
881
- "dtype" : "Int16 " ,
910
+ "dtype" : "int16 " ,
882
911
"channel" : CHANNELS .EQUIPMENT ,
883
912
"unit" : UNITS .SECONDS ,
884
913
},
885
914
"compCool2" : {
886
915
"internal_state" : STATES .COMPCOOL2 ,
887
- "dtype" : "Int16 " ,
916
+ "dtype" : "int16 " ,
888
917
"channel" : CHANNELS .EQUIPMENT ,
889
918
"unit" : UNITS .SECONDS ,
890
919
},
891
920
"compHeat1" : {
892
921
"internal_state" : STATES .COMPHEAT1 ,
893
- "dtype" : "Int16 " ,
922
+ "dtype" : "int16 " ,
894
923
"channel" : CHANNELS .EQUIPMENT ,
895
924
"unit" : UNITS .SECONDS ,
896
925
},
897
926
"compHeat2" : {
898
927
"internal_state" : STATES .COMPHEAT2 ,
899
- "dtype" : "Int16 " ,
928
+ "dtype" : "int16 " ,
900
929
"channel" : CHANNELS .EQUIPMENT ,
901
930
"unit" : UNITS .SECONDS ,
902
931
},
903
932
"fan" : {
904
933
"internal_state" : STATES .FAN ,
905
- "dtype" : "Int16 " ,
934
+ "dtype" : "int16 " ,
906
935
"channel" : CHANNELS .EQUIPMENT ,
907
936
"unit" : UNITS .SECONDS ,
908
937
},
0 commit comments