1010from collections .abc import AsyncGenerator , Callable
1111from datetime import datetime
1212from pathlib import Path
13- from typing import ClassVar
1413
1514import chardet
1615import pandas as pd
1918from anyio import to_thread
2019from dbfread import DBF as DBFReader
2120from pydantic import Field , PrivateAttr
21+ from pyreaddbc import dbc2dbf
2222from pysus import CACHEPATH
2323from pysus .api .metadata .models import Column
2424from pysus .api .models import BaseCompressedFile , BaseLocalFile , BaseTabularFile
@@ -60,14 +60,6 @@ def _map_dtype(raw: str) -> str:
6060 return "VARCHAR"
6161
6262
63- try :
64- from pyreaddbc import dbc2dbf
65-
66- DBC_IMPORT = True
67- except ImportError :
68- DBC_IMPORT = False
69-
70-
7163class File (BaseLocalFile ):
7264 """Represents a generic local file with no special handling."""
7365
@@ -839,76 +831,6 @@ def _extract():
839831 return list (await asyncio .gather (* tasks ))
840832
841833
842- class DBCNotImported (BaseTabularFile ):
843- """Placeholder for DBC files when optional dependency is not installed."""
844-
845- path : Path = Field (default_factory = lambda : Path ("..." ))
846- type : str | FileType = Field (default = "remote" )
847- import_err : ClassVar [
848- str
849- ] = """
850- run "pip install pysus[dbc]" to handle DBC files.
851- Make sure you also have libffi installed on the system. It may not work
852- on Windows
853- """
854-
855- @property
856- def name (self ) -> str :
857- """Raise ImportError indicating the missing DBC dependency."""
858- raise ImportError (self .import_err )
859-
860- @property
861- def extension (self ) -> str :
862- """Return the .dbc extension."""
863- return ".dbc"
864-
865- @property
866- def size (self ) -> int :
867- """Raise ImportError indicating the missing DBC dependency."""
868- raise ImportError (self .import_err )
869-
870- @property
871- def modify (self ) -> datetime :
872- """Raise ImportError indicating the missing DBC dependency."""
873- raise ImportError (self .import_err )
874-
875- @property
876- def columns (self ) -> list ["Column" ]:
877- """Raise ImportError indicating the missing DBC dependency."""
878- raise ImportError (self .import_err )
879-
880- @property
881- def rows (self ) -> int :
882- """Raise ImportError indicating the missing DBC dependency."""
883- raise ImportError (self .import_err )
884-
885- async def load (self ) -> pd .DataFrame :
886- """Raise ImportError indicating the missing DBC dependency."""
887- raise ImportError (self .import_err )
888-
889- def stream (
890- self ,
891- chunk_size : int = 10000 ,
892- ) -> AsyncGenerator [pd .DataFrame , None ]:
893- """Raise ImportError indicating the missing DBC dependency."""
894-
895- async def _internal_gen ():
896- """Yield nothing; always raises ImportError."""
897- raise ImportError (self .import_err )
898- yield pd .DataFrame ()
899-
900- return _internal_gen ()
901-
902- async def to_parquet (
903- self ,
904- output_path : str | Path | None = None ,
905- chunk_size : int = 10000 ,
906- callback : Callable [[int , int ], None ] | None = None ,
907- ) -> Parquet :
908- """Raise ImportError indicating the missing DBC dependency."""
909- raise ImportError (self .import_err )
910-
911-
912834class ExtensionFactory :
913835 """Factory that maps file extensions and MIME types to handler classes."""
914836
@@ -930,7 +852,7 @@ class ExtensionFactory:
930852 ".csv" : CSV ,
931853 ".parquet" : Parquet ,
932854 ".dbf" : DBF ,
933- ".dbc" : DBC if DBC_IMPORT else DBCNotImported , # type: ignore
855+ ".dbc" : DBC ,
934856 ".pdf" : PDF ,
935857 ".json" : JSON ,
936858 }
0 commit comments