def _as_dataframe(self, multi_index=True): """ Converts the ohsome response to a pandas.DataFrame :return: pandas dataframe """ groupby_names = [] if "result" in self.data.keys(): result_df = pd.DataFrame().from_records(self.data["result"]) elif "ratioResult" in self.data.keys(): result_df = pd.DataFrame().from_records(self.data["ratioResult"]) elif "groupByResult" in self.data.keys(): groupby_names = find_groupby_names(self.url) result_df = self._create_groupby_dataframe( self.data["groupByResult"], groupby_names, ) elif "groupByBoundaryResult" in self.data.keys(): groupby_names = find_groupby_names(self.url) result_df = self._create_groupby_dataframe( self.data["groupByBoundaryResult"], groupby_names, ) else: raise TypeError("This result type is not implemented.") self._format_timestamp(result_df) if multi_index: self._set_index(result_df, groupby_names) return result_df.sort_index()
def test_find_groupby_names_two_groups(): """ Tests counting elements within a bounding box for two timestamps :return: """ url = "https://api.ohsome.org/v0.9/elements/count/groupBy/boundary/groupBy/tag" expected = ["boundary", "tag"] result = find_groupby_names(url) assert expected == result