25
25
"value_updated_timestamp" : "Int64" ,
26
26
}
27
27
28
+
28
29
@dataclass
29
30
class CovidcastRow :
30
31
"""A container for the values of a single covidcast database row.
@@ -35,7 +36,8 @@ class CovidcastRow:
35
36
- converting from and to formats (dict, csv, df, kwargs)
36
37
- creating consistent views, with consistent data types (dict, csv, df)
37
38
38
- The rows are specified in 'v4_schema.sql'. The datatypes are made to match database. When writing to Pandas, the dtypes match the JIT model.py schema.
39
+ The rows are specified in 'v4_schema.sql'. The datatypes are made to match
40
+ database. When writing to Pandas, the dtypes match the JIT model.py schema.
39
41
"""
40
42
41
43
# Arguments.
@@ -54,15 +56,20 @@ class CovidcastRow:
54
56
missing_sample_size : int
55
57
issue : int
56
58
lag : int
57
- # The following three fields are only the database, but are not ingested at acquisition and not returned by the API.
59
+ # The following three fields are only in the database, but are not ingested at
60
+ # acquisition and not returned by the API.
58
61
epimetric_id : Optional [int ] = None
59
62
direction : Optional [int ] = None
60
63
value_updated_timestamp : Optional [int ] = 0
61
64
62
65
# Classvars.
63
66
_db_row_ignore_fields : ClassVar = []
64
67
_api_row_ignore_fields : ClassVar = ["epimetric_id" , "value_updated_timestamp" ]
65
- _api_row_compatibility_ignore_fields : ClassVar = _api_row_ignore_fields + ["source" , "time_type" , "geo_type" ]
68
+ _api_row_compatibility_ignore_fields : ClassVar = _api_row_ignore_fields + [
69
+ "source" ,
70
+ "time_type" ,
71
+ "geo_type" ,
72
+ ]
66
73
67
74
_pandas_dtypes : ClassVar = PANDAS_DTYPES
68
75
@@ -72,17 +79,22 @@ def as_dict(self, ignore_fields: Optional[List[str]] = None) -> dict:
72
79
for key in ignore_fields :
73
80
del d [key ]
74
81
return d
75
-
82
+
76
83
def as_api_row_dict (self , ignore_fields : Optional [List [str ]] = None ) -> dict :
77
- """Returns a dict view into the row with the fields returned by the API server."""
84
+ """Returns a dict view into the row with the fields returned by the API
85
+ server."""
78
86
return self .as_dict (ignore_fields = self ._api_row_ignore_fields + (ignore_fields or []))
79
87
80
88
def as_api_compatibility_row_dict (self , ignore_fields : Optional [List [str ]] = None ) -> dict :
81
- """Returns a dict view into the row with the fields returned by the old API server (the PHP server)."""
82
- return self .as_dict (ignore_fields = self ._api_row_compatibility_ignore_fields + (ignore_fields or []))
89
+ """Returns a dict view into the row with the fields returned by the old
90
+ API server (the PHP server)."""
91
+ return self .as_dict (
92
+ ignore_fields = self ._api_row_compatibility_ignore_fields + (ignore_fields or [])
93
+ )
83
94
84
95
def as_db_row_dict (self , ignore_fields : Optional [List [str ]] = None ) -> dict :
85
- """Returns a dict view into the row with the fields returned by the database."""
96
+ """Returns a dict view into the row with the fields returned by the
97
+ database."""
86
98
return self .as_dict (ignore_fields = self ._db_row_ignore_fields + (ignore_fields or []))
87
99
88
100
def as_dataframe (self , ignore_fields : Optional [List [str ]] = None ) -> pd .DataFrame :
@@ -92,15 +104,22 @@ def as_dataframe(self, ignore_fields: Optional[List[str]] = None) -> pd.DataFram
92
104
return df
93
105
94
106
def as_api_row_df (self , ignore_fields : Optional [List [str ]] = None ) -> pd .DataFrame :
95
- """Returns a dataframe view into the row with the fields returned by the API server."""
107
+ """Returns a dataframe view into the row with the fields returned by the
108
+ API server."""
96
109
return self .as_dataframe (ignore_fields = self ._api_row_ignore_fields + (ignore_fields or []))
97
110
111
+ # fmt: off
98
112
def as_api_compatibility_row_df (self , ignore_fields : Optional [List [str ]] = None ) -> pd .DataFrame :
99
- """Returns a dataframe view into the row with the fields returned by the old API server (the PHP server)."""
100
- return self .as_dataframe (ignore_fields = self ._api_row_compatibility_ignore_fields + (ignore_fields or []))
113
+ """Returns a dataframe view into the row with the fields returned by the
114
+ old API server (the PHP server)."""
115
+ # fmt: on
116
+ return self .as_dataframe (
117
+ ignore_fields = self ._api_row_compatibility_ignore_fields + (ignore_fields or [])
118
+ )
101
119
102
120
def as_db_row_df (self , ignore_fields : Optional [List [str ]] = None ) -> pd .DataFrame :
103
- """Returns a dataframe view into the row with the fields returned by an all-field database query."""
121
+ """Returns a dataframe view into the row with the fields returned by an
122
+ all-field database query."""
104
123
return self .as_dataframe (ignore_fields = self ._db_row_ignore_fields + (ignore_fields or []))
105
124
106
125
def signal_pair (self ):
@@ -113,7 +132,6 @@ def time_pair(self):
113
132
return f"{ self .time_type } :{ self .time_value } "
114
133
115
134
116
-
117
135
def check_valid_dtype (dtype ):
118
136
try :
119
137
pd .api .types .pandas_dtype (dtype )
0 commit comments