@@ -242,18 +242,21 @@ def by_date_range(self, start_date: Optional[str] = None,
242242 parse_date (f ['period_end' ]) <= end_obj ))
243243 return self
244244
245- def by_dimension (self , dimension : str , value : Optional [str ] = None ) -> FactQuery :
245+ def by_dimension (self , dimension : Optional [ str ] , value : Optional [str ] = None ) -> FactQuery :
246246 """
247247 Filter facts by dimension.
248248
249249 Args:
250- dimension: Dimension name
250+ dimension: Dimension name, or None to filter for facts with no dimensions
251251 value: Optional dimension value to filter by
252252
253253 Returns:
254254 Self for method chaining
255255 """
256- if value :
256+ if dimension is None :
257+ # Filter for facts with no dimensions
258+ self ._filters .append (lambda f : not any (key .startswith ('dim_' ) for key in f .keys ()))
259+ elif value :
257260 self ._filters .append (lambda f : f'dim_{ dimension } ' in f and f [f'dim_{ dimension } ' ] == value )
258261 else :
259262 self ._filters .append (lambda f : f'dim_{ dimension } ' in f )
@@ -585,10 +588,17 @@ def to_dataframe(self, *columns) -> pd.DataFrame:
585588 # skip these columns
586589 skip_columns = ['fact_key' , 'original_label' , 'period_key' ]
587590
591+ if 'statement_role' in df .columns :
592+ # Change the statement_role to statement name
593+ df ['statement_name' ] = df .statement_role .fillna ('' ).apply (lambda s : s .split ('/' )[- 1 ] if s else None )
594+ # Remove statement_role column if it exists
595+ if 'statement_role' in df .columns :
596+ df = df .drop (columns = ['statement_role' ])
597+
588598 # order columns
589599 first_columns = [col for col in
590600 ['concept' , 'label' , 'value' , 'numeric_value' , 'period_start' , 'period_end' , 'period_instant' ,
591- 'decimals' , 'statement_type' , 'statement_role ' ]
601+ 'decimals' , 'statement_type' , 'statement_name ' ]
592602 if col in df .columns ]
593603 columns = first_columns + [col for col in df .columns
594604 if col not in first_columns
0 commit comments