Skip to content

Commit

Permalink
Add test to check _collapse skips null values
Browse files Browse the repository at this point in the history
Signed-off-by: John Pennycook <[email protected]>
  • Loading branch information
Pennycook committed Aug 14, 2024
1 parent e2b2c7c commit b1a89e6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/data/test_projection.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright (C) 2022-2023 Intel Corporation
# SPDX-License-Identifier: MIT

import unittest

import pandas as pd

from p3.data import projection
from p3.data._projection import _collapse
import unittest


class TestProjection(unittest.TestCase):
Expand All @@ -24,6 +26,18 @@ def test_collapse(self):

pd.testing.assert_frame_equal(df, expected_df)

def test_collapse_null(self):
"""Check that _collapse skips null values"""
data = {"c1": ["x", "y", "z"], "c2": ["1", None, "3"]}
df = pd.DataFrame(data)

_collapse(df, ["c1", "c2"], "c3")

expected_data = {"c3": ["x-1", "y", "z-3"]}
expected_df = pd.DataFrame(expected_data)

pd.testing.assert_frame_equal(df, expected_df)

def test_required_columns(self):
"""p3.data.projection.required_columns"""
df = pd.DataFrame()
Expand Down

0 comments on commit b1a89e6

Please sign in to comment.