tabular-reader 0.1.0__tar.gz → 0.1.1__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.
- {tabular_reader-0.1.0 → tabular_reader-0.1.1}/PKG-INFO +2 -1
- {tabular_reader-0.1.0 → tabular_reader-0.1.1}/pyproject.toml +2 -1
- {tabular_reader-0.1.0 → tabular_reader-0.1.1}/tabular_reader/__init__.py +1 -1
- {tabular_reader-0.1.0 → tabular_reader-0.1.1}/tabular_reader/reader.py +21 -3
- {tabular_reader-0.1.0 → tabular_reader-0.1.1}/LICENSE +0 -0
- {tabular_reader-0.1.0 → tabular_reader-0.1.1}/README.org +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tabular-reader
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: Read XLSX, XLS and CSV files with a uniform interface Read XLSX, XLS and CSV files with a uniform interface
|
|
5
5
|
License: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -22,6 +22,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
22
22
|
Classifier: Programming Language :: Python :: 3.13
|
|
23
23
|
Classifier: Programming Language :: Python :: 3.14
|
|
24
24
|
Requires-Dist: openpyxl (>=3.0,<3.1)
|
|
25
|
+
Requires-Dist: xlrd (>=2.0,<3.0)
|
|
25
26
|
Project-URL: Repository, https://github.com/arkhan/tabular-reader
|
|
26
27
|
Description-Content-Type: text/plain
|
|
27
28
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "tabular-reader"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.1"
|
|
4
4
|
description = "Read XLSX, XLS and CSV files with a uniform interface Read XLSX, XLS and CSV files with a uniform interface"
|
|
5
5
|
authors = ["arkhan <arkhan@riseup.net>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -26,6 +26,7 @@ classifiers = [
|
|
|
26
26
|
[tool.poetry.dependencies]
|
|
27
27
|
python = "^3.6"
|
|
28
28
|
openpyxl = ">=3.0,<3.1"
|
|
29
|
+
xlrd = ">=2.0,<3.0"
|
|
29
30
|
|
|
30
31
|
[tool.poetry.group.dev.dependencies]
|
|
31
32
|
pytest = "^6.2"
|
|
@@ -3,8 +3,6 @@ import csv
|
|
|
3
3
|
import os
|
|
4
4
|
from types import SimpleNamespace
|
|
5
5
|
|
|
6
|
-
from openpyxl import load_workbook
|
|
7
|
-
|
|
8
6
|
|
|
9
7
|
def get_file_format(filename):
|
|
10
8
|
_, ext = os.path.splitext(filename)
|
|
@@ -28,7 +26,25 @@ def read_csv(filename, **kwargs):
|
|
|
28
26
|
]
|
|
29
27
|
|
|
30
28
|
|
|
29
|
+
def read_xls(filename, worksheet="", **kwargs):
|
|
30
|
+
import xlrd
|
|
31
|
+
|
|
32
|
+
wb = xlrd.open_workbook(filename)
|
|
33
|
+
ws = wb.sheet_by_name(worksheet) if worksheet else wb.sheet_by_index(0)
|
|
34
|
+
|
|
35
|
+
total = [[cell.value for cell in row] for row in ws.get_rows()]
|
|
36
|
+
header = total[0] if total else []
|
|
37
|
+
filtered_indices = [
|
|
38
|
+
i for i, val in enumerate(header) if val is not None and str(val).strip() != ""
|
|
39
|
+
]
|
|
40
|
+
return [
|
|
41
|
+
[row[i] if i < len(row) else None for i in filtered_indices] for row in total
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
|
|
31
45
|
def read_xlsx(filename, worksheet="", **kwargs):
|
|
46
|
+
from openpyxl import load_workbook
|
|
47
|
+
|
|
32
48
|
excel_kwargs = {
|
|
33
49
|
k: v for k, v in kwargs.items() if k not in ["delimiter", "encoding"]
|
|
34
50
|
}
|
|
@@ -61,8 +77,10 @@ class TabularReader:
|
|
|
61
77
|
|
|
62
78
|
if file_format == "csv":
|
|
63
79
|
filtered_data = read_csv(filename, **kwargs)
|
|
64
|
-
elif file_format
|
|
80
|
+
elif file_format == "xlsx":
|
|
65
81
|
filtered_data = read_xlsx(filename, worksheet, **kwargs)
|
|
82
|
+
elif file_format == "xls":
|
|
83
|
+
filtered_data = read_xls(filename, worksheet, **kwargs)
|
|
66
84
|
else:
|
|
67
85
|
raise ValueError(f"Unsupported format: {file_format}")
|
|
68
86
|
|
|
File without changes
|
|
File without changes
|