From 37609ff230b9a0f07534a226029207da84c76b68 Mon Sep 17 00:00:00 2001 From: rabii-chaarani Date: Fri, 23 Aug 2024 15:57:27 +0930 Subject: [PATCH] fix: reads correctly input files --- .../__pycache__/__init__.cpython-311.pyc | Bin 355 -> 380 bytes .../__pycache__/_file_readers.cpython-311.pyc | Bin 10130 -> 10175 bytes .../file_readers/_file_readers.py | 18 +++++++++--------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/LoopDataConverter/__pycache__/__init__.cpython-311.pyc b/LoopDataConverter/__pycache__/__init__.cpython-311.pyc index 2d48b46fdcea95d12dd611b9af5348a098198e3f..24e0a20f64a55bd161a3f213675a6c7ec31d6819 100644 GIT binary patch delta 119 zcmaFN^oNOeIWI340}xzzcswm{BCjN)-b8hEmRzM3epV8DrrxPj^bR}vxz delta 95 zcmeyv^q7fvIWI340}!xGI+T_&kynyYYofaP#2_63##>y$rA1|_m41o2seYPl6KCj7 cJQc~s160ch#Kn%2bs6=f6)!MgK}8@V0q&9+LI3~& diff --git a/LoopDataConverter/file_readers/__pycache__/_file_readers.cpython-311.pyc b/LoopDataConverter/file_readers/__pycache__/_file_readers.cpython-311.pyc index 9006fa06708a602475eed5215bb17dbfc5c13628..41833f0fb17b086e1307ff3b4db1129a319f7469 100644 GIT binary patch delta 819 zcmZvWUr1AN6vuz(Zo9i~_ipZwZ8LS^HftLeJ~*>d2)E2>F15fUGWAZYp{qN6Fnx#= zdnr;+!XN^vFrg^p_V2;S9-AWB99}& zbwSV(YCk?d8%W#{vJCL}g*gRAxnC6rFyl-0M<~YonmH)LW;O;cyvI(0Uar$h40!Qo z!8B~a9@9A9(se;KYW1rSz~}l$P$y6G+X3qFiSPh6%VP!`z+Id*hVYfK#mI}QC@Zp2 zc0euar!<)392hE`hY-FgoP=h&aRpkj#O#GN{JL>3qPbphPcWi-lq7UvB5Lrp*0T7il7&w~jE_?k-}k5S%D0#Z{9Dzw^a7<1R#}(2r@G-BO{fQBjnamrF(( zB|p}0u<4{|uQ;Ui8nMJ)!7YuZtu+~I4F>HYHmKB#@PfT>E5~bEAV(A~H0I;7Dj)yD z60CGI8*)UY2`tbl8kQRIq@xFPn09zd^q(R3`)L6tm-teCSFcbv`bM1g9@w)cm;k1qJkOB*CDj36`&JLgJ1?O4_UTa(4mT~WVD6YiPTsXspQ(X9i(Ql&4h`T0@Y w(^b delta 715 zcmZXOUr19?9LLY^Zo9kpZg+E=?TPRUzu(i2sSfdu zC<;W=^3wBO>4CV;fC;}a=fR>zbx8mluIWF42Ok-xz>95cA5`EHI|hQf)0kqQ3K#eZ z2w|a%RN155whtsDAH@R>;mQ19R1Dl3$e6TN$QOBzJi1s3VNy8}Fz^1|$d&Uu< ztFn955y^W`_nZVCKYM~+Ug5^!1g}6Bk%e{fP%=4q;7qzRc1nq* zBC1q$K?e!E>)n7N^-8G?S`tQWguJ>)%ApyVOP$q9N}=ebD5Nk`_$i_kbsA(QWud+w zb7dhI!ct#nPw zarKzL46xSj#K}M_n{Oy%*jbD}1N*QsSh6iad*nxAsjH?K!hvAFt9+(AM+}DYe}LbE i^DvCFl}TXHBpuxzhWZ@&A2XJ3H2v}Css}Gi^}hguP{P>& diff --git a/LoopDataConverter/file_readers/_file_readers.py b/LoopDataConverter/file_readers/_file_readers.py index 7cbd0ab..fadfd98 100644 --- a/LoopDataConverter/file_readers/_file_readers.py +++ b/LoopDataConverter/file_readers/_file_readers.py @@ -6,6 +6,7 @@ import os import validators +#TODO: add a metaclass for methods that are repetitive class BaseFileReader(ABC): def __init__(self): @@ -77,16 +78,15 @@ def check_source_type(self, file_source: str): super().check_source_type(file_source) # TODO: add general check for variable types - def get_file(self, file_source: str, - layer: str = None): + def get_file(self, file_source: str, layer: str = None): file_extension = os.path.splitext(file_source)[1] if file_extension in [".shp", ".geojson"]: return geopandas.read_file(file_source) elif file_extension == ".gpkg": - assert layer is not None, "Layer name must be provided for GeoPackage files" - + assert layer is False, "Layer name must be provided for GeoPackage files" + return geopandas.read_file(file_source, layer=layer) else: @@ -107,14 +107,14 @@ def save(self, file_path: str, file_extension: str = None): raise ValueError(f"Unsupported file format: {file_extension}") @beartype.beartype - def read(self, file_source: str): + def read(self, file_source: str, layer: str = None): self.check_source_type(file_source) - self.file = self.get_file(file_source) + self.file = self.get_file(file_source, layer) self.data = geopandas.GeoDataFrame(self.file) class LoopGisReader: - def __init__(self, fileData, layer=None): + def __init__(self, fileData, layer=""): self._layer = layer self._fileData = fileData self._reader = [None] * len(Datatype) @@ -139,9 +139,9 @@ def assign_reader(self, file_source): def read(self, datatype: Datatype): self._reader[datatype] = self.assign_reader(self._fileData[datatype]) self.file_reader_label[datatype] = self._reader[datatype].type() - self._reader[datatype].get_file(self._fileData[datatype], self._layer) + self._reader[datatype].read(self._fileData[datatype], self._layer) - return self._reader.data + return self._reader[datatype].data def __call__(self): """