Git Product home page Git Product logo

Comments (8)

chriskuipers avatar chriskuipers commented on July 28, 2024 1

Had the same problem, but with an tailing . (dot). Modified parseN to also do a rstrip(b'.'). Works like a charm! Thanks

from dbfread.

olemb avatar olemb commented on July 28, 2024

It looks like there are two '*' characters at the end of each value. I first thought it might be padding, but '0.00**' and '**' are not the same length.

Could you try to open the file with raw=True and see what you get?

Here's a workaround that might work:

from dbfread import DBF, FieldParser

class AsteriskFieldParser(FieldParser):
    def parseN(self, field, value):
        value = value.strip().strip('*')
        return FieldParser.parseN(self, field, value)

f = DBF('test.dbf', load=True, encoding='latin1',
        parserclass=AsteriskFieldParser)

from dbfread.

sgiangola avatar sgiangola commented on July 28, 2024

Thanks for the help. My work around was editing the parseN function in field_parser. I added another replace() to account for the asterisks and replaced them with a 0, resulting in '0.000'. I also tried to replace the majority of the "0.00**" values in the actual dbf files. I realize this could cause problems if a value of "5**", for example, showed up but it appears to have been OK in my use case.

def parseN(self, field, data):
    """Parse numeric field (N)

    Returns int, float or None if the field is empty.
    """
    try:
        return int(data)
    except ValueError:
        if not data.strip():
            return None
        else:
            # Account for , in numeric fields
            return float(data.replace(b',', b'.').replace(b'**', b'0'))

from dbfread.

olemb avatar olemb commented on July 28, 2024

Why not simply remove the '*' characters? 0.000 is the same as 0.00 after all.

from dbfread.

Matungos avatar Matungos commented on July 28, 2024

I'm having this error:
in parseN
return float(data.replace(b',', b'.'))
ValueError: could not convert string to float: b'***********'

from dbfread.

olemb avatar olemb commented on July 28, 2024

I've added some code to remove the '*' characters in float fields. Could you try my develop branch and see if it works for you?

from dbfread.

Matungos avatar Matungos commented on July 28, 2024

In develop branch but adding the same line to parseN too works fine.
In my case the column with problems is a numeric field.

from dbfread.

olemb avatar olemb commented on July 28, 2024

Ah, sounds good. I've pushed a fix to my develop branch. Thanks for reporting this.

from dbfread.

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.