This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| from custom_module import api_get_data | |
| uri = 'http://<.....>' | |
| def fail(*args, **kwargs): | |
| raise requests.exceptions.RequestException() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def api_get_data() -> List[Mapping]: | |
| """ Gets data from the API. """ | |
| url = "{}/v1/booking".format(os.environ['CT_BOOKING_API_URI']) | |
| params: Dict = { | |
| ... | |
| 'limit': 1000, | |
| 'offset': 0, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import hashlib | |
| def get_obj_key(obj: Type) -> str: | |
| """ Creates and returns a unique object id.""" | |
| obj_key = '+'.join( | |
| [ | |
| obj.attr1, str(obj.num_attr1), obj.attr2, ... | |
| ]) | |
| return hashlib.md5(obj_key.encode('utf8')).hexdigest() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def test_format_to_dict(): | |
| """ Tests formatting to a dictionary. """ | |
| data_to_transform = defaultdict(lambda: defaultdict(lambda: {})) | |
| assert isinstance(format_to_dict(data_to_transform), dict) | |
| def test_valid(): | |
| valid_data = {'valid_key': 1} | |
| assert function_to_test(valid_data) == 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| from <service> import app | |
| # ex: app = flask.Flask(__name__, static_url_path='/static') | |
| @pytest.fixture | |
| def client(): | |
| app.app.config['TESTING'] = True | |
| client = app.app.test_client() | |
| yield client |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| headers = { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': ('...'), | |
| 'accept': 'application/json' | |
| } | |
| def test_post(client): | |
| response = client.post('/endpoint', | |
| data=json.dumps(payload), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import globt | |
| # if you need a list, just use glob.glob instead of glob.iglob | |
| for filename in glob.iglob('src/**/*.c', recursive=True): | |
| pprint(filename) | |
| # ----- OR ----- | |
| from pathlib import Path |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create_link(file_name, file_id): | |
| return f'http://localhost:port/{file_name}/{file_id}' | |
| def make_clickable(val): | |
| # target _blank to open new window | |
| return '<a target="_blank" href="{}">{}</a>'.format(val, val) | |
| data['link'] = data.apply(lambda x: create_link(str(x['file_path']), x['file_id']), axis=1) | |
| clickable_table = data.style.format({'link': make_clickable}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sklearn.metrics import precision_score, recall_score, precision_recall_curve | |
| import matplotlib.pyplot as plt | |
| def plt_prc(recall, precision, label=None): | |
| plt.step(recall, precision, label=label) | |
| plt.xlabel('Recall') | |
| plt.ylabel('Precision') | |
| plt.ylim([0.0, 1.05]) | |
| plt.xlim([0.0, 1.0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| filters = { | |
| 'field_1': <threshold value for the field1>, | |
| 'field_2': <threshold value for the field2>, | |
| } | |
| # creates a matrix of True's | |
| mask = np.ones(features.shape[0], dtype=bool) | |
| for field, threshold_value in filters.items(): | |
| # updates the matrix with |