datafort_boolean_indexing Module

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.

Features

  • Boolean masks: Create and manipulate logical masks
  • Comparison operators: gt, lt, ge, le, eq, ne for real, integer, and character columns
  • Logical operators: AND, OR, NOT operations on masks
  • DataFrame filtering: Apply masks to filter data frames (df[mask] style)

Example Usage

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)


Derived Types

type, public ::  boolean_mask

Boolean mask type for storing logical arrays

Read more…

Components

Type Visibility Attributes Name Initial
logical, private :: initialized = .false.
logical, private, dimension(:), allocatable :: mask
integer, private :: size = 0

Type-Bound Procedures

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

Functions

public function contains_character(df, col, substring) result(mask)

Contains substring comparison for character columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
character(len=*), intent(in) :: substring

Return Value type(boolean_mask)

public function df_filter(df, mask) result(filtered_df)

Filter data frame using a boolean mask (pandas-like df[mask] operation)

Read more…

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
type(boolean_mask), intent(in) :: mask

Return Value type(data_frame)

public function eq_character(df, col, value) result(mask)

Equality comparison for character columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
character(len=*), intent(in) :: value

Return Value type(boolean_mask)

public function eq_integer(df, col, value) result(mask)

Equality comparison for integer columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
integer(kind=ik), intent(in) :: value

Return Value type(boolean_mask)

public function eq_real(df, col, value) result(mask)

Equality comparison for real columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
real(kind=rk), intent(in) :: value

Return Value type(boolean_mask)

public function ge_integer(df, col, value) result(mask)

Greater than or equal comparison for integer columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
integer(kind=ik), intent(in) :: value

Return Value type(boolean_mask)

public function ge_real(df, col, value) result(mask)

Greater than or equal comparison for real columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
real(kind=rk), intent(in) :: value

Return Value type(boolean_mask)

private function get_column_index(df, col) result(col_index)

Get column index from either integer or character input

Read more…

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col

Return Value integer

public function gt_integer(df, col, value) result(mask)

Greater than comparison for integer columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
integer(kind=ik), intent(in) :: value

Return Value type(boolean_mask)

public function gt_real(df, col, value) result(mask)

Greater than comparison for real columns

Read more…

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
real(kind=rk), intent(in) :: value

Return Value type(boolean_mask)

public function le_integer(df, col, value) result(mask)

Less than or equal comparison for integer columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
integer(kind=ik), intent(in) :: value

Return Value type(boolean_mask)

public function le_real(df, col, value) result(mask)

Less than or equal comparison for real columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
real(kind=rk), intent(in) :: value

Return Value type(boolean_mask)

public function lt_integer(df, col, value) result(mask)

Less than comparison for integer columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
integer(kind=ik), intent(in) :: value

Return Value type(boolean_mask)

public function lt_real(df, col, value) result(mask)

Less than comparison for real columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
real(kind=rk), intent(in) :: value

Return Value type(boolean_mask)

public function mask_and(mask1, mask2) result(result_mask)

Logical AND operation on two masks

Read more…

Arguments

Type IntentOptional Attributes Name
type(boolean_mask), intent(in) :: mask1
type(boolean_mask), intent(in) :: mask2

Return Value type(boolean_mask)

private function mask_get(this) result(logical_array)

Get the logical array from the mask

Read more…

Arguments

Type IntentOptional Attributes Name
class(boolean_mask), intent(in) :: this

Return Value logical, dimension(:), allocatable

private pure function mask_get_size(this) result(size)

Get the size of the mask

Read more…

Arguments

Type IntentOptional Attributes Name
class(boolean_mask), intent(in) :: this

Return Value integer

private pure function mask_is_initialized(this) result(is_init)

Check if mask is initialized

Read more…

Arguments

Type IntentOptional Attributes Name
class(boolean_mask), intent(in) :: this

Return Value logical

public function mask_not(mask) result(result_mask)

Logical NOT operation on a mask

Read more…

Arguments

Type IntentOptional Attributes Name
type(boolean_mask), intent(in) :: mask

Return Value type(boolean_mask)

public function mask_or(mask1, mask2) result(result_mask)

Logical OR operation on two masks

Read more…

Arguments

Type IntentOptional Attributes Name
type(boolean_mask), intent(in) :: mask1
type(boolean_mask), intent(in) :: mask2

Return Value type(boolean_mask)

public function ne_character(df, col, value) result(mask)

Not equal comparison for character columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
character(len=*), intent(in) :: value

Return Value type(boolean_mask)

public function ne_integer(df, col, value) result(mask)

Not equal comparison for integer columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
integer(kind=ik), intent(in) :: value

Return Value type(boolean_mask)

public function ne_real(df, col, value) result(mask)

Not equal comparison for real columns

Arguments

Type IntentOptional Attributes Name
type(data_frame), intent(in) :: df
class(*), intent(in) :: col
real(kind=rk), intent(in) :: value

Return Value type(boolean_mask)


Subroutines

private subroutine mask_constructor(this, logical_array)

Initialize a boolean mask from a logical array

Read more…

Arguments

Type IntentOptional Attributes Name
class(boolean_mask), intent(inout) :: this
logical, intent(in), dimension(:) :: logical_array

private subroutine mask_destructor(this)

Destroy a boolean mask and free memory

Read more…

Arguments

Type IntentOptional Attributes Name
class(boolean_mask), intent(inout) :: this