Skip to content

BUG: np.fromstring ignores invalid data. #6076

Closed

Description

@trendelkampschroer

I encountered strange behaviour of numpy.fromstring

import numpy as np

lines='1.0\n2.0\n3.0\n'
np.fromstring(lines, dtype=float, sep="\n")
array([ 1.,  2.,  3.])

np.fromstring(lines, dtype=int, sep="\n")
array([1])

Is this desired? To me it feels like this should raise an error.

Activity

  1. solarjoe commented on Jun 19, 2017

    @solarjoe
    Contributor

    The above still is broken.

    And I found another strange behaviour for numpy.fromstring (NumPy 1.10.4).

    import numpy as np
    np.fromstring('1.0, 2.0, 3.0\n', dtype=float, sep=",")
    >>> array([ 1.,  2.,  3.])
    
    np.fromstring('1.0, 2.0, 3.0,\n', dtype=float, sep=",")
    >>> array([ 1.,  2.,  3., -1.])

    If the string ends with a seperator and a line break, a -1.0 is inserted.

  2. ron819 commented on Nov 18, 2018

    @ron819

    any progress with fix for this?

  3. changed the title [-]numpy.fromstring behaviour[/-] [+]BUG: np.fromstring ignores invalid data.[/+] on May 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions