|
| 1 | +""" |
| 2 | +Integration tests for pandas modules. |
| 3 | +
|
| 4 | +These tests verify interactions between multiple modules/components: |
| 5 | +- pandas.core.series (Series construction) |
| 6 | +- pandas.core.frame (DataFrame construction) |
| 7 | +- pandas.core.dtypes (dtype handling) |
| 8 | +- pandas.core.internals (internal data management) |
| 9 | +- pandas.util._validators (validation utilities) |
| 10 | +- pandas.core.missing (missing data handling) |
| 11 | +""" |
| 12 | +import numpy as np |
| 13 | +import pytest |
| 14 | + |
| 15 | +import pandas as pd |
| 16 | +from pandas import Series, DataFrame, Index |
| 17 | +from pandas.core.missing import clean_fill_method |
| 18 | +from pandas._libs import lib |
| 19 | +from pandas.util._validators import ( |
| 20 | + validate_args_and_kwargs, |
| 21 | + validate_fillna_kwargs, |
| 22 | + check_dtype_backend, |
| 23 | + validate_percentile, |
| 24 | +) |
| 25 | + |
| 26 | + |
| 27 | +class TestSandeepIntegration: |
| 28 | + """Integration tests by Sandeep Ramavath covering Series-DataFrame-dtype interactions.""" |
| 29 | + |
| 30 | + def test_series_to_dataframe_dtype_preservation(self): |
| 31 | + """Test Series.to_frame() preserves dtype through internals conversion. |
| 32 | + |
| 33 | + This exercises interaction between: |
| 34 | + - pandas.core.series.Series.to_frame() |
| 35 | + - pandas.core.internals (manager conversion) |
| 36 | + - pandas.core.frame.DataFrame |
| 37 | + - pandas.core.dtypes (dtype preservation) |
| 38 | + """ |
| 39 | + # Create Series with specific dtype |
| 40 | + s = Series([1, 2, 3], name="test_col", dtype="int32") |
| 41 | + |
| 42 | + # Convert to DataFrame - should preserve dtype through internal conversion |
| 43 | + df = s.to_frame() |
| 44 | + |
| 45 | + assert isinstance(df, DataFrame) |
| 46 | + assert df.columns[0] == "test_col" |
| 47 | + assert df["test_col"].dtype == np.dtype("int32") |
| 48 | + assert len(df) == 3 |
| 49 | + assert (df["test_col"] == s).all() |
| 50 | + |
| 51 | + def test_dataframe_from_dict_mixed_series_dtypes(self): |
| 52 | + """Test DataFrame construction from dict with mixed Series dtypes. |
| 53 | + |
| 54 | + This exercises interaction between: |
| 55 | + - pandas.core.frame.DataFrame.__init__ |
| 56 | + - pandas.core.internals.construction.dict_to_mgr |
| 57 | + - pandas.core.series.Series (multiple instances with different dtypes) |
| 58 | + - pandas.core.dtypes (type coercion and preservation) |
| 59 | + """ |
| 60 | + # Create Series with different dtypes |
| 61 | + s1 = Series([1, 2, 3], dtype="int64") |
| 62 | + s2 = Series([1.0, 2.0, 3.0], dtype="float32") |
| 63 | + s3 = Series(["a", "b", "c"], dtype="object") |
| 64 | + |
| 65 | + # Build DataFrame from dict of Series |
| 66 | + df = DataFrame({"col1": s1, "col2": s2, "col3": s3}) |
| 67 | + |
| 68 | + # Verify each column maintains its original dtype |
| 69 | + assert df["col1"].dtype == np.dtype("int64") |
| 70 | + assert df["col2"].dtype == np.dtype("float32") |
| 71 | + assert df["col3"].dtype == np.dtype("object") |
| 72 | + assert len(df) == 3 |
| 73 | + |
| 74 | + |
| 75 | +class TestNithikeshIntegration: |
| 76 | + """Integration tests by Nithikesh Bobbili covering validation-missing data interactions.""" |
| 77 | + |
| 78 | + def test_validate_fillna_with_clean_method(self): |
| 79 | + """Test validate_fillna_kwargs delegates to clean_fill_method. |
| 80 | + |
| 81 | + This exercises interaction between: |
| 82 | + - pandas.util._validators.validate_fillna_kwargs |
| 83 | + - pandas.core.missing.clean_fill_method |
| 84 | + - method normalization and validation |
| 85 | + """ |
| 86 | + # Test method normalization through validate_fillna_kwargs |
| 87 | + value, method = validate_fillna_kwargs(None, "pad") |
| 88 | + assert value is None |
| 89 | + assert method == clean_fill_method("pad") |
| 90 | + |
| 91 | + # Test alternate method names |
| 92 | + value, method = validate_fillna_kwargs(None, "ffill") |
| 93 | + assert method == clean_fill_method("ffill") |
| 94 | + |
| 95 | + # Both None should raise |
| 96 | + with pytest.raises(ValueError, match="Must specify a fill"): |
| 97 | + validate_fillna_kwargs(None, None) |
| 98 | + |
| 99 | + def test_series_fillna_integration(self): |
| 100 | + """Test Series.fillna() and ffill() use validation and missing data modules. |
| 101 | + |
| 102 | + This exercises interaction between: |
| 103 | + - pandas.core.series.Series.fillna() / ffill() |
| 104 | + - pandas.util._validators.validate_fillna_kwargs (internally) |
| 105 | + - pandas.core.missing (fill methods) |
| 106 | + - pandas.core.internals (data modification) |
| 107 | + """ |
| 108 | + # Create Series with missing values |
| 109 | + s = Series([1.0, np.nan, 3.0, np.nan, 5.0]) |
| 110 | + |
| 111 | + # ffill uses forward fill method - interacts with missing data module |
| 112 | + result = s.ffill() |
| 113 | + expected = Series([1.0, 1.0, 3.0, 3.0, 5.0]) |
| 114 | + pd.testing.assert_series_equal(result, expected) |
| 115 | + |
| 116 | + # fillna with value - validation ensures value is acceptable |
| 117 | + result = s.fillna(value=0.0) |
| 118 | + expected = Series([1.0, 0.0, 3.0, 0.0, 5.0]) |
| 119 | + pd.testing.assert_series_equal(result, expected) |
| 120 | + |
| 121 | +class TestMallikarjunaIntegration: |
| 122 | + """Integration tests by Mallikarjuna covering dtype_backend-libs interactions.""" |
| 123 | + |
| 124 | + def test_check_dtype_backend_with_lib_sentinel(self): |
| 125 | + """Test check_dtype_backend with lib.no_default sentinel. |
| 126 | + |
| 127 | + This exercises interaction between: |
| 128 | + - pandas.util._validators.check_dtype_backend |
| 129 | + - pandas._libs.lib.no_default (sentinel value) |
| 130 | + - validation of backend options |
| 131 | + """ |
| 132 | + # Should accept sentinel without exception |
| 133 | + check_dtype_backend(lib.no_default) |
| 134 | + |
| 135 | + # Should accept valid backends |
| 136 | + check_dtype_backend("numpy_nullable") |
| 137 | + check_dtype_backend("pyarrow") |
| 138 | + |
| 139 | + # Should reject unknown backend |
| 140 | + with pytest.raises(ValueError, match="dtype_backend .* is invalid"): |
| 141 | + check_dtype_backend("not_a_backend") |
| 142 | + |
| 143 | + def test_percentile_validation_with_numpy_arrays(self): |
| 144 | + """Test validate_percentile with numpy array interaction. |
| 145 | + |
| 146 | + This exercises interaction between: |
| 147 | + - pandas.util._validators.validate_percentile |
| 148 | + - numpy array conversion and validation |
| 149 | + - pandas statistical methods that use percentiles |
| 150 | + """ |
| 151 | + # Single percentile as float |
| 152 | + result = validate_percentile(0.5) |
| 153 | + assert isinstance(result, np.ndarray) |
| 154 | + assert result == 0.5 |
| 155 | + |
| 156 | + # Multiple percentiles as list |
| 157 | + result = validate_percentile([0.25, 0.5, 0.75]) |
| 158 | + expected = np.array([0.25, 0.5, 0.75]) |
| 159 | + np.testing.assert_array_equal(result, expected) |
| 160 | + |
| 161 | + # Invalid percentile should raise |
| 162 | + with pytest.raises(ValueError, match="percentiles should all be"): |
| 163 | + validate_percentile(1.5) |
| 164 | + |
| 165 | + with pytest.raises(ValueError, match="percentiles should all be"): |
| 166 | + validate_percentile([0.25, 1.5, 0.75]) |
| 167 | + |
| 168 | + |
0 commit comments