codec-bridge 0.2.3__tar.gz → 0.2.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codec_bridge
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: Detect encoding from CSV files and return the accepted case format for analytical tools (currently supports DuckDB)
5
5
  Home-page: https://github.com/jpferraz-git/codec_bridge
6
6
  Author: João Pedro Ferraz Bezerra
@@ -1,9 +1,11 @@
1
1
  import charset_normalizer
2
2
  import os
3
3
  import re
4
+ import logging
4
5
 
5
6
  from codec_bridge.repository.python_to_duckdb import PYTHON_TO_DUCKDB_ENCODING, ENCODINGS_UNDERSCORE_CONFLICT
6
7
 
8
+ logger = logging.getLogger(__name__)
7
9
  def get_duckdb_encoding(python_encoding_name: str) -> str:
8
10
  """
9
11
  Translates a Python-standard encoding name to the name expected by DuckDB.
@@ -13,10 +15,19 @@ def get_duckdb_encoding(python_encoding_name: str) -> str:
13
15
  :return: The translated encoding name for DuckDB (e.g., 'ibm-819').
14
16
  """
15
17
  if not python_encoding_name:
16
- return 'utf-8'
18
+ return "utf-8"
17
19
 
18
- normalized_name = python_encoding_name.lower()
19
- return PYTHON_TO_DUCKDB_ENCODING.get(normalized_name, python_encoding_name)
20
+ normalized = python_encoding_name.lower()
21
+
22
+ duckdb_encoding = PYTHON_TO_DUCKDB_ENCODING.get(normalized)
23
+
24
+ if duckdb_encoding is None:
25
+ logger.warning(
26
+ f"Encoding {python_encoding_name} not mapped yet, falling back to utf-8"
27
+ )
28
+ return "utf-8"
29
+
30
+ return duckdb_encoding
20
31
 
21
32
 
22
33
  def detect_encoding(file_path: str, chunk: int = 1000000) -> str:
@@ -51,7 +62,7 @@ def detect_delimiter(file_path: str, encoding: str = "utf-8") -> str:
51
62
  if any(c > 0 for c in counts.values()):
52
63
  detected_delimiter = max(counts, key=counts.get)
53
64
  except Exception as e:
54
- print(f"[WARN] Could not detect delimiter for {os.path.basename(file_path)}: {e}")
65
+ logger.warning(f" Could not detect delimiter for {os.path.basename(file_path)}: {e}")
55
66
 
56
67
  return detected_delimiter
57
68
 
@@ -65,7 +76,7 @@ def process_files(directory_path: str) -> list[dict]:
65
76
  :return: A list of dictionaries, each containing metadata for a file.
66
77
  """
67
78
  if not os.path.isdir(directory_path):
68
- print(f"Error: The directory '{directory_path}' does not exist.")
79
+ logger.warning(f"Error: The directory '{directory_path}' does not exist.")
69
80
  return []
70
81
 
71
82
  results = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codec_bridge
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: Detect encoding from CSV files and return the accepted case format for analytical tools (currently supports DuckDB)
5
5
  Home-page: https://github.com/jpferraz-git/codec_bridge
6
6
  Author: João Pedro Ferraz Bezerra
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codec_bridge"
3
- version = "0.2.3"
3
+ version = "0.2.4"
4
4
  description = "Detect encoding from CSV files and return the accepted case format for analytical tools (currently supports DuckDB)"
5
5
  authors = [
6
6
  { name = "João Pedro Ferraz Bezerra", email = "jpferraz554@gmail.com" }
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='codec_bridge',
5
- version='0.2.3',
5
+ version='0.2.4',
6
6
  packages=find_packages(),
7
7
  description='Encoding and case normalization bridge for DuckDB and other engines',
8
8
  long_description=open('README.md', encoding='utf-8').read(),
File without changes
File without changes
File without changes