okadakk commented on a change in pull request #11167:
URL: https://github.com/apache/arrow/pull/11167#discussion_r710873328



##########
File path: ruby/red-arrow/lib/arrow/table.rb
##########
@@ -261,12 +261,35 @@ def slice(*args)
         expected_n_args = nil
         case args.size
         when 1
-          if args[0].is_a?(Integer)
+          case args[0]
+          when Integer
             index = args[0]
             index += n_rows if index < 0
             return nil if index < 0
             return nil if index >= n_rows
             return Record.new(self, index)
+          when Hash
+            hash = args[0]
+            if hash.size != 1
+              message = "wrong number of hash size (given #{hash.size}, 
expected 1)"
+              raise ArgumentError, message
+            end
+
+            key = hash.keys[0]
+            value = hash.values[0]
+            case value
+            when Integer, String, TrueClass, FalseClass
+              slicers << (Slicer.new(self).send(key) == value)
+            when Range
+              if value.end == nil
+                slicers << (Slicer.new(self).send(key) >= value.first)
+              else
+                slicers << (Slicer.new(self).send(key) <= value.last)
+              end
+            else
+              message = "hash value must be Integer, String, TrueClass, 
FalseClass, Range"
+              raise ArgumentError, message  
+            end

Review comment:
       memo 
   
   If Range Object is endless, 
   Range.last occur error (cannot get the last element of endless range), 
   but Range.end return nil.
   
   

##########
File path: ruby/red-arrow/lib/arrow/table.rb
##########
@@ -261,12 +261,35 @@ def slice(*args)
         expected_n_args = nil
         case args.size
         when 1
-          if args[0].is_a?(Integer)
+          case args[0]
+          when Integer
             index = args[0]
             index += n_rows if index < 0
             return nil if index < 0
             return nil if index >= n_rows
             return Record.new(self, index)
+          when Hash
+            hash = args[0]
+            if hash.size != 1
+              message = "wrong number of hash size (given #{hash.size}, 
expected 1)"
+              raise ArgumentError, message
+            end
+
+            key = hash.keys[0]
+            value = hash.values[0]
+            case value
+            when Integer, String, TrueClass, FalseClass
+              slicers << (Slicer.new(self).send(key) == value)
+            when Range
+              if value.end == nil
+                slicers << (Slicer.new(self).send(key) >= value.first)
+              else
+                slicers << (Slicer.new(self).send(key) <= value.last)
+              end
+            else
+              message = "hash value must be Integer, String, TrueClass, 
FalseClass, Range"
+              raise ArgumentError, message  
+            end

Review comment:
       memo 
   
   If Range Object is endless, 
   Range.last occur error (cannot get the last element of endless range), 
   But Range.end return nil.
   
   




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