general-filter
GitHubGeneralFilter算子参考文档,说明如何通过Lambda函数组合规则对DataFrame进行行过滤。
Trigger Scenarios
Install
npx skills add OpenDCAI/DataFlow-WebUI --skill general-filter -g -y
SKILL.md
Frontmatter
{
"name": "general-filter",
"description": "Reference documentation for the GeneralFilter operator. Covers the constructor, rule-based filtering logic, and pipeline usage notes.\nUse when: filtering rows based on column value conditions that can be expressed as lambda functions without LLM calls."
}
GeneralFilter Operator Reference
GeneralFilter filters DataFrame rows using a custom rule list, combining all rules with AND. It does not add new columns — it only removes rows that do not satisfy all conditions.
1. Import
from dataflow.operators.core_text import GeneralFilter
2. Constructor
GeneralFilter(
filter_rules=[
lambda df: df["score"] >= 4,
lambda df: df["text"].str.len() > 10,
]
)
| Parameter | Required | Default | Description |
|---|---|---|---|
filter_rules |
Yes | None | List of rules; each rule is a callable with signature (df: DataFrame) -> Series[bool] |
Each rule returns a boolean Series the same length as the DataFrame; True means keep the row. Multiple rules are combined with AND.
3. run() Signature
op.run(
storage=self.storage.step(),
)
# returns: "" (empty string)
| Parameter | Required | Default | Description |
|---|---|---|---|
storage |
Yes | None | DataFlowStorage step object. The operator reads a DataFrame from here and writes the filtered DataFrame back. |
Note: run() has no input_key / output_key parameters. Column names referenced in rules are written directly in the lambda.
Return Value
The method returns "" (empty string).
4. Actual Runtime Logic
The source code behavior is:
- Read the DataFrame from
storage.read("dataframe"). - Initialize a boolean mask as
pd.Series(True, index=df.index). - For each rule in
filter_rules:- Validate the rule is callable.
- Call
cond = rule_fn(df). - Validate
condis a boolean Series. - Update mask:
mask &= cond.
- Filter the DataFrame:
filtered_df = df[mask]. - Write the filtered DataFrame back via
storage.write(filtered_df). - Return
"".
Key Behavior Notes
- Each rule must return a boolean
pd.Series; otherwise raisesValueError. - Columns referenced in rules must already exist in the current step's DataFrame.
- Only removes rows; adds no new columns.
- Multiple rules are combined with AND — only rows satisfying all conditions are kept.
5. Pipeline Usage Pattern
from dataflow.operators.core_text import GeneralFilter
from dataflow.utils.storage import FileStorage
class MyPipeline:
def __init__(self):
self.storage = FileStorage(
first_entry_file_name="./data/input.jsonl",
cache_path="./cache",
file_name_prefix="step",
cache_type="jsonl"
)
self.filter = GeneralFilter(
filter_rules=[
lambda df: df["score"] >= 4,
lambda df: df["text"].str.len() > 10,
]
)
def forward(self):
self.filter.run(storage=self.storage.step())
if __name__ == "__main__":
pipeline = MyPipeline()
pipeline.forward()
Note: forward() has no return value, following the standard pipeline pattern.
Version History
- 2e95d40 Current 2026-08-27 09:03


