# behave-pandas
Utility package for the [Behave](https://github.com/behave/behave) BDD testing framework, to make converting gherkin tables
to and from [pandas](https://github.com/pandas-dev/pandas) data frames a breeze.
## Build Status
![Travis CI badge](https://travis-ci.org/clembou/behave-pandas.svg?branch=master)
## Installation
```bash
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.](CHANGELOG.md)
## API
The behave-pandas api is extremely simple, and consists in two functions:
```python
from behave_pandas import table_to_dataframe, dataframe_to_table
```
## Example
```gherkin
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 |
| index_col | float_col | 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 data_frame_to_table
Then it prints a valid string copy pasteable into gherkin files
"""
| object | float64 | object |
| index_col | float_col | str_col |
| egg | 3.0 | silly walks |
| spam | 4.1 | spanish inquisition |
| bacon | 5.2 | dead parrot |
"""
```
Associated steps:
```python
from behave import *
from behave_pandas import table_to_dataframe, dataframe_to_table
use_step_matcher("parse")
@given("a gherkin table as input")
def step_impl(context,):
context.input = context.table
@when('converted to a data frame using {column_levels:d} row as column names and {index_levels:d} column as index')
def step_impl(context, column_levels, index_levels):
context.parsed = table_to_dataframe(context.input, column_levels=column_levels, index_levels=index_levels)
@then("it prints a valid string copy pasteable into gherkin files")
def step_impl(context):
assert context.result == context.text
@step("printed using data_frame_to_table")
def step_impl(context):
context.result = dataframe_to_table(context.parsed)
```
Parsed dataframe:
```
>>> context.parsed
float_col str_col
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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/clembou/behave-pandas",
"name": "behave-pandas",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "behave pandas testing bdd",
"author": "Cl\u00e9ment Bouscasse",
"author_email": "clement.bouscasse@gmail.com",
"download_url": "",
"platform": null,
"description": "# behave-pandas\n\nUtility package for the [Behave](https://github.com/behave/behave) BDD testing framework, to make converting gherkin tables\nto and from [pandas](https://github.com/pandas-dev/pandas) data frames a breeze.\n\n## Build Status\n![Travis CI badge](https://travis-ci.org/clembou/behave-pandas.svg?branch=master)\n\n## Installation\n\n```bash\npip install behave-pandas\n```\n\n## Features\n\n* Easily convert a Gherkin table into a pandas data frame with explicit dtype information\n* Easily convert a pandas data frame into a behave table that can be parsed by behave-pandas\n* Support converting data frames with multiple index levels either on columns or rows\n* Handle missing data for dtypes that support it.\n\n## Changelog\n\n[See the changelog here.](CHANGELOG.md)\n\n## API\n\nThe behave-pandas api is extremely simple, and consists in two functions:\n\n```python\nfrom behave_pandas import table_to_dataframe, dataframe_to_table\n```\n\n## Example\n\n```gherkin\nFeature: Table printer\n\n as a tester\n I want to be able to create gherkin tables from existing data frames\n\n Scenario: simple index\n Given a gherkin table as input\n | str | float | str |\n | index_col | float_col | str_col |\n | egg | 3.0 | silly walks |\n | spam | 4.1 | spanish inquisition |\n | bacon | 5.2 | dead parrot |\n When converted to a data frame using 1 row as column names and 1 column as index\n And printed using data_frame_to_table\n Then it prints a valid string copy pasteable into gherkin files\n \"\"\"\n | object | float64 | object |\n | index_col | float_col | str_col |\n | egg | 3.0 | silly walks |\n | spam | 4.1 | spanish inquisition |\n | bacon | 5.2 | dead parrot |\n \"\"\"\n```\n\nAssociated steps:\n\n```python\nfrom behave import *\nfrom behave_pandas import table_to_dataframe, dataframe_to_table\n\nuse_step_matcher(\"parse\")\n\n@given(\"a gherkin table as input\")\ndef step_impl(context,):\n context.input = context.table\n\n@when('converted to a data frame using {column_levels:d} row as column names and {index_levels:d} column as index')\ndef step_impl(context, column_levels, index_levels):\n context.parsed = table_to_dataframe(context.input, column_levels=column_levels, index_levels=index_levels)\n\n\n@then(\"it prints a valid string copy pasteable into gherkin files\")\ndef step_impl(context):\n assert context.result == context.text\n\n\n@step(\"printed using data_frame_to_table\")\ndef step_impl(context):\n context.result = dataframe_to_table(context.parsed)\n```\n\nParsed dataframe:\n\n```\n>>> context.parsed\n float_col str_col\nindex_col\negg 3.0 silly walks\nspam 4.1 spanish inquisition\nbacon 5.2 dead parrot\n\n>>> context.parsed.info()\n<class 'pandas.core.frame.DataFrame'>\nIndex: 3 entries, egg to bacon\nData columns (total 2 columns):\nfloat_col 3 non-null float64\nstr_col 3 non-null object\ndtypes: float64(1), object(1)\nmemory usage: 72.0+ bytes\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Provides helper functions to help converting behave tables into pandas dataframes and vice versa.",
"version": "0.5.0",
"split_keywords": [
"behave",
"pandas",
"testing",
"bdd"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7a8148eeaf56a2176590d7ec925cae64505d797c0a0086411f7ab7d4b161e1b8",
"md5": "cb799ff060cdb87a470bc3c28bd4d416",
"sha256": "ff67906387e778e5f83c430e679d8b0709c53a6093b1ab551dc63e24795b0afb"
},
"downloads": -1,
"filename": "behave_pandas-0.5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cb799ff060cdb87a470bc3c28bd4d416",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 6692,
"upload_time": "2023-02-09T23:09:31",
"upload_time_iso_8601": "2023-02-09T23:09:31.418836Z",
"url": "https://files.pythonhosted.org/packages/7a/81/48eeaf56a2176590d7ec925cae64505d797c0a0086411f7ab7d4b161e1b8/behave_pandas-0.5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-09 23:09:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "clembou",
"github_project": "behave-pandas",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "behave-pandas"
}