8000 ENH: Quoting support in np.genfromtxt(...) by ddasilva · Pull Request #4594 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Quoting support in np.genfromtxt(...) #4594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

ddasilva
Copy link
Contributor
@ddasilva ddasilva commented Apr 6, 2014

Based off patch in #2211. Implements custom split method and adds new keyword argument quoter= to np.genfromtxt. The quoting feature also supports escaping.

Example usage:

data.txt:

"King","Henry, VI"
"Queen","Victoria"
Sir,Isaac Newton

Python:

>>> np.genfromtxt("data.txt", quoter='"', delimiter=",", dtype="|S20")
array([[b'King', b'Henry, VI'],
       [b'Queen', b'Victoria'],
       [b'Sir', b'Isaac Newton']], 
      dtype='|S20')

Changes from original patch:

  • Python 3 compatibility:
    old code was iterating through bytes and not expecting int
  • Bugfix:
    old code was dropping final word in split implemention
  • Test:
    added a unit test

Based off patch in numpy#2211. Implements custom split method and adds keywd.
@juliantaylor
Copy link
Contributor

before adding more stuff to the text loading functions they should be fixed to work properly in python3 in total, see e.g. #4208 for loadtxt

@@ -207,6 +208,9 @@ def __init__(self, delimiter=None, comments=asbytes('#'), autostrip=True):
else:
(_handyman, delimiter) = (self._delimited_splitter, None)
self.delimiter = delimiter
if isinstance(quoter, unicode):
quoter = quoter.encode('ascii')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should no reason the quoter must be ascii, though to fix that probably the full machinery must be fixed to work properly with strings and not bytes

@charris
Copy link
Member
charris commented Jan 25, 2015

@ddasilva Are you still going to work on this?

8000

@ddasilva
Copy link
Contributor Author

@charris Unfortunately I don't have the time right now to come back to this. I'm closing this PR.

@ddasilva ddasilva closed this Jan 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0