2828
2929from collections import defaultdict
3030
31- import pandas as pd
32-
3331import datacommons .utils as utils
3432import requests
3533
@@ -40,7 +38,7 @@ def get_property_labels(dcids, out=True):
4038 """ Returns the labels of properties defined for the given :code:`dcids`.
4139
4240 Args:
43- dcids (:obj:`list ` of :obj:`str`): A list of nodes identified by their
41+ dcids (:obj:`iterable ` of :obj:`str`): A list of nodes identified by their
4442 dcids.
4543 out (:obj:`bool`, optional): Whether or not the property points away from
4644 the given list of nodes.
@@ -99,6 +97,7 @@ def get_property_labels(dcids, out=True):
9997 }
10098 """
10199 # Generate the GetProperty query and send the request
100+ dcids = list (dcids )
102101 url = utils ._API_ROOT + utils ._API_ENDPOINTS ['get_property_labels' ]
103102 payload = utils ._send_request (url , req_json = {'dcids' : dcids })
104103
@@ -120,8 +119,7 @@ def get_property_values(dcids,
120119 """ Returns property values of given :code:`dcids` along the given property.
121120
122121 Args:
123- dcids (Union[:obj:`list` of :obj:`str`, :obj:`pandas.Series`]): dcids to get
124- property values for.
122+ dcids (:obj:`iterable` of :obj:`str`): dcids to get property values for.
125123 prop (:obj:`str`): The property to get property values for.
126124 out (:obj:`bool`, optional): A flag that indicates the property is directed
127125 away from the given nodes when set to true.
@@ -131,15 +129,8 @@ def get_property_values(dcids,
131129 aggregated over all given nodes.
132130
133131 Returns:
134- When :code:`dcids` is an instance of :obj:`list`, the returned property
135- values are formatted as a :obj:`dict` from a given dcid to a list of its
136- property values.
137-
138- When :code:`dcids` is an instance of :obj:`pandas.Series`, the returned
139- property values are formatted as a :obj:`pandas.Series` where the `i`-th
140- entry corresponds to property values associated with the `i`-th given dcid.
141- The cells of the returned series will always contain a :obj:`list` of
142- property values.
132+ Returned property values are formatted as a :obj:`dict` from a given dcid
133+ to a list of its property values.
143134
144135 Raises:
145136 ValueError: If the payload returned by the Data Commons REST API is
@@ -160,21 +151,11 @@ def get_property_values(dcids,
160151 "geoId/21": ["Kentucky"],
161152 "geoId/24": ["Maryland"],
162153 }
163-
164- Next, we specify :code:`dcids` as a :obj:`pandas.Series`
165-
166- >>> import pandas as pd
167- >>> dcids = pd.Series(["geoId/06", "geoId/21", "geoId/24"])
168- >>> get_property_values(dcids, "name")
169- 0 [California]
170- 1 [Kentucky]
171- 2 [Maryland]
172- dtype: object
173154 """
174155 # Convert the dcids field and format the request to GetPropertyValue
175- dcids , req_dcids = utils . _convert_dcids_type (dcids )
156+ dcids = list (dcids )
176157 req_json = {
177- 'dcids' : req_dcids ,
158+ 'dcids' : dcids ,
178159 'property' : prop ,
179160 'limit' : limit
180161 }
@@ -205,9 +186,6 @@ def get_property_values(dcids,
205186 # Make sure each dcid is in the results dict, and convert all sets to lists.
206187 results = {dcid : sorted (list (unique_results [dcid ])) for dcid in dcids }
207188
208- # Format the results as a Series if a Pandas Series is provided.
209- if isinstance (dcids , pd .Series ):
210- return pd .Series ([results [dcid ] for dcid in dcids ], index = dcids .index )
211189 return results
212190
213191
@@ -221,7 +199,7 @@ def get_triples(dcids, limit=utils._MAX_LIMIT):
221199 *predicate*).
222200
223201 Args:
224- dcids (:obj:`list ` of :obj:`str`): A list of dcids to get triples for.
202+ dcids (:obj:`iterable ` of :obj:`str`): A list of dcids to get triples for.
225203 limit (:obj:`int`, optional): The maximum total number of triples to get.
226204
227205 Returns:
@@ -249,6 +227,7 @@ def get_triples(dcids, limit=utils._MAX_LIMIT):
249227 }
250228 """
251229 # Generate the GetTriple query and send the request.
230+ dcids = list (dcids )
252231 url = utils ._API_ROOT + utils ._API_ENDPOINTS ['get_triples' ]
253232 payload = utils ._send_request (url , req_json = {'dcids' : dcids , 'limit' : limit })
254233
0 commit comments