File size: 700 Bytes
7f9a652
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import glob, os, re


def latest(root, pattern):
    """Newest file matching pattern (by the date in its path), as a path relative to root."""
    hits = sorted(glob.glob(os.path.join(root, pattern)))
    if not hits:
        return None
    hits.sort(key=lambda p: re.findall(r'\d{4}-\d{2}-\d{2}', p)[-1] if re.findall(r'\d{4}-\d{2}-\d{2}', p) else '')
    return os.path.relpath(hits[-1], root).replace(os.sep, '/')


def day_of(rel):
    m = re.findall(r'\d{4}-\d{2}-\d{2}', rel or '')
    return m[-1] if m else None


def has(df, *cols):
    return all(c in df.columns for c in cols)


def uniq(df, col):
    return df[df[col].notna() & ~df.duplicated([col], keep=False)]