clembou
behave-pandas
Python

Utility package for the Behave BDD testing framework, to make converting gherkin tables to and from pandas data frames a breeze.

Last updated Jan 14, 2026
15
Stars
6
Forks
2
Issues
0
Stars/day
Attention Score
6
Language breakdown
Python 61.8%
Gherkin 38.0%
Shell 0.2%
Files click to expand
README

behave-pandas

Utility package for the Behave BDD testing framework, to make converting gherkin tables to and from pandas data frames a breeze.

Build Status

Travis CI badge

Installation

pip install behave-pandas

Features

  • Easily convert a Gherkin table into a pandas data frame with explicit dtype information
  • Easily convert a pandas data frame into a behave table that can be parsed by behave-pandas
  • Support converting data frames with multiple index levels either on columns or rows
  • Handle missing data for dtypes that support it.

Changelog

See the changelog here.

API

The behave-pandas api is extremely simple, and consists in two functions:

from behavepandas import tabletodataframe, dataframeto_table

Example

Feature: Table printer

as a tester I want to be able to create gherkin tables from existing data frames

Scenario: simple index Given a gherkin table as input | str | float | str | | indexcol | floatcol | str_col | | egg | 3.0 | silly walks | | spam | 4.1 | spanish inquisition | | bacon | 5.2 | dead parrot | When converted to a data frame using 1 row as column names and 1 column as index And printed using dataframeto_table Then it prints a valid string copy pasteable into gherkin files """ | object | float64 | object | | indexcol | floatcol | str_col | | egg | 3.0 | silly walks | | spam | 4.1 | spanish inquisition | | bacon | 5.2 | dead parrot | """

Associated steps:

from behave import *
from behavepandas import tabletodataframe, dataframeto_table

usestepmatcher("parse")

@given("a gherkin table as input") def step_impl(context,): context.input = context.table

@when('converted to a data frame using {columnlevels:d} row as column names and {indexlevels:d} column as index') def stepimpl(context, columnlevels, index_levels): context.parsed = tabletodataframe(context.input, columnlevels=columnlevels, indexlevels=indexlevels)

@then("it prints a valid string copy pasteable into gherkin files") def step_impl(context): assert context.result == context.text

@step("printed using dataframeto_table") def step_impl(context): context.result = dataframetotable(context.parsed)

Parsed dataframe:

>>> context.parsed
           floatcol              strcol
index_col
egg              3.0          silly walks
spam             4.1  spanish inquisition
bacon            5.2          dead parrot

>>> context.parsed.info() <class 'pandas.core.frame.DataFrame'> Index: 3 entries, egg to bacon Data columns (total 2 columns): float_col 3 non-null float64 str_col 3 non-null object dtypes: float64(1), object(1) memory usage: 72.0+ bytes

🔗 More in this category

© 2026 GitRepoTrend · clembou/behave-pandas · Updated daily from GitHub