Skip to content

Commit

Permalink
Add Series#none? (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
wagner authored Aug 8, 2023
1 parent 64e4faf commit 3904d41
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/polars/series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,18 @@ def all?(&block)
end
alias_method :all, :all?

# Check if all boolean values in the column are `false`.
#
# @return [Boolean]
def none?(&block)
if block_given?
apply(&block).none?
else
to_frame.select(Polars.col(name).is_not.all).to_series[0]
end
end
alias_method :none, :none?

# Compute the logarithm to a given base.
#
# @param base [Float]
Expand Down
7 changes: 7 additions & 0 deletions test/series_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ def test_all
assert Polars::Series.new([2, 4, 6]).all?(&:even?)
end

def test_none
assert Polars::Series.new([false, false, false]).none?
refute Polars::Series.new([false, true, false]).none?
assert Polars::Series.new([1, 3, 5]).none?(&:even?)
refute Polars::Series.new([2, 3, 5]).none?(&:even?)
end

def test_log
s = Polars::Series.new([1, 2, 4])
assert_series [0, 1, 2], s.log(2)
Expand Down

0 comments on commit 3904d41

Please sign in to comment.