Skip to content

Commit 8ec310d

Browse files
committed
Server: add assert_frame_equal_no_order test util
1 parent 0b1696a commit 8ec310d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/acquisition/covidcast/covidcast_row.py

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from delphi_utils import Nans
66
from numpy import isnan
77
from pandas import DataFrame, concat
8+
from pandas.testing import assert_frame_equal
89

910
from delphi.epidata.acquisition.covidcast.csv_importer import CsvImporter
1011
from delphi.epidata.server.utils.dates import date_to_time_value, time_value_to_date
@@ -267,3 +268,11 @@ def set_df_dtypes(df: DataFrame, dtypes: Dict[str, Any]) -> DataFrame:
267268
if k in df.columns:
268269
df[k] = df[k].astype(v)
269270
return df
271+
272+
273+
def assert_frame_equal_no_order(df1: DataFrame, df2: DataFrame, index: List[str], **kwargs: Any) -> None:
274+
"""Assert that two DataFrames are equal, ignoring the order of rows."""
275+
# Remove any existing index. If it wasn't named, drop it. Set a new index and sort it.
276+
df1 = df1.reset_index().drop(columns="index").set_index(index).sort_index()
277+
df2 = df2.reset_index().drop(columns="index").set_index(index).sort_index()
278+
assert_frame_equal(df1, df2, **kwargs)

0 commit comments

Comments
 (0)