Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Changes:
The
export_kv_to_pandas
function is a new addition that converts key-value pairs with optional confidence filtering into a pandas DataFrame. I find myself needing to use this quite a lot. This PR introduces a safe import check for thepandas
library, ensuring that the function only runs ifpandas
is available, thus improving error handling. Additionally, we have added configurable options for confidence filtering, trimming whitespace and punctuation, and optional inclusion of the confidence score.Details of Changes:
pandas.DataFrame
. Ifpandas
is not installed, aMissingDependencyException
is raised with a clear message:"pandas library is required for exporting tables to DataFrame objects or markdown."
trim
: Parameter to remove extra whitespace and punctuation in key-value strings.confidence_threshold
: Parameter to set a minimum confidence level for key-value pairs to be included in the output DataFrame.drop_confidence
: Parameter to exclude the confidence column from the output DataFrame if it is not needed.Confidence
column is included.Testing:
pandas
installed to ensure that theMissingDependencyException
is raised appropriately.confidence_threshold
,trim
, anddrop_confidence
to confirm they yield expected DataFrame outputs.Confidence
column whendrop_confidence
isFalse
.Example Code:
Here’s the full function code added in this PR:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution under the terms of your choice.