Skip to content
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

np.fromfile() raises non-helpful error when reading non-numerical text #12426

Open
Doom312 opened this issue Nov 20, 2018 · 5 comments
Open

np.fromfile() raises non-helpful error when reading non-numerical text #12426

Doom312 opened this issue Nov 20, 2018 · 5 comments

Comments

@Doom312
Copy link

Doom312 commented Nov 20, 2018

When I try to read strings from file to numpy array Python crashes.

Reproducing code example:

import sys
print(sys.platform)
print(sys.version)

import numpy as np
print(np.version.full_version)

np.fromfile('data\\foo.txt', dtype='str')
win32
3.7.1 (default, Oct 28 2018, 08:39:03) [MSC v.1912 64 bit (AMD64)]
1.15.4

The file contains:

[data\foo.txt content -- this line is not there]
dsadas
asdasdads
asdasda
dasdasda

Error message:

There is no error message just the Python has stopped working window:
image


Summary by @seberg:

As noted below, this is now working, but gives a strange ValueError(for 'S' dtype without a size).

@charris
Copy link
Member

charris commented Nov 20, 2018

Is this problem new in Python 3.7.1?

@mattip
Copy link
Member

mattip commented Nov 20, 2018

Strange no-one hit this before. Using np.fromfile with

  • a dtype with variable itemsize (str, unicode, void) and
  • not specifying count

does not work, it passes -1 to PyArray_NewFromDescr_int. However it should raise an error, not crash the interpreter.

Where did you get numpy? Are you running python inside an IDE or jupyter, or directly from the command line?

@mattip
Copy link
Member

mattip commented Nov 20, 2018

Does

with open('data\\foo.txt', 'rt') as fid:
    for line in fid:
        print line

print the file contents?

@cgohlke
Copy link
Contributor

cgohlke commented Nov 21, 2018

I think this is fixed by #12354. The crash is due to a DECREF on a NULL at https://github.com/numpy/numpy/blob/maintenance/1.15.x/numpy/core/src/multiarray/multiarraymodule.c#L2178

@mattip
Copy link
Member

mattip commented Jan 13, 2019

While this no longer crashes, it raises ValueError: negative dimensions are not allowed. np.loadtxt with no dtype is no better, it returns an uninitialized float64 ndarray.

@mattip mattip changed the title np.fromfile() kills kernel on Windows 10 np.fromfile() raises non-helpful error when reading non-numerical text Jan 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants