Skip to content

Instantly share code, notes, and snippets.

@datavudeja
datavudeja / data_importer_with_field_checks.py
Created September 30, 2025 13:47 — forked from adgedenkers/data_importer_with_field_checks.py
Data File Importer That Checks Field Names
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
@datavudeja
datavudeja / nullsafe.py
Created September 30, 2025 13:47 — forked from fzhem/nullsafe.py
Null-safe comparison accessor for Pandas
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
@datavudeja
datavudeja / main.py
Created September 17, 2025 20:20 — forked from mypy-play/main.py
Shared via mypy Playground
# 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
@datavudeja
datavudeja / units.py
Created September 17, 2025 20:16 — forked from markusand/units.py
A simple unit converter system with Measure value object
"""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
@datavudeja
datavudeja / rasp.py
Created September 17, 2025 20:16 — forked from profsucrose/rasp.py
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:
@datavudeja
datavudeja / main.py
Created September 17, 2025 20:10 — forked from mypy-play/main.py
Shared via mypy Playground
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):
@datavudeja
datavudeja / status.py
Created September 17, 2025 19:49 — forked from isaquealves/status.py
Status rule
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"
@datavudeja
datavudeja / math_parser.py
Created September 17, 2025 19:32 — forked from ve-ron/math_parser.py
A math calculator parser in python.
# 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:
@datavudeja
datavudeja / tokenize.py
Created September 17, 2025 19:30 — forked from jorektheglitch/tokenize.py
Simple tokenizer for (extended) math expressions
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")
@datavudeja
datavudeja / main.py
Created September 17, 2025 19:29 — forked from io-mi/main.py
Simple Lexer & Parser in Python
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