|
87 | 87 | "warnings.filterwarnings('ignore')" |
88 | 88 | ] |
89 | 89 | }, |
| 90 | + { |
| 91 | + "cell_type": "markdown", |
| 92 | + "metadata": {}, |
| 93 | + "source": [ |
| 94 | + "In general the order of results from database queries cannot be assumed to be the same every time.\n", |
| 95 | + "This function sorts the data so we can compare the result dataframes even if the records are not in the same order from the query." |
| 96 | + ] |
| 97 | + }, |
| 98 | + { |
| 99 | + "cell_type": "code", |
| 100 | + "execution_count": null, |
| 101 | + "metadata": {}, |
| 102 | + "outputs": [], |
| 103 | + "source": [ |
| 104 | + "def sort_dataframe(df, sort_key='objectid'):\n", |
| 105 | + " df = df.sort_values('objectId')\n", |
| 106 | + " df.set_index(np.array(range(len(df))), inplace=True) # Since we are sorting, we need to reset the incremental index as well\n", |
| 107 | + " return df" |
| 108 | + ] |
| 109 | + }, |
90 | 110 | { |
91 | 111 | "cell_type": "markdown", |
92 | 112 | "metadata": {}, |
|
303 | 323 | "source": [ |
304 | 324 | "# Convert the results to pandas data frames and assert that the\n", |
305 | 325 | "# contents of the two tables are identical\n", |
306 | | - "assert_frame_equal(results.to_table().to_pandas(),\n", |
307 | | - " results1.to_table().to_pandas())" |
| 326 | + "assert_frame_equal(sort_dataframe(results.to_table().to_pandas()),\n", |
| 327 | + " sort_dataframe(results1.to_table().to_pandas()))" |
308 | 328 | ] |
309 | 329 | }, |
310 | 330 | { |
|
827 | 847 | "# Assert that the results are the same as obtained from\n", |
828 | 848 | "# executing synchronous queries\n", |
829 | 849 | "assert len(async_results) == 14424 \n", |
830 | | - "assert_frame_equal(results, async_results.to_table().to_pandas())" |
| 850 | + "assert_frame_equal(sort_dataframe(results), sort_dataframe(async_results.to_table().to_pandas()))" |
831 | 851 | ] |
832 | 852 | }, |
833 | 853 | { |
|
848 | 868 | "retrieved_job = retrieve_query(job.url)\n", |
849 | 869 | "retrieved_results = retrieved_job.fetch_result()\n", |
850 | 870 | "assert len(retrieved_results) == 14424\n", |
851 | | - "assert_frame_equal(retrieved_results.to_table().to_pandas(),\n", |
852 | | - " async_results.to_table().to_pandas())" |
| 871 | + "assert_frame_equal(sort_dataframe(retrieved_results.to_table().to_pandas()),\n", |
| 872 | + " sort_dataframe(async_results.to_table().to_pandas()))" |
853 | 873 | ] |
854 | 874 | }, |
855 | 875 | { |
|
0 commit comments