DataFort Boolean Indexing Module
This module provides pandas-like boolean indexing/masking functionality. It allows filtering data frames using logical masks created from comparison operations and combined with logical operators.
use datafort
use datafort_boolean_indexing
type(data_frame) :: df, filtered
type(boolean_mask) :: mask1, mask2, combined
! Create masks using comparison operators
mask1 = gt_real(df, "temperature", 25.0_rk)
mask2 = lt_real(df, "humidity", 60.0_rk)
! Combine masks with logical operators
combined = mask_and(mask1, mask2)
! Filter dataframe
filtered = df_filter(df, combined)
Boolean mask type for storing logical arrays
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
logical, | private | :: | initialized | = | .false. | ||
logical, | private, | dimension(:), allocatable | :: | mask | |||
integer, | private | :: | size | = | 0 |
procedure, public :: destroy => mask_destructor | |
procedure, public :: get_mask => mask_get | |
procedure, public :: get_size => mask_get_size | |
procedure, public :: is_initialized => mask_is_initialized | |
procedure, public :: new => mask_constructor |
Contains substring comparison for character columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
character(len=*), | intent(in) | :: | substring |
Filter data frame using a boolean mask (pandas-like df[mask] operation)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
type(boolean_mask), | intent(in) | :: | mask |
Equality comparison for character columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
character(len=*), | intent(in) | :: | value |
Equality comparison for integer columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
integer(kind=ik), | intent(in) | :: | value |
Equality comparison for real columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
real(kind=rk), | intent(in) | :: | value |
Greater than or equal comparison for integer columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
integer(kind=ik), | intent(in) | :: | value |
Greater than or equal comparison for real columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
real(kind=rk), | intent(in) | :: | value |
Get column index from either integer or character input
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col |
Greater than comparison for integer columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
integer(kind=ik), | intent(in) | :: | value |
Greater than comparison for real columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
real(kind=rk), | intent(in) | :: | value |
Less than or equal comparison for integer columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
integer(kind=ik), | intent(in) | :: | value |
Less than or equal comparison for real columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
real(kind=rk), | intent(in) | :: | value |
Less than comparison for integer columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
integer(kind=ik), | intent(in) | :: | value |
Less than comparison for real columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
real(kind=rk), | intent(in) | :: | value |
Logical AND operation on two masks
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(boolean_mask), | intent(in) | :: | mask1 | |||
type(boolean_mask), | intent(in) | :: | mask2 |
Get the logical array from the mask
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(boolean_mask), | intent(in) | :: | this |
Get the size of the mask
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(boolean_mask), | intent(in) | :: | this |
Check if mask is initialized
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(boolean_mask), | intent(in) | :: | this |
Logical NOT operation on a mask
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(boolean_mask), | intent(in) | :: | mask |
Logical OR operation on two masks
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(boolean_mask), | intent(in) | :: | mask1 | |||
type(boolean_mask), | intent(in) | :: | mask2 |
Not equal comparison for character columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
character(len=*), | intent(in) | :: | value |
Not equal comparison for integer columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
integer(kind=ik), | intent(in) | :: | value |
Not equal comparison for real columns
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(data_frame), | intent(in) | :: | df | |||
class(*), | intent(in) | :: | col | |||
real(kind=rk), | intent(in) | :: | value |
Initialize a boolean mask from a logical array
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(boolean_mask), | intent(inout) | :: | this | |||
logical, | intent(in), | dimension(:) | :: | logical_array |
Destroy a boolean mask and free memory
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(boolean_mask), | intent(inout) | :: | this |