|
5 | 5 | import asyncio |
6 | 6 | from collections import OrderedDict |
7 | 7 | from datetime import datetime, timedelta, timezone |
8 | | -from billiard import current_process |
| 8 | +from billiard import current_process # pylint: disable=no-name-in-module |
9 | 9 | import requests |
10 | 10 | from requests.exceptions import ConnectionError as ConnError |
11 | 11 | import pandas as pd |
@@ -249,6 +249,12 @@ async def make_async_request(self, url, params, session, retry=0): |
249 | 249 |
|
250 | 250 | exception_type = type(e).__name__ |
251 | 251 |
|
| 252 | + # If we're just catching the exception raised above |
| 253 | + # don't need to do anything else |
| 254 | + if exception_type == 'MailChimpImportError': |
| 255 | + raise |
| 256 | + |
| 257 | + # Otherwise, log what happened as appropriate |
252 | 258 | if exception_type == 'ClientHttpProxyError': |
253 | 259 | self.logger.warning('Failed to connect to proxy! Proxy: %s', |
254 | 260 | self.proxy) |
@@ -287,6 +293,7 @@ async def make_async_request(self, url, params, session, retry=0): |
287 | 293 | # Log the error and raise an exception |
288 | 294 | self.logger.exception('Error in async request to MailChimp (%s)', |
289 | 295 | exception_type) |
| 296 | + |
290 | 297 | raise MailChimpImportError( |
291 | 298 | 'Error in async request to MailChimp ({})'.format( |
292 | 299 | exception_type), |
@@ -397,6 +404,7 @@ async def import_sub_activity(self): # pylint: disable=too-many-locals |
397 | 404 | """ |
398 | 405 | params = ( |
399 | 406 | ('fields', 'activity.action,activity.timestamp,email_id'), |
| 407 | + ('exclude_fields', 'total_items,_links') |
400 | 408 | ) |
401 | 409 |
|
402 | 410 | request_uri = ('https://{}.api.mailchimp.com/3.0/lists/{}/members/' |
@@ -516,10 +524,10 @@ def calc_frequency(self, date_created, campaign_count): |
516 | 524 |
|
517 | 525 | def calc_histogram(self): |
518 | 526 | """Calculates the distribution for subscriber open rate.""" |
519 | | - bin_boundaries = [-0.001, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1.] |
| 527 | + bin_boundaries = np.linspace(0, 1, num=11) |
520 | 528 | bins = (pd.cut( |
521 | 529 | self.df.loc[self.df['status'] == 'subscribed', 'avg_open_rate'], |
522 | | - bin_boundaries)) |
| 530 | + bin_boundaries, include_lowest=True)) |
523 | 531 | self.hist_bin_counts = (pd.value_counts(bins, sort=False).tolist()) |
524 | 532 |
|
525 | 533 | def calc_high_open_rate_pct(self): |
|
0 commit comments