Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-9451

[Python] Unsigned integer types will accept string values in pyarrow.array

Details

    Description

      See

      In [12]: pa.array(['5'], type='uint32')                                                                                                                                                   
      Out[12]: 
      <pyarrow.lib.UInt32Array object at 0x7fabbdb1edc8>
      [
        5
      ]
      

      Also:

      In [9]: pa.scalar('5', type='uint8')                                                                                                                                                      
      Out[9]: <pyarrow.UInt8Scalar: 5>
      
      In [10]: pa.scalar('5', type='uint16')                                                                                                                                                    
      Out[10]: <pyarrow.UInt16Scalar: 5>
      
      In [11]: pa.scalar('5', type='uint32')                                                                                                                                                    
      Out[11]: <pyarrow.UInt32Scalar: 5>
      

      But:

      In [13]: pa.array(['5'], type='int32')                                                                                                                                                    
      ---------------------------------------------------------------------------
      TypeError                                 Traceback (most recent call last)
      <ipython-input-13-48092f69d948> in <module>
      ----> 1 pa.array(['5'], type='int32')
      
      ~/code/arrow/python/pyarrow/array.pxi in pyarrow.lib.array()
          267     else:
          268         # ConvertPySequence does strict conversion if type is explicitly passed
      --> 269         return _sequence_to_array(obj, mask, size, type, pool, c_from_pandas)
          270 
          271 
      
      ~/code/arrow/python/pyarrow/array.pxi in pyarrow.lib._sequence_to_array()
           36 
           37     with nogil:
      ---> 38         check_status(ConvertPySequence(sequence, mask, options, &out))
           39 
           40     if out.get().num_chunks() == 1:
      
      TypeError: an integer is required (got type str)
      

      Attachments

        Issue Links

          Activity

            People

              apitrou Antoine Pitrou
              wesm Wes McKinney
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h

                  Slack

                    Issue deployment