smartcolumns 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 vallomar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: smartcolumns
3
+ Version: 0.1.0
4
+ Summary: Detect and normalize column names in messy CSV and Excel tables (French, Arabic, English).
5
+ Author: vallomar
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/vallomar/smartcolumns
8
+ Keywords: csv,excel,columns,data-cleaning,arabic,french
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Dynamic: license-file
16
+
17
+ # smartcolumns
18
+
19
+ Detect and normalize column names in messy CSV and Excel tables. It understands French, Arabic and English headers, for example `Nom_FR`, `Moy Bac` or `الاسم الكامل`.
20
+
21
+ It has no dependencies and works on any list of column names, so you can use it with pandas, csv or openpyxl.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install smartcolumns
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```python
32
+ from smartcolumns import detect_columns, clean_col_name
33
+
34
+ detect_columns(["Nom_FR", "Moy Bac", "Decision"])
35
+ # {'name_fr': 'Nom_FR', 'score': 'Moy Bac', 'decision': 'Decision'}
36
+
37
+ clean_col_name(" Nom_FR ")
38
+ # 'nom fr'
39
+ ```
40
+
41
+ With pandas:
42
+
43
+ ```python
44
+ import pandas as pd
45
+ from smartcolumns import detect_columns
46
+
47
+ df = pd.read_csv("results.csv")
48
+ cols = detect_columns(df.columns)
49
+ df = df.rename(columns={v: k for k, v in cols.items()})
50
+ ```
51
+
52
+ ## Canonical names
53
+
54
+ `student_id`, `name_fr`, `name_ar`, `score`, `decision`, `wilaya_fr`, `wilaya_ar`, `school`, `series`, `birth_date`, `birth_place_fr`, `birth_place_ar`. The keyword lists are in `smartcolumns.COLUMN_PATTERNS`.
55
+
56
+ Matching is by keyword: the first column whose cleaned name contains a keyword wins. Short keywords like `id` can match inside longer names, so check the result on unusual files.
57
+
58
+ ## Tests
59
+
60
+ ```bash
61
+ python -m unittest discover tests
62
+ ```
63
+
64
+ ## License
65
+
66
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,50 @@
1
+ # smartcolumns
2
+
3
+ Detect and normalize column names in messy CSV and Excel tables. It understands French, Arabic and English headers, for example `Nom_FR`, `Moy Bac` or `الاسم الكامل`.
4
+
5
+ It has no dependencies and works on any list of column names, so you can use it with pandas, csv or openpyxl.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install smartcolumns
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```python
16
+ from smartcolumns import detect_columns, clean_col_name
17
+
18
+ detect_columns(["Nom_FR", "Moy Bac", "Decision"])
19
+ # {'name_fr': 'Nom_FR', 'score': 'Moy Bac', 'decision': 'Decision'}
20
+
21
+ clean_col_name(" Nom_FR ")
22
+ # 'nom fr'
23
+ ```
24
+
25
+ With pandas:
26
+
27
+ ```python
28
+ import pandas as pd
29
+ from smartcolumns import detect_columns
30
+
31
+ df = pd.read_csv("results.csv")
32
+ cols = detect_columns(df.columns)
33
+ df = df.rename(columns={v: k for k, v in cols.items()})
34
+ ```
35
+
36
+ ## Canonical names
37
+
38
+ `student_id`, `name_fr`, `name_ar`, `score`, `decision`, `wilaya_fr`, `wilaya_ar`, `school`, `series`, `birth_date`, `birth_place_fr`, `birth_place_ar`. The keyword lists are in `smartcolumns.COLUMN_PATTERNS`.
39
+
40
+ Matching is by keyword: the first column whose cleaned name contains a keyword wins. Short keywords like `id` can match inside longer names, so check the result on unusual files.
41
+
42
+ ## Tests
43
+
44
+ ```bash
45
+ python -m unittest discover tests
46
+ ```
47
+
48
+ ## License
49
+
50
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "smartcolumns"
7
+ version = "0.1.0"
8
+ description = "Detect and normalize column names in messy CSV and Excel tables (French, Arabic, English)."
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text = "MIT"}
12
+ authors = [{name = "vallomar"}]
13
+ keywords = ["csv", "excel", "columns", "data-cleaning", "arabic", "french"]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/vallomar/smartcolumns"
22
+
23
+ [tool.setuptools]
24
+ packages = ["smartcolumns"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,49 @@
1
+ """smartcolumns: detect canonical columns in messy tables.
2
+
3
+ Header names in real-world spreadsheets are inconsistent: "Nom_FR", "NOM FR",
4
+ "Moy Bac", "الاسم الكامل". This module maps such headers to canonical names
5
+ (for example ``name_fr`` or ``score``) using simple keyword matching.
6
+ """
7
+ import re
8
+
9
+ __version__ = "0.1.0"
10
+ __all__ = ["COLUMN_PATTERNS", "clean_col_name", "detect_columns"]
11
+
12
+ COLUMN_PATTERNS = {
13
+ "student_id": ["nodoss", "numero", "number", "id", "matricule", "code"],
14
+ "name_fr": ["nom_fr", "nom", "name_fr", "full_name_fr", "nom et prenom"],
15
+ "name_ar": ["nom_ar", "الاسم", "الاسم الكامل", "name_ar"],
16
+ "score": ["my bac", "moy bac", "moyenne", "score", "resultat", "note", "mark", "average"],
17
+ "decision": ["decision", "result", "status", "admission"],
18
+ "wilaya_fr": ["wilaya_fr", "wilaya", "state", "region"],
19
+ "wilaya_ar": ["wilaya_ar", "الولاية"],
20
+ "school": ["etablissement", "school", "lycee", "ecole", "institution"],
21
+ "series": ["serie", "filiere", "type", "section", "branch"],
22
+ "birth_date": ["datn", "date naissance", "birth", "birth_date", "dob"],
23
+ "birth_place_fr": ["lieun_fr", "birth_place", "place_fr"],
24
+ "birth_place_ar": ["lieunn_a", "place_ar"],
25
+ }
26
+
27
+
28
+ def clean_col_name(col):
29
+ """Lowercase, trim, turn underscores into spaces and collapse whitespace."""
30
+ col = str(col).strip().lower()
31
+ col = col.replace("_", " ")
32
+ col = re.sub(r"\s+", " ", col)
33
+ return col
34
+
35
+
36
+ def detect_columns(columns):
37
+ """Map canonical names to the original column names found in ``columns``.
38
+
39
+ Returns a dict such as ``{"name_fr": "Nom_FR", "score": "Moy Bac"}``.
40
+ The first matching column wins for each canonical name.
41
+ """
42
+ detected = {}
43
+ cleaned = {col: clean_col_name(col) for col in columns}
44
+ for canonical_name, patterns in COLUMN_PATTERNS.items():
45
+ for original_col, cleaned_col in cleaned.items():
46
+ if any(pat in cleaned_col for pat in patterns):
47
+ detected[canonical_name] = original_col
48
+ break
49
+ return detected
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: smartcolumns
3
+ Version: 0.1.0
4
+ Summary: Detect and normalize column names in messy CSV and Excel tables (French, Arabic, English).
5
+ Author: vallomar
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/vallomar/smartcolumns
8
+ Keywords: csv,excel,columns,data-cleaning,arabic,french
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Dynamic: license-file
16
+
17
+ # smartcolumns
18
+
19
+ Detect and normalize column names in messy CSV and Excel tables. It understands French, Arabic and English headers, for example `Nom_FR`, `Moy Bac` or `الاسم الكامل`.
20
+
21
+ It has no dependencies and works on any list of column names, so you can use it with pandas, csv or openpyxl.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install smartcolumns
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```python
32
+ from smartcolumns import detect_columns, clean_col_name
33
+
34
+ detect_columns(["Nom_FR", "Moy Bac", "Decision"])
35
+ # {'name_fr': 'Nom_FR', 'score': 'Moy Bac', 'decision': 'Decision'}
36
+
37
+ clean_col_name(" Nom_FR ")
38
+ # 'nom fr'
39
+ ```
40
+
41
+ With pandas:
42
+
43
+ ```python
44
+ import pandas as pd
45
+ from smartcolumns import detect_columns
46
+
47
+ df = pd.read_csv("results.csv")
48
+ cols = detect_columns(df.columns)
49
+ df = df.rename(columns={v: k for k, v in cols.items()})
50
+ ```
51
+
52
+ ## Canonical names
53
+
54
+ `student_id`, `name_fr`, `name_ar`, `score`, `decision`, `wilaya_fr`, `wilaya_ar`, `school`, `series`, `birth_date`, `birth_place_fr`, `birth_place_ar`. The keyword lists are in `smartcolumns.COLUMN_PATTERNS`.
55
+
56
+ Matching is by keyword: the first column whose cleaned name contains a keyword wins. Short keywords like `id` can match inside longer names, so check the result on unusual files.
57
+
58
+ ## Tests
59
+
60
+ ```bash
61
+ python -m unittest discover tests
62
+ ```
63
+
64
+ ## License
65
+
66
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ smartcolumns/__init__.py
5
+ smartcolumns.egg-info/PKG-INFO
6
+ smartcolumns.egg-info/SOURCES.txt
7
+ smartcolumns.egg-info/dependency_links.txt
8
+ smartcolumns.egg-info/top_level.txt
9
+ tests/test_smartcolumns.py
@@ -0,0 +1 @@
1
+ smartcolumns
@@ -0,0 +1,36 @@
1
+ import unittest
2
+
3
+ from smartcolumns import clean_col_name, detect_columns
4
+
5
+
6
+ class CleanColNameTests(unittest.TestCase):
7
+ def test_lowercases_trims_and_replaces_underscores(self):
8
+ self.assertEqual(clean_col_name(" Nom_FR "), "nom fr")
9
+
10
+ def test_collapses_repeated_whitespace(self):
11
+ self.assertEqual(clean_col_name("Moy Bac"), "moy bac")
12
+
13
+ def test_accepts_non_string_values(self):
14
+ self.assertEqual(clean_col_name(2024), "2024")
15
+
16
+
17
+ class DetectColumnsTests(unittest.TestCase):
18
+ def test_detects_score_and_decision_columns(self):
19
+ found = detect_columns(["Nom_FR", "Moy Bac", "Decision"])
20
+ self.assertEqual(found["name_fr"], "Nom_FR")
21
+ self.assertEqual(found["score"], "Moy Bac")
22
+ self.assertEqual(found["decision"], "Decision")
23
+
24
+ def test_detects_arabic_name_column(self):
25
+ found = detect_columns(["الاسم الكامل"])
26
+ self.assertEqual(found["name_ar"], "الاسم الكامل")
27
+
28
+ def test_unrelated_columns_are_ignored(self):
29
+ self.assertEqual(detect_columns(["foo", "bar"]), {})
30
+
31
+ def test_empty_input(self):
32
+ self.assertEqual(detect_columns([]), {})
33
+
34
+
35
+ if __name__ == "__main__":
36
+ unittest.main()