File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -136,17 +136,18 @@ def observations_dataframe(
136136 entity_type (Optional[str]): The type of entities to filter by when `entity_dcids="all"`.
137137 Required if `entity_dcids="all"`. Defaults to None.
138138 parent_entity (Optional[str]): The parent entity under which the target entities fall.
139- Used only when `entity_dcids="all"`. Defaults to None.
139+ Required if `entity_dcids="all"`. Defaults to None.
140140 property_filters (Optional[dict[str, str | list[str]]): An optional dictionary used to filter
141141 the data by using observation properties like `measurementMethod`, `unit`, or `observationPeriod`.
142142
143143 Returns:
144144 pd.DataFrame: A DataFrame containing the requested observations.
145145 """
146146
147- if entity_dcids == "all" and not entity_type :
147+ if entity_dcids == "all" and not ( entity_type and parent_entity ) :
148148 raise ValueError (
149- "When 'entity_dcids' is 'all', 'entity_type' must be specified." )
149+ "When 'entity_dcids' is 'all', both 'parent_entity' and 'entity_type' must be specified."
150+ )
150151
151152 if entity_dcids != "all" and (entity_type or parent_entity ):
152153 raise ValueError (
Original file line number Diff line number Diff line change @@ -70,11 +70,27 @@ def test_observations_dataframe_raises_error_when_entities_all_but_no_entity_typ
7070 """Tests that ValueError is raised if 'entities' is 'all' but 'entity_type' is not specified."""
7171 with pytest .raises (
7272 ValueError ,
73- match = "When 'entity_dcids' is 'all', 'entity_type' must be specified." ,
73+ match =
74+ "When 'entity_dcids' is 'all', both 'parent_entity' and 'entity_type' must be specified." ,
7475 ):
7576 mock_client .observations_dataframe (variable_dcids = "var1" ,
7677 date = "2024" ,
77- entity_dcids = "all" )
78+ entity_dcids = "all" ,
79+ parent_entity = "africa" )
80+
81+
82+ def test_observations_dataframe_raises_error_when_entities_all_but_no_parent_entity (
83+ mock_client ,):
84+ """Tests that ValueError is raised if 'entities' is 'all' but 'entity_type' is not specified."""
85+ with pytest .raises (
86+ ValueError ,
87+ match =
88+ "When 'entity_dcids' is 'all', both 'parent_entity' and 'entity_type' must be specified." ,
89+ ):
90+ mock_client .observations_dataframe (variable_dcids = "var1" ,
91+ date = "2024" ,
92+ entity_dcids = "all" ,
93+ entity_type = "Country" )
7894
7995
8096def test_observations_dataframe_raises_error_when_invalid_entity_type_usage (
You can’t perform that action at this time.
0 commit comments