wjones127 commented on PR #12751:
URL: https://github.com/apache/arrow/pull/12751#issuecomment-1096915372

   Errors now show `cbind()` or `rbind()` as calls instead of showing internal 
helper functions.
   ```r
   # Concatenating chunked arrays returns a new chunked array containing all 
chunks
   a <- chunked_array(c(1, 2), 3)
   b <- chunked_array(c(4, 5), 6)
   c(a, b)
   #> ChunkedArray
   #> [
   #>   [
   #>     1,
   #>     2
   #>   ],
   #>   [
   #>     3
   #>   ],
   #>   [
   #>     4,
   #>     5
   #>   ],
   #>   [
   #>     6
   #>   ]
   #> ]
   
   # RecordBatch doesn't support rbind
   rbind(
     RecordBatch$create(a = 1:10),
     RecordBatch$create(a = 2:4)
   )
   #> Error in `rbind()`:
   #> ! Use `Table$create()` to combine record batches
   
   # Array no longer supports c()
   a <- Array$create(c(1, 2))
   b <- Array$create(c(4, 5))
   c(a, b)
   #> Error in `c()`:
   #> ! Use `concat_arrays()` or `ChunkedArray$create()` instead.
   #> ℹ `concat_arrays()` creates a new Array by copying data.
   #> ℹ `ChunkedArray$create()` uses the arrays as chunks for zero-copy 
concatenation.
   
   # cbind() for Recordbatch handles a variety of input types
   cbind(
     record_batch(a = 1:2),
     record_batch(b = 4:5)
   )
   #> RecordBatch
   #> 2 rows x 2 columns
   #> $a <int32>
   #> $b <int32>
   
   cbind(
     record_batch(a = 1:2),
     data.frame(b = 4:5)
   )
   #> RecordBatch
   #> 2 rows x 2 columns
   #> $a <int32>
   #> $b <int32>
   
   cbind(
     record_batch(a = 1:2),
     b = Array$create(4:5)
   )
   #> RecordBatch
   #> 2 rows x 2 columns
   #> $a <int32>
   #> $b <int32>
   
   # ...with nice errors for invalid arguments
   cbind(
     record_batch(a = 1:2),
     b = Array$create(4:6)
   )
   #> Error in `cbind()`:
   #> ! Non-scalar inputs must have an equal number of rows.
   #> ℹ ..1 has 2, ..2 has 3
   
   cbind(
     record_batch(a = 1:2),
     b = c(1 + 4i, 2 + 3i)
   )
   #> Error in `cbind()`:
   #> ! Error occurred when trying to convert input ..b to an Arrow Array
   #> Caused by error:
   #> ! Cannot infer type from vector
   
   # And can make up names for vector input types
   
   cbind(
     record_batch(a = 1:2),
     b = Array$create(4:5),
     c("a", "b")
   )
   #> RecordBatch
   #> 2 rows x 3 columns
   #> $a <int32>
   #> $b <int32>
   #> $X.1 <string>
   
   # cbind() for Table works the same
   cbind(
     arrow_table(a = 1:2),
     arrow_table(b = 4:5)
   )
   #> Table
   #> 2 rows x 2 columns
   #> $a <int32>
   #> $b <int32>
   
   cbind(
     arrow_table(a = 1:2),
     data.frame(b = 4:5)
   )
   #> Table
   #> 2 rows x 2 columns
   #> $a <int32>
   #> $b <int32>
   
   cbind(
     arrow_table(a = 1:2),
     b = Array$create(4:5)
   )
   #> Table
   #> 2 rows x 2 columns
   #> $a <int32>
   #> $b <int32>
   
   # ...with nice errors for invalid arguments
   cbind(
     arrow_table(a = 1:2),
     b = Array$create(4:6)
   )
   #> Error in `cbind()`:
   #> ! Non-scalar inputs must have an equal number of rows.
   #> ℹ ..1 has 2, ..2 has 3
   
   cbind(
     arrow_table(a = 1:2),
     b = c(1 + 4i, 2 + 3i)
   )
   #> Error in `cbind()`:
   #> ! Error occurred when trying to convert input ..b to an Arrow Array
   #> Caused by error:
   #> ! Cannot infer type from vector
   
   # ...rbind works for Tables with a common schema
   rbind(
     arrow_table(a = 1:2),
     arrow_table(a = 3:4)
   )
   #> Table
   #> 4 rows x 1 columns
   #> $a <int32>
   
   # ...with nice errors for Tables with non-unifiable schemas 
   rbind(
     arrow_table(a = 1:2),
     arrow_table(b = 3:4)
   )
   #> Error in `rbind()`:
   #> ! Schema at index 2 does not match the first schema
   #> ℹ Schema 1:
   #> a: int32
   #> ℹ Schema 2:
   #> b: int32
   ```


-- 
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