Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force tables to have all columns that are defined in schema #147

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repos:
# Formatters: hooks that re-write Python and RST files
########################################################################################
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.290
rev: v0.0.291
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ docs = [
"doc8>=1.0,<1.2", # Ensures clean documentation formatting
"furo>=2022.4.7",
"sphinx>=4,!=5.1.0,<7.3", # The default Python documentation engine
"sphinx-autoapi>=2.0,<2.2", # Generates documentation from docstrings
"sphinx-autoapi>=3.0,<4", # Generates documentation from docstrings
"sphinx-issues>=1.2,<3.1", # Allows references to GitHub issues
]
tests = [
Expand Down
1 change: 1 addition & 0 deletions src/ferc_xbrl_extractor/datapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def construct_dataframe(self, instance: Instance) -> pd.DataFrame:
.set_index(fact_index)
.pipe(fuzzy_dedup)["value"]
.unstack("name")
.reindex(columns=self.data_columns)
)

facts["report_date"] = instance.report_date
Expand Down
21 changes: 11 additions & 10 deletions tests/integration/datapackage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def _create_schema(instant=True, axes=None):
*axes,
Field(name="column_one", title="", description=""),
Field(name="column_two", title="", description=""),
Field(name="null_col", title="", description=""),
],
primary_key=primary_key,
)
Expand All @@ -61,9 +62,9 @@ def _create_schema(instant=True, axes=None):
"duration",
pd.read_csv(
io.StringIO(
"c_id,entity_id,filing_name,start_date,end_date,column_one,column_two\n"
'cid_1,EID1,filing,2021-01-01,2021-12-31,"value 1","value 2"\n'
'cid_4,EID1,filing,2020-01-01,2020-12-31,"value 3","value 4"\n'
"c_id,entity_id,filing_name,start_date,end_date,column_one,column_two,null_col\n"
'cid_1,EID1,filing,2021-01-01,2021-12-31,"value 1","value 2",\n'
'cid_4,EID1,filing,2020-01-01,2020-12-31,"value 3","value 4",\n'
)
),
),
Expand All @@ -72,10 +73,10 @@ def _create_schema(instant=True, axes=None):
"duration",
pd.read_csv(
io.StringIO(
"c_id,entity_id,filing_name,start_date,end_date,dimension_one_axis,column_one,column_two\n"
'cid_1,EID1,filing,2021-01-01,2021-12-31,total,"value 1","value 2"\n'
'cid_4,EID1,filing,2020-01-01,2020-12-31,total,"value 3","value 4"\n'
'cid_5,EID1,filing,2020-01-01,2020-12-31,"Dim 1 Value","value 9","value 10"\n'
"c_id,entity_id,filing_name,start_date,end_date,dimension_one_axis,column_one,column_two,null_col\n"
'cid_1,EID1,filing,2021-01-01,2021-12-31,total,"value 1","value 2",\n'
'cid_4,EID1,filing,2020-01-01,2020-12-31,total,"value 3","value 4",\n'
'cid_5,EID1,filing,2020-01-01,2020-12-31,"Dim 1 Value","value 9","value 10",\n'
)
),
),
Expand All @@ -84,9 +85,9 @@ def _create_schema(instant=True, axes=None):
"instant",
pd.read_csv(
io.StringIO(
"c_id,entity_id,filing_name,date,dimension_one_axis,dimension_two_axis,column_one,column_two\n"
'cid_2,EID1,filing,2021-12-31,total,total,"value 5","value 6"\n'
'cid_3,EID1,filing,2021-12-31,"Dim 1 Value","ferc:Dimension2Value","value 7","value 8"\n'
"c_id,entity_id,filing_name,date,dimension_one_axis,dimension_two_axis,column_one,column_two,null_col\n"
'cid_2,EID1,filing,2021-12-31,total,total,"value 5","value 6",\n'
'cid_3,EID1,filing,2021-12-31,"Dim 1 Value","ferc:Dimension2Value","value 7","value 8",\n'
)
),
),
Expand Down