Skip to content

Commit

Permalink
adds unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BWMac committed Sep 3, 2024
1 parent 0514dec commit b96f950
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/unit/synapseclient/unit_test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,53 @@ def test_csv_table() -> None:
print(ex)
raise

def test_csv_table_no_default_na_values() -> None:
# GIVEN a CSVFileTable with known data
data = {
'id': ['abc', '', 'None', 'NA'],
'test_num': [1, 2, 3, 4],
}
test_df = pd.DataFrame(data)
schema = synapseclient.table.Schema(
name="test_table",
parent="syn59478569",
column_names=["id", "test_num"],
column_types=["STRING", "INTEGER"],
)
test_table = CsvFileTable.from_data_frame(df=test_df, schema=schema)

# WHEN the table is converted to a DataFrame without default NA values
result = test_table.asDataFrame(keep_default_na=False)

# THEN the DataFrame should be equal to the original DataFrame
pd.testing.assert_frame_equal(result, test_df)

def test_csv_table_custom_na_values() -> None:
# GIVEN a CSVFileTable with known data
data = {
'id': ['abc', '', 'None', 'NA'],
'test_num': [1, 2, 3, 4],
}
test_df = pd.DataFrame(data)
schema = synapseclient.table.Schema(
name="test_table",
parent="syn59478569",
column_names=["id", "test_num"],
column_types=["STRING", "INTEGER"],
)
test_table = CsvFileTable.from_data_frame(df=test_df, schema=schema)

# WHEN the table is converted to a DataFrame with custom NA values
result = test_table.asDataFrame(na_values=['None'], keep_default_na=False)
expected_data = {
'id': ['abc', '', float('nan'), 'NA'],
'test_num': [1, 2, 3, 4],
}
expected_df = pd.DataFrame(expected_data)

# THEN the DataFrame should be equal to a dataframe with the custom NA values converted to NaN
pd.testing.assert_frame_equal(result, expected_df)


def test_list_of_rows_table() -> None:
data = [
Expand Down

0 comments on commit b96f950

Please sign in to comment.