File size: 1,488 Bytes
7bd410e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b5326d
 
 
 
7bd410e
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# # utils.py
# import io
# import pandas as pd

# def pick_existing_columns(all_cols: list[str], desired: list[str]) -> list[str]:
#     seen = {c.lower(): c for c in all_cols}
#     out = []
#     for d in desired:
#         key = d.lower()
#         if key in seen:
#             out.append(seen[key])
#     return out or list(all_cols)  # fall back to everything if none matched

# def slice_up_to_page(df: pd.DataFrame, page: int, page_size: int) -> pd.DataFrame:
#     start = page * page_size
#     end = start + page_size
#     return df.iloc[:end].copy()

# def contains_any_column(df: pd.DataFrame, term: str) -> pd.Series:
#     if not term:
#         return pd.Series([True] * len(df), index=df.index)
#     term = str(term).strip()
#     if not term:
#         return pd.Series([True] * len(df), index=df.index)

#     # Combine columns as strings (fast-ish)
#     joined = df.astype(str).apply(lambda col: col.str.contains(term, case=False, na=False))
#     return joined.any(axis=1)

# def export_csv(df: pd.DataFrame) -> tuple[str, bytes]:
#     buf = io.StringIO()
#     df.to_csv(buf, index=False)
#     name = "buildscout_export.csv"
#     return name, buf.getvalue().encode("utf-8")

# utils.py
import io
import pandas as pd

def pick_existing_columns(all_cols, wanted):
    s = set(all_cols)
    return [c for c in wanted if c in s]

def export_csv(df: pd.DataFrame) -> io.BytesIO:
    bio = io.BytesIO()
    df.to_csv(bio, index=False)
    bio.seek(0)
    return bio