Giter Site home page Giter Site logo

Comments (3)

RDWimmers avatar RDWimmers commented on June 2, 2024
import pygef

pygef.read_cpt("./KNM_GEF_stuk/S0270_35.gef")

> Traceback (most recent call last):
>   File "/home/robin/Documents/Repositories/pygef/venv/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3460, in run_code
>     exec(code_obj, self.user_global_ns, self.user_ns)
>   File "<ipython-input-3-4d7bdd2c1549>", line 3, in <module>
>     pygef.read_cpt("./KNM_GEF_stuk/S0270_35.gef")
>   File "/home/robin/Documents/Repositories/pygef/venv/lib/python3.9/site-packages/pygef/shim.py", line 82, in read_cpt
>     return gef_cpt_to_cpt_data(_GefCpt(path=file))
>   File "/home/robin/Documents/Repositories/pygef/venv/lib/python3.9/site-packages/pygef/gef/parse_cpt.py", line 134, in __init__
>     self.parse_data(
>   File "/home/robin/Documents/Repositories/pygef/venv/lib/python3.9/site-packages/pygef/gef/gef.py", line 151, in parse_data
>     return pl.read_csv(
>   File "/home/robin/Documents/Repositories/pygef/venv/lib/python3.9/site-packages/polars/io/csv/functions.py", line 354, in read_csv
>     df = pl.DataFrame._read_csv(
>   File "/home/robin/Documents/Repositories/pygef/venv/lib/python3.9/site-packages/polars/dataframe/frame.py", line 784, in _read_csv
>     self._df = PyDataFrame.read_csv(
> exceptions.ComputeError: projection index 1 is out of bounds for CSV schema with 1 columns

The #COLUMNSEPARATOR argument is not set in the GEF file. Therefore pyGEF assumes a space is used. Base on the GEF file a tab is used as separator.

import pygef

# Read in the file
with open('./KNM_GEF_stuk/S0270_35.gef', 'r') as file :
  filedata = file.read()

# Replace the target string
filedata = filedata.replace('\t', ' ')

# Write the file out again
with open('./KNM_GEF_stuk/S0270_35.gef', 'w') as file:
  file.write(filedata)

pygef.read_cpt("./KNM_GEF_stuk/S0270_35.gef")

Its nicer to provide a parsing error and not a polars error.

from pygef.

tlukkezen avatar tlukkezen commented on June 2, 2024

Yes, throwing a custom error would definitely be preferred, e.g. pygef.exceptions.ParseCptGefError

We could throw it if the inferred column-separator can not be found on every row in the CSV-data for the expected amount of times (= #columns - 1).

from pygef.

tlukkezen avatar tlukkezen commented on June 2, 2024

Linked to #367

from pygef.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.