|
16 | 16 | _any, |
17 | 17 | _cast_to_type, |
18 | 18 | _extract_timezone_from_a_string, |
| 19 | + _fill_nan_with_none_series, |
19 | 20 | _get_utc_offset, |
20 | 21 | _handle_enforce_uniqueness_and_cardinality_rule, |
21 | 22 | _max_repeat, |
@@ -167,6 +168,45 @@ def test_fill_nan_with_none_no_warning(): |
167 | 168 | pd.testing.assert_series_equal(result, expected) |
168 | 169 |
|
169 | 170 |
|
| 171 | +def test__fill_nan_with_none_series(): |
| 172 | + """Test the ``_fill_nan_with_none_series`` method.""" |
| 173 | + # Setup |
| 174 | + series = pd.Series([1.0, 2.0, 3.0, np.nan], dtype='object') |
| 175 | + categorical_serie = pd.Series(['a', 'b', 'c', 'd', np.nan], dtype='category') |
| 176 | + |
| 177 | + # Run |
| 178 | + result = _fill_nan_with_none_series(series) |
| 179 | + result_categorical = _fill_nan_with_none_series(categorical_serie) |
| 180 | + |
| 181 | + # Assert |
| 182 | + expected_result = pd.Series([1.0, 2.0, 3.0, None], dtype='object') |
| 183 | + pd.testing.assert_series_equal(result, expected_result) |
| 184 | + expected_result_categorical = pd.Series( |
| 185 | + pd.Categorical(['a', 'b', 'c', 'd', None], categories=['a', 'b', 'c', 'd']) |
| 186 | + ) |
| 187 | + pd.testing.assert_series_equal(result_categorical, expected_result_categorical) |
| 188 | + |
| 189 | + |
| 190 | +def test_fill_nan_with_none_series(): |
| 191 | + """Test the `fill_nan_with_none_series` function.""" |
| 192 | + # Setup |
| 193 | + series = pd.Series([1.0, 2.0, 3.0, np.nan], dtype='object') |
| 194 | + data = pd.DataFrame({'col1': series}) |
| 195 | + data_2 = pd.DataFrame({'col1': series, 'col2': ['a', 'b', 'c', np.nan]}) |
| 196 | + |
| 197 | + # Run |
| 198 | + result_series = _fill_nan_with_none_series(series) |
| 199 | + result_data = fill_nan_with_none(data) |
| 200 | + result_data_2 = fill_nan_with_none(data_2) |
| 201 | + |
| 202 | + # Assert |
| 203 | + expected_result = pd.Series([1.0, 2.0, 3.0, None], dtype='object') |
| 204 | + expected_result_data_2 = pd.DataFrame({'col1': expected_result, 'col2': ['a', 'b', 'c', None]}) |
| 205 | + pd.testing.assert_series_equal(result_series, expected_result) |
| 206 | + pd.testing.assert_frame_equal(result_data, pd.DataFrame({'col1': expected_result})) |
| 207 | + pd.testing.assert_frame_equal(result_data_2, expected_result_data_2) |
| 208 | + |
| 209 | + |
170 | 210 | def test_check_nan_in_transform(): |
171 | 211 | """Test ``check_nan_in_transform`` method. |
172 | 212 |
|
|
0 commit comments