"src/git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "63d974bca5b19821d016d392b2a82c6cd3797d3a"
Unverified Commit 27d9ad2e authored by Nikita Titov's avatar Nikita Titov Committed by GitHub
Browse files

[tests][python] Make test that checks original pandas data isn't modified more strict (#5267)

* Update test_basic.py

* Address review comment
parent 1dc7a293
...@@ -654,16 +654,17 @@ def test_no_copy_when_single_float_dtype_dataframe(dtype, feature_name): ...@@ -654,16 +654,17 @@ def test_no_copy_when_single_float_dtype_dataframe(dtype, feature_name):
assert np.shares_memory(X, built_data) assert np.shares_memory(X, built_data)
@pytest.mark.parametrize('feature_name', [['x1'], 'auto']) @pytest.mark.parametrize('feature_name', [['x1'], [42], 'auto'])
def test_categorical_code_conversion_doesnt_modify_original_data(feature_name): def test_categorical_code_conversion_doesnt_modify_original_data(feature_name):
pd = pytest.importorskip('pandas') pd = pytest.importorskip('pandas')
X = np.random.choice(['a', 'b'], 100).reshape(-1, 1) X = np.random.choice(['a', 'b'], 100).reshape(-1, 1)
df = pd.DataFrame(X.copy(), columns=['x1'], dtype='category') column_name = 'a' if feature_name == 'auto' else feature_name[0]
df = pd.DataFrame(X.copy(), columns=[column_name], dtype='category')
data = lgb.basic._data_from_pandas(df, feature_name, None, None)[0] data = lgb.basic._data_from_pandas(df, feature_name, None, None)[0]
# check that the original data wasn't modified # check that the original data wasn't modified
np.testing.assert_equal(df['x1'], X[:, 0]) np.testing.assert_equal(df[column_name], X[:, 0])
# check that the built data has the codes # check that the built data has the codes
np.testing.assert_equal(df['x1'].cat.codes, data[:, 0]) np.testing.assert_equal(df[column_name].cat.codes, data[:, 0])
@pytest.mark.parametrize('min_data_in_bin', [2, 10]) @pytest.mark.parametrize('min_data_in_bin', [2, 10])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment