Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 typing import Union | |
def is_valid_type(object): | |
return isinstance(object, Union[str, None]) | |
def is_valid_type_new(object): | |
return isinstance(object, str | None) |
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 pandas as pd | |
from pandas.testing import assert_frame_equal | |
df_one = pd.DataFrame( | |
{"city": ["Tokyo", "Delhi"], "population": [13_515_271, 16_753_235]} | |
) | |
df_two = df_one[["population", "city"]].copy(deep=True) | |
assert_frame_equal(left=df_one, right=df_two) |
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
names = ['a', 'b', 'c'] | |
values = [10, 54, 2] | |
values_too_long = values + [10] | |
""" | |
>>> {k: v for k, v in zip(names, values_too_long, strict=True)} | |
ValueError: zip() argument 2 is longer than argument 1 | |
>>> {k: v for k, v in zip(names, values_too_long, strict=False)} | |
{'a': 10, 'b': 54, 'c': 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
import pandas as pd | |
from pandarallel import pandarallel | |
from sklearn.datasets import fetch_20newsgroups | |
def preprocess_text(row: pd.Series) -> float: | |
return [word.lower() for word in row.text.split()] | |
def get_data() -> pd.DataFrame: |
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 json | |
import pytest | |
@pytest.fixture | |
def min_dict(): | |
return {"name": "foo"} | |
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 pydantic import BaseSettings, Field, SecretStr | |
class Credentials(BaseSettings): | |
password: SecretStr = Field(..., env="DB_PASSWORD") | |
""" | |
>>> Credentials() | |
pydantic.error_wrappers.ValidationError: 1 validation error for Credentials |
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 pydantic import SecretStr | |
# NOTE: it is usually not a good idea to hard-code your passwords, | |
# this is just for illustration purposes | |
my_password = SecretStr("adminAdmin123") | |
""" | |
>>> str(my_password) | |
'**********' | |
>>> print(my_password) |
NewerOlder