This file contains 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 pathlib import Path | |
data_directory_path = Path('data/assets') | |
data_directory_path.mkdir(parents=True, exist_ok=True) |
This file contains 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 pathlib import Path | |
import boto3 | |
from tqdm import tqdm | |
def upload_to_s3( | |
file_name: str, | |
target_bucket_name: str, | |
target_object_name: str, |
This file contains 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 datetime import datetime | |
from pydantic import BaseModel | |
class Message(BaseModel): | |
id: int | |
content: str | |
created_at: datetime |
This file contains 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
first_dict = {"a": 1, "b": "foo"} | |
second_dict = {"c": 1, "d": 5.5, "e": "bar"} | |
combined_dict_1 = first_dict | second_dict | |
combined_dict_2 = {**first_dict, **second_dict} | |
assert combined_dict_1 == combined_dict_2 |
This file contains 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 pathlib import Path | |
def delete_all(directory_path: Path): | |
if directory_path.is_dir(): | |
for file in directory_path.iterdir(): | |
file.unlink(missing_ok=True) | |
if __name__ == "__main__": |
This file contains 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 operator | |
from itertools import groupby | |
list_of_city_dicts = [ | |
{"city": "New York"}, | |
{"city": "Hamburg"}, | |
{"city": "New York"}, | |
{"city": "Puerto Viejo"}, | |
] |
This file contains 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 operator | |
from itertools import groupby | |
list_of_city_dicts = [ | |
{"city": "New York", "country": "US"}, | |
{"city": "San José", "country": "CR"}, | |
{"city": "New York", "country": "US"}, | |
{"city": "San José", "country": "CO"}, | |
{"city": "Puerto Viejo", "country": "CR"}, | |
] |
This file contains 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 boto3 | |
from moto import mock_s3 | |
def create_s3_bucket(bucket_name: str, aws_region: str): | |
s3_client = boto3.client("s3", region_name=aws_region) | |
s3_client.create_bucket( | |
Bucket=bucket_name, CreateBucketConfiguration={"LocationConstraint": aws_region} | |
) |
This file contains 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 pathlib import Path | |
from cloudpathlib import CloudPath | |
s3_file = "s3://mybucket/foo/bar.txt" | |
cloud_path = CloudPath(s3_file) | |
conventional_path = Path(s3_file) | |
""" |
This file contains 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
feature_names = ["sepal_length", "sepal_width", "petal_length", "petal_width"] | |
default_type = float | |
feature_map = dict.fromkeys(feature_names, default_type) | |
""" | |
>>> feature_map | |
{'sepal_length': <class 'float'>, 'sepal_width': <class 'float'>, | |
'petal_length': <class 'float'>, 'petal_width': <class 'float'>} |
OlderNewer