Event: PyCon Lithuania
Date: Thu May 26, 2022
Speaker: James Powell
Twitter: @dontusethiscode
| #!/usr/bin/env python3 | |
| from collections import namedtuple | |
| from functools import wraps | |
| from inspect import signature | |
| from itertools import islice, tee | |
| from math import isclose | |
| from shlex import quote | |
| from subprocess import check_call, DEVNULL, CalledProcessError | |
| from textwrap import dedent |
| from pandas import MultiIndex, date_range, Series, Categorical, merge, get_dummies, date_range, DataFrame | |
| from itertools import product | |
| from numpy import arange, zeros, newaxis, tile, log2 | |
| from numpy.random import default_rng | |
| from string import ascii_lowercase | |
| from contextlib import contextmanager | |
| from time import perf_counter | |
| from matplotlib.cm import get_cmap | |
| from matplotlib.pyplot import subplots, show |
Event: PyCon Lithuania
Date: Thu May 26, 2022
Speaker: James Powell
Twitter: @dontusethiscode
| from pandas import read_csv | |
| s = read_csv('data.txt', squeeze=True, header=None) | |
| print( | |
| (s.diff() > 0).sum(), | |
| ) |
| #!/usr/bin/env python3 | |
| from itertools import tee, islice, zip_longest, chain, repeat | |
| nwise = lambda g, *, n=2: zip(*(islice(g, i, None) for i, g in enumerate(tee(g, n)))) | |
| nwise_longest = lambda g, *, n=2, fv=object(): zip_longest(*(islice(g, i, None) for i, g in enumerate(tee(g, n))), fillvalue=fv) | |
| first = lambda g, *, n=1: zip(chain(repeat(True, n), repeat(False)), g) | |
| last = lambda g, *, m=1, s=object(): ((xs[-1] is s, x) for x, *xs in nwise_longest(g, n=m+1, fv=s)) | |
| if __name__ == '__main__': |
| from pandas import Series | |
| from numpy.random import default_rng | |
| from string import ascii_lowercase | |
| rng = default_rng(0) | |
| s = Series( | |
| rng.integers(-10, 10, size=(size := 10_000)), | |
| index=rng.choice([*ascii_lowercase], size=(size, length := 10)).view(f'<U{length}').ravel(), | |
| ) |
| def foo(self, _): | |
| pass | |
| class T: | |
| from json import dumps | |
| from itertools import repeat | |
| foo = foo | |
| def bar(self, _): | |
| pass |
| class A: | |
| x = 1 | |
| class B(A): | |
| y = 20 | |
| class D: | |
| def __get__(self, instance, owner): | |
| return 50_000 |
| 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): |
| from pandas import DataFrame | |
| class Base: | |
| def __len__(self): | |
| return 1 | |
| class Derived(Base): | |
| def __len__(self): | |
| return super().__len__() + 1 |