Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/ci/scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ for python_container in $python_containers; do
docker exec $python_container bash -c 'sudo chown -R circleci:circleci /home/circleci/project'
docker exec -w /home/circleci/project $python_container bash -c 'python3 -m pip install --upgrade pip'
docker exec -w /home/circleci/project $python_container bash -c 'python3 -m pip install --upgrade flake8 flake8-commas flake8-quotes'
docker exec -w /home/circleci/project $python_container bash -c 'python3 -m flake8 . --max-complexity=10 --max-line-length=160 --show-source --exclude __init__.py'
docker exec -w /home/circleci/project $python_container bash -c 'python3 -m flake8 . --max-complexity=12 --max-line-length=160 --show-source --exclude __init__.py'
docker exec -w /home/circleci/project $python_container bash -c 'python3 -m pip install -e .[report]'
docker exec -w /home/circleci/project $python_container bash -c 'python3 -m pip install --upgrade python-dotenv pytest coverage'
# The minimum version of each dependency should be tested in the
Expand Down
2 changes: 1 addition & 1 deletion xdmod_data/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__title__ = 'xdmod-data'
__version__ = '1.1.0'
__version__ = '1.1.1.dev1'
69 changes: 37 additions & 32 deletions xdmod_data/_http_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@


class _HttpRequester:
def __init__(self, xdmod_host):
def __init__(self, xdmod_host, logger):
self.__logger = logger
self.__in_runtime_context = False
_validator._assert_str('xdmod_host', xdmod_host)
xdmod_host = re.sub('/+$', '', xdmod_host)
Expand Down Expand Up @@ -65,37 +66,41 @@ def _request_raw_data(self, params):
# line contains the row we care about and the first line
# contains the hex size of the second line.
is_first_line_in_pair = True
for line in response.iter_lines():
# There is a bug in Requests (see
# https://github.com/psf/requests/issues/5540) such that empty
# lines are occasionally sent via iter_lines(); ignore these.
if line == b'':
continue
line_text = line.decode('utf-8')
if is_first_line_in_pair:
last_line_size = line_text
# The last line will be of size 0 and should not be
# processed.
elif last_line_size != '0': # pragma: no branch
(data, fields) = self.__process_raw_data_response_row(
line_text,
num_rows_read,
params['show_progress'],
data,
fields,
)
num_rows_read += 1
is_first_line_in_pair = not is_first_line_in_pair
if params['show_progress']:
self.__print_progress_msg(num_rows_read, 'DONE\n')
if last_line_size != '0': # pragma: no cover
raise RuntimeError(
'Connection closed before all data were received!'
+ ' You may need to break your request into smaller'
+ ' chunks by running `get_raw_data()` multiple times with'
+ ' fewer days specified for `duration` and then piecing'
+ ' the resulting data frames back together.',
)
connection_closed_warning_msg = (
'Connection closed before all data were received!'
+ ' You may need to break your request into smaller'
+ ' chunks by running `get_raw_data()` multiple times with'
+ ' fewer days specified for `duration` and then piecing'
+ ' the resulting data frames back together.'
)
try:
for line in response.iter_lines():
# There is a bug in Requests (see
# https://github.com/psf/requests/issues/5540) such that empty
# lines are occasionally sent via iter_lines(); ignore these.
if line == b'':
continue
line_text = line.decode('utf-8')
if is_first_line_in_pair:
last_line_size = line_text
# The last line will be of size 0 and should not be
# processed.
elif last_line_size != '0': # pragma: no branch
(data, fields) = self.__process_raw_data_response_row(
line_text,
num_rows_read,
params['show_progress'],
data,
fields,
)
num_rows_read += 1
is_first_line_in_pair = not is_first_line_in_pair
if params['show_progress']:
self.__print_progress_msg(num_rows_read, 'DONE\n')
if last_line_size != '0': # pragma: no cover
self.__logger.warning(connection_closed_warning_msg)
except requests.exceptions.ChunkedEncodingError: # pragma: no cover
self.__logger.warning(connection_closed_warning_msg)
return (data, fields)

def _request_filter_values(self, realm_id, dimension_id):
Expand Down
13 changes: 12 additions & 1 deletion xdmod_data/warehouse.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import numpy as np
import os
import pandas as pd
Expand Down Expand Up @@ -50,7 +51,8 @@ def __init__(self, xdmod_host=None):
'`xdmod_host` parameter or `XDMOD_HOST` environment'
+ ' variable must be set.',
) from None
self.__http_requester = _HttpRequester(xdmod_host)
self.__logger = self.__init_logger()
self.__http_requester = _HttpRequester(xdmod_host, self.__logger)
self.__descriptors = _Descriptors(self.__http_requester)

def __enter__(self):
Expand Down Expand Up @@ -456,6 +458,15 @@ def _get_dimension_label(self, realm, dimension_id):
d = self.__descriptors._get_aggregate()
return d[realm]['dimensions'][dimension_id]['label']

def __init_logger(self):
logger = logging.getLogger('xdmod_data_warehouse')
logger.setLevel(logging.WARNING)
formatter = logging.Formatter('Warning: %(message)s')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger

def __get_data_frame(self, data, column_data, index=None):
result = pd.DataFrame(
data=data,
Expand Down