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 pandas as pd | |
import pyodbc | |
class DataImporter: | |
""" | |
This Python class takes in a pandas DataFrame from a CSV file and a SQL Server connection string, as | |
well as a name for the SQL table where the data will be imported. The class compares the columns of | |
the DataFrame to those in the SQL table and ensures that at least 50% of the fields match. If there | |
are missing fields, the class adds them to the SQL table using the same naming convention as existing | |
fields. All new fields are created as varchar fields by default. Once the SQL table has all the fields |
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 pandas as pd | |
@pd.api.extensions.register_series_accessor("nullsafe") | |
class NullSafeSeriesAccessor: | |
""" | |
Null-safe comparison accessor for Pandas Series. | |
This is equivalent to a null-safe equal operator in SQL (<=>) where |
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
# This example is copied verbatim from one of the codebases I contribute to. | |
# Unfortunately, I can't copy it, so I tried to extract the scenario as it was, | |
# as an example that I could share publicly. | |
# | |
# I'm sure the example could be simplified, but I thought it would be better to | |
# show it as it is, and leave any conclusions to whomever is going to read it. | |
# | |
from typing import Union, TypeVar, Callable | |
from typing_extensions import TypeAlias, Literal, overload |
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
"""Unit conversion""" | |
from dataclasses import dataclass | |
from functools import total_ordering | |
from enum import Enum | |
from typing import Callable, NamedTuple | |
class UnitDesc(NamedTuple): | |
"""Unit description""" | |
scale: float |
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 dataclasses import dataclass | |
from typing import Callable, Any, Literal, Type | |
from enum import Enum | |
El = int | float | str | |
S = list[El] | |
BoolMat = list[list[bool]] | |
def default_for_type(t: Type) -> El: |
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 enum import Enum, unique, auto | |
from dataclasses import dataclass | |
from typing import List, TypeVar, Type | |
from pathlib import Path | |
import os | |
I = TypeVar('I', bound='Input') | |
@unique | |
class InputType(Enum): |
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 dataclasses import dataclass | |
from datetime import datetime | |
import enum | |
from functools import reduce | |
from typing import List, Optional | |
import uuid | |
class StatusEnum(enum.Enum): | |
PENDING: str = "PENDING" |
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
# Thanks blanket#1213 https://github.com/blanketsucks for helping. | |
from dataclasses import dataclass | |
import enum | |
import math | |
class MathError(Exception): | |
pass | |
class InavliadSyntax(MathError): | |
def __init__(self, *args: object) -> None: |
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 abc import ABC | |
from dataclasses import dataclass | |
from enum import Enum | |
from string import ascii_letters, digits | |
from typing import List, Optional, Union | |
DELIMITER = Enum("DELIMITER", "COMMA SEMICOLON") |
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 typing import Iterator, Match, TypeVar, Type | |
from dataclasses import dataclass, field | |
from enum import Enum | |
import re | |
class TokenKind(int, Enum): | |
NUMBER = 0x01 | |
SYMBOL = 0x02 | |
ASSIGN = 0x03 |
NewerOlder