Skip to content

Instantly share code, notes, and snippets.

@dutc
dutc / class.py
Created Aug 31, 2021
“Python Expert” Newsletter (Sep 22, 2021): Learning Corner
View class.py
def foo(self, _):
pass
class T:
from json import dumps
from itertools import repeat
foo = foo
def bar(self, _):
pass
@dutc
dutc / getattr.py
Created Aug 31, 2021
“Python Expert” Newsletter (Sep 15, 2021): Learning Corner
View getattr.py
class A:
x = 1
class B(A):
y = 20
class D:
def __get__(self, instance, owner):
return 50_000
@dutc
dutc / mro.py
Created Aug 31, 2021
“Python Expert” Newsletter (Sep 8, 2021): Learning Corner
View mro.py
class A:
def foo(self):
return 'A.foo',
class B(A):
def foo(self):
return 'B.foo', *super().foo()
class C(A):
def foo(self):
@dutc
dutc / protocols.py
Created Aug 31, 2021
“Python Expert” Newsletter (Sep 1, 2021): Learning Corner
View protocols.py
from pandas import DataFrame
class Base:
def __len__(self):
return 1
class Derived(Base):
def __len__(self):
return super().__len__() + 1
@dutc
dutc / groupby.apply.py
Created Jul 13, 2021
“Python Expert” Newsletter (July 28, 2021): Learning Corner
View groupby.apply.py
from numpy import tile, repeat, int64
from numpy.random import default_rng
from pandas import DataFrame, date_range, Timestamp, concat
from pandas.tseries.offsets import Day
from random import seed
from scipy.stats import zscore
from string import ascii_lowercase
if __name__ == '__main__':
rng = default_rng(s := Timestamp('2021-07-04').asm8.astype('uint32'))
@dutc
dutc / groupby.aggregate.py
Last active Jul 13, 2021
“Python Expert” Newsletter (July 21, 2021): Learning Corner
View groupby.aggregate.py
from numpy import tile, repeat
from numpy.random import default_rng
from pandas import DataFrame, date_range, Timestamp
from pandas.tseries.offsets import Day
from random import seed
from scipy.stats import zscore
from string import ascii_lowercase
if __name__ == '__main__':
rng = default_rng(s := Timestamp('2021-07-04').asm8.astype('uint32'))
@dutc
dutc / groupby.transform.py
Created Jul 13, 2021
“Python Expert” Newsletter (July 14, 2021): Learning Corner
View groupby.transform.py
from numpy import tile, repeat
from numpy.random import default_rng
from pandas import DataFrame, date_range, Timestamp
from pandas.tseries.offsets import Day
from random import seed
from scipy.stats import zscore
from string import ascii_lowercase
if __name__ == '__main__':
rng = default_rng(s := Timestamp('2021-07-04').asm8.astype('uint32'))
@dutc
dutc / groupby.py
Created Jul 7, 2021
“Python Expert” Newsletter (July 7, 2021): Learning Corner
View groupby.py
#!/usr/bin/env python3
from functools import total_ordering
from dataclasses import dataclass
from numpy import tile, repeat
from numpy.random import default_rng
from pandas import DataFrame, date_range, Timestamp
from pandas.core.dtypes.common import is_numeric_dtype
from random import seed
from string import ascii_lowercase
@dutc
dutc / slides.clay
Created Apr 7, 2021
“Python Expert” Newsletter (Apr 4, 2021): Slides for “What Does it All Really Mean?” (https://www.youtube.com/watch?v=hYi9S0GwVB8)
View slides.clay
! pulse
What Does It All
<i>Really</i> <b>Mean</b> <i>?</i>
! fade
What Does It All
<i>Really</i> <b>Mean</b> <i>?</i>
\
☆ PyCon India ☆ Sat Oct 3, 2020 ☆
@dutc
dutc / cidict.py
Created Mar 24, 2021
“Python Expert” Newsletter (Mar 23, 2021): Learning Corner, Python Data Structure Fundamentals and “Concordance”
View cidict.py
from collections.abc import Mapping, MutableMapping
class cidict(dict):
''' a case insensitive, immutable `dict` subclass '''
def __init__(self, *args, **kwargs):
super().__init__({k.lower(): v for k, v in dict(*args, **kwargs).items()})
def __missing__(self, key):
return self[key.lower()]
__setitem__ = __delitem__ = None
clear = update = pop = popitem = setdefault = update = None