Skip to content

numpy float multiplied by a string does not raise a TypeError #5919

Closed

Description

@ngoldbaum

This illustrates the issue:

>>> import numpy as np 
>>> print 'x'*np.float64(3.5)

The same construction using a regular python float raises a TypeError, as I would expect:

>>> 'x'*3.5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'float'

I haven't looked very closely at the implementation of the numpy float class. Please feel free to close this issue if this is working as expected.

This is on numpy 1.9.2 and python 2.7.9

Activity

  1. njsmith commented on May 27, 2015

    @njsmith
    Member
    In [1]: import warnings
    
    In [2]: warnings.simplefilter("always")
    
    In [3]: "x" * np.float64(3.5)
    /home/njs/.user-python2.7-64bit-3/bin/ipython:1: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
      #!/home/njs/.user-python2.7-64bit-3/bin/python
    Out[3]: 'xxx'
    

    We really need to do something about DeprecationWarnings not showing up interactively, it bites people constantly :-/

  2. njsmith commented on May 27, 2015

    @njsmith
    Member

    (Closing b/c there should be an issue for turning that DeprecationWarning into an error at some point... though I haven't double-checked :-))

  3. ngoldbaum commented on May 27, 2015

    @ngoldbaum
    MemberAuthor

    I agree that the way DeprecationWarning is hidden by default makes it pretty much useless. Thanks for clearing that up!

  4. jakirkham commented on Feb 3, 2016

    @jakirkham
    Contributor

    Interesting coming across this today. Yeah, I think I agree. Did an issue ever get opened or confirmed for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions