Skip to content

Commit

Permalink
Added docs for DataType [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jan 22, 2024
1 parent 3448c46 commit 4e5b029
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
43 changes: 43 additions & 0 deletions lib/polars/data_types.rb
Original file line number Diff line number Diff line change
@@ -1,49 +1,92 @@
module Polars
# Base class for all Polars data types.
class DataType
# Return this DataType's fundamental/root type class.
#
# @return [Class]
#
# @example
# Polars::Datetime.new("ns").base_type
# # => Polars::Datetime
# @example
# Polars::List.new(Polars::Int32).base_type
# # => Polars::List
# @example
# Polars::Struct.new([Polars::Field.new("a", Polars::Int64), Polars::Field.new("b", Polars::Boolean)]).base_type
# # => Polars::Struct
def self.base_type
self
end

# Return this DataType's fundamental/root type class.
#
# @return [Class]
def base_type
is_a?(DataType) ? self.class : self
end

# Check if this DataType is the same as another DataType.
#
# @return [Boolean]
def self.==(other)
eql?(other) || other.is_a?(self)
end

# Check whether the data type is a numeric type.
#
# @return [Boolean]
def self.numeric?
self < NumericType
end

# Check whether the data type is a decimal type.
#
# @return [Boolean]
def self.decimal?
self == Decimal
end

# Check whether the data type is an integer type.
#
# @return [Boolean]
def self.integer?
# TODO Change to IntegerType in 0.9.0
self < IntegralType
end

# Check whether the data type is a signed integer type.
#
# @return [Boolean]
def self.signed_integer?
# TODO Add SignedIntegerType in 0.9.0
[Int8, Int16, Int32, Int64].include?(self)
end

# Check whether the data type is an unsigned integer type.
#
# @return [Boolean]
def self.unsigned_integer?
# TODO Add UnsignedIntegerType in 0.9.0
[UInt8, UInt16, UInt32, UInt64].include?(self)
end

# Check whether the data type is a float type.
#
# @return [Boolean]
def self.float?
self < FloatType
end

# Check whether the data type is a temporal type.
#
# @return [Boolean]
def self.temporal?
self < TemporalType
end

# Check whether the data type is a nested type.
#
# @return [Boolean]
def self.nested?
false
end
Expand Down
4 changes: 4 additions & 0 deletions test/docs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def test_data_frame
assert_docs Polars::DataFrame
end

def test_data_types
assert_docs Polars::DataType
end

def test_date_time_expr
assert_docs Polars::DateTimeExpr
end
Expand Down

0 comments on commit 4e5b029

Please sign in to comment.