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 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 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
.PHONY: test lint | |
lint: | |
TEST=1 pylint <folder> --rcfile=pylint.cfg | |
flake8 | |
test: | |
coverage run --rcfile=setup.cfg --source=<folder> -m pytest --ignore=<folder to ignore> | |
coverage report --rcfile=setup.cfg |
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
[flake8] | |
max-line-length = 100 | |
[coverage:run] | |
branch=True | |
source=<folder to run coverage on> | |
omit= | |
*/<folder to omit>/* | |
[coverage:report] |
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
[MASTER] | |
# run on all available cores | |
jobs=0 | |
# Specify a configuration file. | |
#rcfile= | |
# Python code to execute, usually for sys.path manipulation such as | |
# pygtk.require(). |
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 pymongo import MongoClient | |
def get_db(): | |
# For local use | |
from pymongo import MongoClient | |
# if your db is run locally | |
client = MongoClient(host='localhost', port=27017) | |
print(client.list_database_names()) | |
return client.warehouse |
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
(pd.pivot_table( | |
direct_roundtrip_flights.query('departure_and_destination in @most_common_dep_dest_pairs'), | |
index=['departure_and_destination', 'type_of_flight', 'departure_time_interval', 'departure_day_of_week'], | |
values='booking_id', | |
aggfunc={'booking_id': np.count_nonzero}) | |
.rename(columns={'booking_id': 'n'}) | |
.sort_values('n', ascending=False) | |
) |
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
label_size = 30 | |
plt.rcParams['xtick.labelsize'] = label_size | |
plt.figure(figsize=(100, 250)) | |
# put on one date plain | |
df['departure_time_utc'] = df['departure_time_utc'].apply(lambda dt: dt.replace(year=2018, month=11, day=20)) | |
# group by category | |
grouped = df.groupby('departure_and_destination') |
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 os | |
import unittest | |
import shutil | |
from setuptools import setup | |
from setuptools import Command | |
from <module> import __version__ | |
try: | |
import coverage |