davlee1972 opened a new issue, #43858:
URL: https://github.com/apache/arrow/issues/43858

   ### Describe the enhancement requested
   
   https://github.com/apache/arrow/blob/main/python/pyarrow/types.pxi
   
   Can we add more aliases?
   
   I added some additional ones on my own, but it would be nice if we can make 
these standard?
   
   ```
   "binary" to pa.binary()
   "fixed_sized_binary[?]" to pa.binary(?)
   "decimal128[?]" or "decimal128[?,?]" to pa.decimal128(?) or 
pa.decimal128(?,?)
   "decimal256[?]" or "decimal256[?,?]" to pa.decimal256(?) or 
pa.decimal256(?,?)
   "decimal[?]" or "decimal[?,?]" to pa.decimal256() if precision is > 38
   "decimal[?]" or "decimal[?,?]" to pa.decimal128() if precision is <= 38
   "timestamp" to pa.timestamp('us')
   "date" to pa.date32()
   "int" to pa.int32()
   ```
   
   ```
               if obj.startswith("binary") or 
obj.startswith("fixed_size_binary"):
                   res = re.search(r"\[.*?\]", obj)
                   if res:
                       length = int(res.group()[1:-1])
                       obj = pa.binary(length)
                   else:
                       obj = pa.binary()
               elif obj.startswith("decimal"):
                   res = re.search(r"\[.*?\]", obj)
                   scale_precision = []
                   if res:
                       scale_precision = [int(i) for i in 
res.group()[1:-1].split(",")]
   
                   if obj.startswith("decimal256"):
                       dec_func = pa.decimal256
                   elif obj.startswith("decimal128"):
                       dec_func = pa.decimal128
                   elif obj.startswith("decimal")
                       if scale_precision[0] > 38:
                           dec_func = pa.decimal256
                       else:
                           dec_func = pa.decimal128
   
                   if len(scale_precision) == 1:
                       obj = dec_func(scale_precision[0])
                   elif len(scale_precision) == 2:
                       obj = dec_func(scale_precision[0], scale_precision[1])
               else:
                   if obj == "timestamp":
                       # default timestamp to microsecond precision
                       obj = "timestamp[us]"
                   elif obj == "date":
                       # default date to date32 which is an alias for 
date32[day]
                       obj = "date32"
                   elif obj == "int":
                       # default int to int32
                       obj = "int32"
                   obj = pa.type_for_alias(obj)
               return obj
   ```
   
   
   
   ### Component(s)
   
   C++, Python


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to