import torch

def build_batch(df):
    municipios = df["municipio"].unique()
    series_list = []

    for mun in municipios:
        s = df[df["municipio"] == mun]["taxa"].values

        if len(s) < 20:
            continue

        s = torch.tensor(s, dtype=torch.float32)
        series_list.append(s)

    # padding
    max_len = max(len(s) for s in series_list)

    padded = []
    for s in series_list:
        pad = torch.zeros(max_len)
        pad[:len(s)] = s
        padded.append(pad)

    batch = torch.stack(padded).unsqueeze(1)  # (N,1,T)

    return batch, municipios
