Skip to content

Commit 494865c

Browse files
committed
style(black): format covidcast_rows and logger
1 parent 794eca2 commit 494865c

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

src/common/covidcast_row.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"value_updated_timestamp": "Int64",
2626
}
2727

28+
2829
@dataclass
2930
class CovidcastRow:
3031
"""A container for the values of a single covidcast database row.
@@ -62,7 +63,11 @@ class CovidcastRow:
6263
# Classvars.
6364
_db_row_ignore_fields: ClassVar = []
6465
_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"]
66+
_api_row_compatibility_ignore_fields: ClassVar = _api_row_ignore_fields + [
67+
"source",
68+
"time_type",
69+
"geo_type",
70+
]
6671

6772
_pandas_dtypes: ClassVar = PANDAS_DTYPES
6873

@@ -72,14 +77,16 @@ def as_dict(self, ignore_fields: Optional[List[str]] = None) -> dict:
7277
for key in ignore_fields:
7378
del d[key]
7479
return d
75-
80+
7681
def as_api_row_dict(self, ignore_fields: Optional[List[str]] = None) -> dict:
7782
"""Returns a dict view into the row with the fields returned by the API server."""
7883
return self.as_dict(ignore_fields=self._api_row_ignore_fields + (ignore_fields or []))
7984

8085
def as_api_compatibility_row_dict(self, ignore_fields: Optional[List[str]] = None) -> dict:
8186
"""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 []))
87+
return self.as_dict(
88+
ignore_fields=self._api_row_compatibility_ignore_fields + (ignore_fields or [])
89+
)
8390

8491
def as_db_row_dict(self, ignore_fields: Optional[List[str]] = None) -> dict:
8592
"""Returns a dict view into the row with the fields returned by the database."""
@@ -95,9 +102,13 @@ def as_api_row_df(self, ignore_fields: Optional[List[str]] = None) -> pd.DataFra
95102
"""Returns a dataframe view into the row with the fields returned by the API server."""
96103
return self.as_dataframe(ignore_fields=self._api_row_ignore_fields + (ignore_fields or []))
97104

98-
def as_api_compatibility_row_df(self, ignore_fields: Optional[List[str]] = None) -> pd.DataFrame:
105+
def as_api_compatibility_row_df(
106+
self, ignore_fields: Optional[List[str]] = None
107+
) -> pd.DataFrame:
99108
"""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 []))
109+
return self.as_dataframe(
110+
ignore_fields=self._api_row_compatibility_ignore_fields + (ignore_fields or [])
111+
)
101112

102113
def as_db_row_df(self, ignore_fields: Optional[List[str]] = None) -> pd.DataFrame:
103114
"""Returns a dataframe view into the row with the fields returned by an all-field database query."""
@@ -113,7 +124,6 @@ def time_pair(self):
113124
return f"{self.time_type}:{self.time_value}"
114125

115126

116-
117127
def check_valid_dtype(dtype):
118128
try:
119129
pd.api.types.pandas_dtype(dtype)

src/common/logger.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import threading
55
import structlog
66

7+
78
def handle_exceptions(logger):
89
"""Handle exceptions using the provided logger."""
10+
911
def exception_handler(etype, value, traceback):
10-
logger.exception("Top-level exception occurred",
11-
exc_info=(etype, value, traceback))
12+
logger.exception("Top-level exception occurred", exc_info=(etype, value, traceback))
1213

1314
def multithread_exception_handler(args):
1415
exception_handler(args.exc_type, args.exc_value, args.exc_traceback)
@@ -17,9 +18,7 @@ def multithread_exception_handler(args):
1718
threading.excepthook = multithread_exception_handler
1819

1920

20-
def get_structured_logger(name=__name__,
21-
filename=None,
22-
log_exceptions=True):
21+
def get_structured_logger(name=__name__, filename=None, log_exceptions=True):
2322
"""Create a new structlog logger.
2423
2524
Use the logger returned from this in indicator code using the standard
@@ -49,11 +48,7 @@ def get_structured_logger(name=__name__,
4948
else:
5049
log_level = logging.INFO
5150

52-
logging.basicConfig(
53-
format="%(message)s",
54-
level=log_level,
55-
handlers=handlers
56-
)
51+
logging.basicConfig(format="%(message)s", level=log_level, handlers=handlers)
5752

5853
def add_pid(logger, method_name, event_dict):
5954
"""
@@ -85,7 +80,7 @@ def add_pid(logger, method_name, event_dict):
8580
# Decode unicode characters
8681
structlog.processors.UnicodeDecoder(),
8782
# Render as JSON
88-
structlog.processors.JSONRenderer()
83+
structlog.processors.JSONRenderer(),
8984
],
9085
# Use a dict class for keeping track of data.
9186
context_class=dict,

0 commit comments

Comments
 (0)