pitrou commented on a change in pull request #7614:
URL: https://github.com/apache/arrow/pull/7614#discussion_r449080783



##########
File path: r/src/array_from_vector.cpp
##########
@@ -351,15 +351,20 @@ std::shared_ptr<Array> 
MakeFactorArrayImpl(Rcpp::IntegerVector_ factor,
 
 std::shared_ptr<Array> MakeFactorArray(Rcpp::IntegerVector_ factor,
                                        const std::shared_ptr<arrow::DataType>& 
type) {
-  SEXP levels = factor.attr("levels");
-  int n = Rf_length(levels);
-  if (n < 128) {
+  auto* dict_type = checked_cast<arrow::DictionaryType*>(type.get());
+  auto index_type = dict_type->index_type();
+  if (index_type->Equals(int8())) {

Review comment:
       Faster if written as `index_type->id() == Type::INT8`. You may or may 
not bother, depending on how important this function is.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to