์ต์ข ์ฌ์ฉ์๋ ๋๋ฒ๊น ๋ชฉ์ ์ผ๋ก ์ค๋ฅ ๋ฉ์์ง์ ์์กดํฉ๋๋ค. ๋ฐ๋ผ์ ํธ๋ฆฌ๊ฑฐ๋ ์ค๋ฅ์ ๋ฐ๋ผ ์ฌ๋ฐ๋ฅธ ์ค๋ฅ ๋ฉ์์ง๊ฐ ํ์๋๋์ง ํ์ธํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค.
ํต์ฌ ์์ด๋์ด๋ ์ด๊ฒ์ ๋ณํํ๋ ๊ฒ์ ๋๋ค.
with pytest.raises(klass):
# Some code that raise an error
์ด์:
with pytest.raises(klass, match=msg):
# Some code that raise an error
pytest.raises
์ ๋ํ ์์ธํ ๋ด์ฉ์ ์ฌ๊ธฐ ๋ฅผ ์ฐธ์กฐํ์ญ์์ค .
์ ๊ธฐ ์ค๋ฅ ๋ฉ์์ง (์ฆ, ํน์ ํฌ๋ ์๋๋ค ์๋ฏธ) ์ธ๋ถ ์ค๋ฅ ๋ฉ์์ง๊ฐ์ด ๊ฒฝ์ฐ์, ๋น์ ์ ์ฌ์ฉํด์ผ external_error_raised
๋์ pytest.raises
.
์ ์ฌ์ฉ external_error_raised
๊ฐ์ __exactly__์
๋๋ค pytest.raises
์ ์ ์ผํ ์ฐจ์ด์ ์ ๋น์ ์ด ์ ๋ฌ๋์ง ์๋๋ค๋ ๊ฒ์
๋๋ค match
์ธ์.
์๋ฅผ ๋ค์ด:
import pandas._testing as tm
def test_foo():
with tm.external_error_raised(ValueError):
raise ValueError("foo")
https://github.com/pandas-dev/pandas/issues/30999
๋น์ ์ PR์์.
์์ ๊ณํ์ ๋ํด ์๊ฒฌ์ ๋งํ์ฌ ์์ ์ ๋ ๋ฐฐ๋ก ํ์ง ์๋๋ก ํ์ญ์์ค(์ ๋ฅผ ์ธ๊ธํ ํ์๊ฐ ์์ต๋๋ค. ์์ ๊ณํ์ ์ ์ธํ ์ ์์ต๋๋ค. ์ด๋ฏธ ์ํํ ์์ ์ด ์๋์ง ํ์ธํ๋ ๊ฒ์ ๊ธฐ์ตํ์ญ์์ค).
"์๋ฃ"๋ก ํ์๋์ด์ผ ํ๋ ํ์ผ(๋ ์ด์ ํ ์ผ์ด ์๋ ๊ฒ์ฒ๋ผ)์ด "์๋ฃ"๋ก ํ์๋์ง ์์ ๊ฒฝ์ฐ, ์ด์ ๋ํด ์๋ ค์ฃผ๋ ๋๊ธ์ ๋ฌ์์ฃผ์ธ์(๊ทธ๋ฆฌ๊ณ @MomIsBestFriend
๋ฃ์ด ์ ๋ฅผ ์ธ๊ธํ์ธ์.
์ ์ฒด ๋ชฉ๋ก์ ์ง์ ์์ฑํ๋ ค๋ฉด ๋ค์์ ์คํํ ์ ์์ต๋๋ค.
python scripts/validate_unwanted_patterns.py -vt="bare_pytest_raises" pandas/tests/
๋ค์๊ณผ ๊ฐ์ ๋จ์ผ ํ์ผ์ ๋ํด ์คํํ ์๋ ์์ต๋๋ค.
python scripts/validate_unwanted_patterns.py -vt="bare_pytest_raises" pandas/tests/PATH/TO/SPECIFIC/FILE.py
ํ์ผ์ ๋ฒ ์ด pytest.raises
๊ฐ ํฌํจ๋์ด ์์ผ๋ฉด ์คํฌ๋ฆฝํธ๋ ๋ค์์ ์ถ๋ ฅํฉ๋๋ค.
pandas/tests/arithmetic/test_numeric.py:553:Bare pytests raise have been found. Please pass in the argument 'match' as well the exception
์ด๋ 553
๋ผ์ธ์ pandas/tests/arithmetic/test_numeric.py
์ pytest.raises
ํ์ผ์ด ์ง์์ ์ผ๋ก ์ด๋/์ด๋ฆ ๋ณ๊ฒฝ๋จ์ ๋ฐ๋ผ ๋ชฉ๋ก์ด ๋ณ๊ฒฝ๋ ์ ์์ต๋๋ค.
@gfyoung์ด ์ฒ์ ์ด์๋ #23922์์ ๊ฑฐ์ ๋ชจ๋ ๊ฒ์ ๊ฐ์ ธ์์ต๋๋ค.
๋ด๊ฐ ๊ฑธ๋ฆด ๊ฒ์ ๋๋ค:
๋ค์ ์์ ์ ์์ํ ๊ฒ์ ๋๋ค.
ํฌ๋/ํ
์คํธ/์ฐ์ /test_numeric.py
ํฌ๋/ํ
์คํธ/์ฐ์ /test_object.py
ํฌ๋/ํ
์คํธ/์ฐ์ /test_period.py
ํฌ๋/ํ
์คํธ/์ฐ์ /test_timedelta64.py
ํฌ๋/ํ
์คํธ/๋ฐฐ์ด/๊ฐ๊ฒฉ/test_interval.py
@gdex1 ๋์์ด ๋์์ผ๋ฉด ํฉ๋๋ค :)
(์ซ์๋ ์ค ๋ฒํธ๋ฅผ ๋ํ๋ ๋๋ค)
pandas/tests/arithmetic/test_numeric.py:138
pandas/tests/arithmetic/test_numeric.py:141
pandas/tests/arithmetic/test_numeric.py:190
pandas/tests/arithmetic/test_numeric.py:208
pandas/tests/arithmetic/test_numeric.py:210
pandas/tests/arithmetic/test_numeric.py:212
pandas/tests/arithmetic/test_numeric.py:214
pandas/tests/arithmetic/test_numeric.py:232
pandas/tests/arithmetic/test_numeric.py:234
pandas/tests/arithmetic/test_numeric.py:236
pandas/tests/arithmetic/test_numeric.py:238
pandas/tests/arithmetic/test_numeric.py:519
pandas/tests/arithmetic/test_numeric.py:610
pandas/tests/arithmetic/test_numeric.py:615
pandas/tests/arithmetic/test_numeric.py:617
pandas/tests/arithmetic/test_numeric.py:795
pandas/tests/arithmetic/test_numeric.py:798
pandas/tests/arithmetic/test_numeric.py:819
pandas/tests/arithmetic/test_object.py:140
pandas/tests/arithmetic/test_object.py:152
pandas/tests/arithmetic/test_object.py:154
pandas/tests/arithmetic/test_object.py:278
pandas/tests/arithmetic/test_object.py:280
pandas/tests/arithmetic/test_object.py:282
pandas/tests/arithmetic/test_object.py:284
pandas/tests/arithmetic/test_object.py:298
pandas/tests/arithmetic/test_object.py:301
pandas/tests/arithmetic/test_object.py:315
pandas/tests/arithmetic/test_object.py:318
md5-634e15eb80aa764171dbacd11a06b70b
pandas/tests/arithmetic/test_timedelta64.py:51
pandas/tests/arithmetic/test_timedelta64.py:445
pandas/tests/arithmetic/test_timedelta64.py:607
pandas/tests/arithmetic/test_timedelta64.py:609
pandas/tests/arithmetic/test_timedelta64.py:703
pandas/tests/arithmetic/test_timedelta64.py:705
pandas/tests/arithmetic/test_timedelta64.py:707
pandas/tests/arithmetic/test_timedelta64.py:709
pandas/tests/arithmetic/test_timedelta64.py:741
pandas/tests/arithmetic/test_timedelta64.py:743
pandas/tests/arithmetic/test_timedelta64.py:960
pandas/tests/arithmetic/test_timedelta64.py:972
pandas/tests/arithmetic/test_timedelta64.py:1028
pandas/tests/arithmetic/test_timedelta64.py:1037
pandas/tests/arithmetic/test_timedelta64.py:1039
pandas/tests/arithmetic/test_timedelta64.py:1502
pandas/tests/arithmetic/test_timedelta64.py:1505
pandas/tests/arithmetic/test_timedelta64.py:1508
pandas/tests/arithmetic/test_timedelta64.py:1511
pandas/tests/arithmetic/test_timedelta64.py:1536
pandas/tests/arithmetic/test_timedelta64.py:1591
pandas/tests/arithmetic/test_timedelta64.py:1783
pandas/tests/arithmetic/test_timedelta64.py:1785
pandas/tests/arithmetic/test_timedelta64.py:1911
pandas/tests/arithmetic/test_timedelta64.py:1960
pandas/tests/arithmetic/test_timedelta64.py:1962
pandas/tests/arithmetic/test_timedelta64.py:1968
md5-634e15eb80aa764171dbacd11a06b70b
pandas/tests/arrays/interval/test_interval.py:155
@gfyoung ๋ชฉ๋ก์ ์ค์ ๋ก grep -r -e "pytest.raises([a-zA-Z]*)" pandas/tests -l
์ ์ํด ์์ฑ๋ ๊ฒ์ด ์๋๋ผ #30755์ ์คํฌ๋ฆฝํธ์ ์ํด ์์ฑ๋์์ต๋๋ค( bare_pytest_raises
๋ผ๋ ์ ํจ์ฑ ๊ฒ์ฌ ์ ํ). ํ ๋ฒ ๋ฌธ์ ๋ณธ๋ฌธ์ ์ง์นจ์ ์
๋ ฅํ๊ฒ ์ต๋๋ค. ๋ณํฉ๋ฉ๋๋ค :์ค๋ง์ผ:
@MomIsBestFriend ๋์๋๋ฆฌ๊ฒ ์ต๋๋ค:
ํฌ๋/ํ
์คํธ/๋ฒ ์ด์ค/test_constructors.py
ํฌ๋/ํ
์คํธ/๋ฒ ์ด์ค/test_ops.py
๋๋ ์ด๊ฒ๋ค์ ๋๋ณผ ์ ์๋ค:
@MomIsBestFriend
ํฌ๋/tests/io/test_html.py
ํฌ๋/ํ
์คํธ/io/test_parquet.py
ํฌ๋/ํ
์คํธ/io/test_sql.py
ํฌ๋/ํ
์คํธ/io/test_stata.py
ํฌ๋/ํ
์คํธ/ํ๋กํ
/test_backend.py
ํฌ๋/ํ
์คํธ/ํ๋กํ
/test_boxplot_method.py
ํฌ๋/ํ
์คํธ/ํ๋กํ
/test_frame.py
ํฌ๋/ํ
์คํธ/ํ๋กํ
/test_hist_method.py
ํฌ๋/ํ
์คํธ/ํ๋กํ
/test_series.py
ํฌ๋/tests/reductions/test_reductions.py
@MomIsBestFriend https://github.com/pandas-dev/pandas/issues/23922์์ ์ด์ ๋ํ ๋ ผ์๊ฐ ๊ฝค ์์์ต๋๋ค. ๋ด๊ฐ ๊ฑฐ๊ธฐ์์ ๋งํ๋ฏ์ด ๋ฐ๋ณตํ๊ธฐ ๋๋ฌธ์: ๋๋ ์ฐ๋ฆฌ๊ฐ ๋ชจ๋ ์ค๋ฅ ๋ฉ์์ง๋ฅผ "๋งน๋ชฉ์ ์ผ๋ก" ์ฃผ์ฅํด์ผ ํ๋ค๊ณ ์๊ฐํ์ง ์์ต๋๋ค.
๊ทธ ์ค๋ ๋์์ ๋งํ ๋ช ๊ฐ์ง: ๋ด๋ถ ์ค๋ฅ ๋ฉ์์ง๋ก ์ ํํ๊ณ , ๋ฉ์์ง์ ๋ช ๊ฐ์ง ํต์ฌ ๋จ์ด๋ก ์ผ์น๋ฅผ ์ ํํ๊ณ , ๋ณต์กํ ํจํด์ ํผํ์ญ์์ค.
๋ํ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ์ฃผ์ฅํ๋ ๊ฒ์ ์ค์ ๋ก ๊ทธ๊ฒ์ด ํ๋ฅญํ๊ณ ๋ช ํํ ์ค๋ฅ ๋ฉ์์ง์ธ์ง ํ์ธํ๊ณ ์ด๋ฅผ ์ ์ฌ์ ์ผ๋ก ๊ฐ์ ํ๋ ๊ฒ๊ณผ ํจ๊ป ์ด๋ฃจ์ด์ ธ์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
๋ค๋ฅธ ๋ฌธ์ ์ ํ ๋ก ์์ ์ฃผ์์ ๋ชฉ๋ก์ ์ถ์ถํ์ฌ ์ฌ๊ธฐ์ ๋ฃ๋ ๊ฒ์ด ์ข์ต๋๋ค.
@jorisvandenbossche
@MomIsBestFriend #23922์์ ์ด์ ๋ํด ๊ฝค ๋ง์ ํ ๋ก ์ด ์์์ต๋๋ค. ๋ด๊ฐ ๊ฑฐ๊ธฐ์์ ๋งํ๋ฏ์ด ๋ฐ๋ณตํ๊ธฐ ๋๋ฌธ์: ๋๋ ์ฐ๋ฆฌ๊ฐ ๋ชจ๋ ์ค๋ฅ ๋ฉ์์ง๋ฅผ "๋งน๋ชฉ์ ์ผ๋ก" ์ฃผ์ฅํด์ผ ํ๋ค๊ณ ์๊ฐํ์ง ์์ต๋๋ค.
๋๋ ์ ์ ์ผ๋ก ๋์ํ์ง๋ง ๋ฌธ์ ๋ ์ฐ๋ฆฌ๊ฐ ์ฃผ์ฅํ ์ค๋ฅ ๋ฉ์์ง์ ์ฃผ์ฅํ์ง ์์ ๊ฒ์ ๋ํ ๊ท์น์ ์ด๋ป๊ฒ๋ ์ ์ํ๊ณ ๋์์ ์ด ๋ฌธ์ ๋ "์ด๋ณด์ ์นํ์ "์ด๋ฉฐ ํ๋ฅญํ ๊ฒ์ ๋๋ค(IMO).
๋ํ CI์์ ์ด๊ฒ์ ์ํํ ๊ณํ์ด๋ผ๋ฉด bare pytest raises
๊ฐ ์๋์ ์ผ๋ก "๋ฒ ์ด"์ธ ๊ฒ์ ์ด๋ป๊ฒ๋ ํ์ํด์ผ ํฉ๋๋ค( isort: skip
์คํ์ผ์ IMO ์ฃผ์์ด๋ฉด ์ถฉ๋ถํฉ๋๋ค). ์ฌ๋๋ค์ ํน์ bare pytest raise
๊ฐ ์๋์ ์ผ๋ก ๋ฒ ์ด ์๋ค๋ ๊ฒ์ ์๊ฒ ๋ ๊ฒ์
๋๋ค.
๊ทธ ์ค๋ ๋์์ ๋งํ ๋ช ๊ฐ์ง: ๋ด๋ถ ์ค๋ฅ ๋ฉ์์ง๋ก ์ ํํ๊ณ , ๋ฉ์์ง์ ๋ช ๊ฐ์ง ํต์ฌ ๋จ์ด๋ก ์ผ์น๋ฅผ ์ ํํ๊ณ , ๋ณต์กํ ํจํด์ ํผํ์ญ์์ค.
๋ด๋ถ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ํ ์คํธํ๊ณ ์ถ์ง ์์ ์ด์ ๋ฅผ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ๋ ์์ธํ ์ค๋ช ํด ์ฃผ์๊ฒ ์ต๋๊น?
๋๋ ๋น์ ์ด https://github.com/pandas-dev/pandas/issues/23922#issuecomment -458551763์์ ์ง์ ํ ์์ ์ ๋ณด์๊ณ ๋๋ ๊ทธ๊ฒ์ ๋ํด +1
์ด์ง๋ง ๋๋ +2
https://github.com/pandas-dev/pandas/issues/23922#issuecomment -458733117 ๋ฐ https://github.com/pandas-dev/pandas/issues/ ์์ +2
(์ดํด๊ฐ ๋๋ ๊ฒฝ์ฐ) 23922#issuecomment -458735169 IMO์ ์ด์ต์ด ๋น์ฉ๋ณด๋ค ํฌ๊ธฐ ๋๋ฌธ์
๋๋ค.
๋ํ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ์ฃผ์ฅํ๋ ๊ฒ์ ์ค์ ๋ก ๊ทธ๊ฒ์ด ํ๋ฅญํ๊ณ ๋ช ํํ ์ค๋ฅ ๋ฉ์์ง์ธ์ง ํ์ธํ๊ณ ์ด๋ฅผ ์ ์ฌ์ ์ผ๋ก ๊ฐ์ ํ๋ ๊ฒ๊ณผ ํจ๊ป ์ด๋ฃจ์ด์ ธ์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
์ ๋์ ์ผ๋ก ๋์ํฉ๋๋ค.
๋ค๋ฅธ ๋ฌธ์ ์ ํ ๋ก ์์ ์ฃผ์์ ๋ชฉ๋ก์ ์ถ์ถํ์ฌ ์ฌ๊ธฐ์ ๋ฃ๋ ๊ฒ์ด ์ข์ต๋๋ค.
#23922์์ ๋ํ๋ฅผ ์ฝ์์ง๋ง IMO ๊ฐ ๋ฌธ์ ๋ณธ๋ฌธ์ "๋ฉ๋ชจ"๋ก ๋ฃ์ ๊ฐ์น๊ฐ ์๋ ๊ฒ์ ๋ณด์ง ๋ชปํ์ต๋๋ค. ์ ๊ฐ ๋์น ๋ถ๋ถ์ ์ง์ ํด ์ฃผ์๊ฒ ์ต๋๊น?
#23922์์ ๋ํ๋ฅผ ์ฝ์์ง๋ง IMO๊ฐ ๋ฌธ์ ๋ณธ๋ฌธ์ "๋ฉ๋ชจ"๋ก ๋ฃ์ ๊ฐ์น๊ฐ ์๋ ๊ฒ์ ๋ณด์ง ๋ชปํ์ต๋๋ค. ์ ๊ฐ ๋์น ๋ถ๋ถ์ ์ง์ ํด ์ฃผ์๊ฒ ์ต๋๊น?
๊ทธ ๋ฌธ์ ์์ ์ถ๊ฐํ ๋ด์ฉ๋ ๋ณ๋ก ์์ต๋๋ค.
๋๋ ์ ์ ์ผ๋ก ๋์ํ์ง๋ง ๋ฌธ์ ๋ ์ฐ๋ฆฌ๊ฐ ์ฃผ์ฅํ ์ค๋ฅ ๋ฉ์์ง์ ์ฃผ์ฅํ์ง ์์ ๊ฒ์ ๋ํ ๊ท์น์ ์ด๋ป๊ฒ๋ ์ ์ํ๊ณ ๋์์ ์ด ๋ฌธ์ ๋ "์ด๋ณด์ ์นํ์ "์ด๋ฉฐ ํ๋ฅญํ ๊ฒ์ ๋๋ค(IMO).
๋ํ, CI์์ ์ด๊ฒ์ ์ํํ ๊ณํ์ด๋ผ๋ฉด, ๋ฒ ์ด pytest๊ฐ ์ ๊ธฐํ๋ ๊ฒ์ด ์๋์ ์ผ๋ก "๋ฒ ์ด"์ธ ๊ฒ์ ์ด๋ป๊ฒ๋ ํ์ํด์ผ ํ๋ฉฐ(isort ์คํ์ผ์ IMO ์ฃผ์: ๊ฑด๋๋ฐ๊ธฐ๊ฐ ์ถฉ๋ถํจ), ๋ค๋ฅธ ์ฌ๋๋ค๋ ํน์ ๋ฒ ์ด pytest ์ธ์์ ์๋์ ์ผ๋ก ๋ฒ ์ด ์์ต๋๋ค.
ํ
์คํธํ ํญ๋ชฉ๊ณผ ํ
์คํธํ์ง ์์ ํญ๋ชฉ์ ์ ํํ๊ณ ์ ํํ๋ ๊ฒ์ด ๋ด๊ฐ ์ ํธํ๋ ๋ฐฉํฅ์ด ์๋ ๋ถ๋ถ์ ์ธ ์ด์ ์
๋๋ค. ๋ํ ๋๋๋ก except
๋ธ๋ก์์ ์ค๋ฅ ๋ฉ์์ง ๋ฌธ์์ด์ ํ์ธํ๋ฏ๋ก ์ข์ ์ค๋ฅ ๋ฉ์์ง๋ ๊ฐ๋ฐ ์ค์๋ ๋์์ด ๋๋ค๊ณ ๋ง๋ถ์์ต๋๋ค.
๋ํ ์ด๋ฌํ "๋ด๋ถ" ๋ฉ์์ง๊ฐ ๊ทธ๋ค์ง ์ค์ํ์ง ์์ ๊ฒฝ์ฐ ์ฒ์์ ์ค๋ฅ ๋ฉ์์ง๊ฐ ํ์๋๋ ์ด์ ๋ ๋ฌด์์ ๋๊น? ๊ทธ๋ฐ ๋ค์ ๋ฉ์์ง๊ฐ ๋น์ด ์๋ค๊ณ ์ฃผ์ฅํ๋ ๋์ฐ๋ฏธ๋ฅผ ๋ง๋ญ๋๋ค.
๋ด๋ถ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ํ ์คํธํ๊ณ ์ถ์ง ์์ ์ด์ ๋ฅผ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ๋ ์์ธํ ์ค๋ช ํด ์ฃผ์๊ฒ ์ต๋๊น?
๊ทธ๋์ ์ ๋ "๋ด๋ถ ์ค๋ฅ ๋ฉ์์ง๋ก ์ ํ"์ด๋ผ๊ณ ๋งํ์ง๋ง "๋ด๋ถ"๋ ์ฝ๊ฐ ๋ชจํธํ ์ ์์ต๋๋ค... ์ ๋ง์: ํฌ๋ ์์ฒด์์ ๋ฐ์ํ๋ ์ค๋ฅ ๋ฉ์์ง์ด๊ณ ๋ฌผ๋ก ํ ์คํธํ๋ ค๋ ๊ฒ์ ๋๋ค. ํ์ง๋ง ๊ทธ๋์ ๋๋ ์ฐ๋ฆฌ(IMO)๊ฐ ๋๋ฌด ๋ง์ ์ธ๋ถ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ํ ์คํธํด์๋ ์ ๋๋ค๋ ๊ฒ์ ์๋ฏธํ์ต๋๋ค. ์ฆ, numpy ๋๋ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์ค๋ ๋ฉ์์ง์ ๋๋ค. Numpy๋ ๊ทธ๊ฒ๋ค์ ๋ณ๊ฒฝํ ์ ์์ผ๋ฉฐ, ์ฐ๋ฆฌ์ ํ ์คํธ๋ numpy์ ์ธ๊ด์์ ๋ณ๊ฒฝ์ผ๋ก ์ธํด ์คํจํ๊ธฐ ์์ํฉ๋๋ค(์ด๊ฒ์ ๊ฐ์ค์ด ์๋๋ฉฐ ์ง๋์ฃผ์ ์ผ์ด๋ ์ผ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค).
์ด์ https://github.com/pandas-dev/pandas/pull/30998#discussion_r366726966 ์ ๋ค๋ฅธ ์ปจํ ์คํธ์์ "๋ด๋ถ"๋ฅผ ์ฌ์ฉํ์ต๋๋ค ์ ๋ ๋ฐ์ํด์๋ ์ ๋๋ ๋ด๋ถ, ๊ฐ๋ฐ์ ์งํฅ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ์๋ฏธํ์ต๋๋ค. IMO, ์ค๋ฅ ๋ฉ์์ง๋ก ์ ํํ๊ฒ ํ ์คํธํ๋ ๋ฐ ์ค์ํ์ง ์์ต๋๋ค.
๋๋ ๋น์ ์ด #23922(๋๊ธ)์์ ์ง์ ํ ์์ ์ ๋ณด์๊ณ ๋๋ ๊ทธ๊ฒ์ ๋ํด +1์ด์ง๋ง #23922(๋๊ธ)๊ณผ #23922(๋๊ธ)์ ๋ํด์๋ +2(์๋ฏธ๊ฐ ์๋ค๋ฉด)์ ๋๋ค. ์๋ํ๋ฉด IMO ์ด์ต์ด ๋น์ฉ๋ณด๋ค ํฝ๋๋ค.
์ฌ๊ธฐ์ ๋งํฌํ๋ @simonjayhawkins ์ ์๊ฒฌ์ ๋ฃ์ด ๋ณด๊ฒ ์ต๋๋ค.
๋๋ ๊ทธ๊ฒ์ด ๋ค์๊ณผ ๊ฐ์ ๊ฒฝ์ฐ์ ๋์์ด ๋ ๊ฒ์ด๋ผ๋ ๊ฐ์ ์ ํ๊ณ ์์ต๋๋ค.
- ๋งค๊ฐ๋ณ์ํํ ์ ์๋ ํ ์คํธ ์๋ณ
- ๋ถํ ํด์ผ ํ๋ ํ ์คํธ ์๋ณ
- ํ ์คํธ๋ ๊ณ ์ฅ ๋ชจ๋์ ๋ํ ๋ ๋์ ์ดํด
- ํ ์คํธ์ ๊ฐ์ ์ ์ผ๋ก ๋ ๋ง์ ๋ฌธ์ ์ถ๊ฐ
- ์ค๋ฅ ๋ฉ์์ง์ ์ผ๊ด์ฑ์ ๋์ผ ์ ์๋ ์์น ์๋ณ
- ์ค๋ณต๋๋ ํ ์คํธ ์๋ณ
- ์ค๋ฅ ๋ฉ์์ง ๊ฐ์ ์ ๋์
- ์๋ชป๋ ์ด์ ๋ก ํ์ฌ ํต๊ณผ ์ค์ธ ํ ์คํธ๋ฅผ ์๋ณํฉ๋๋ค.
๋ชจ๋ ์ ์ฉํ ๋ด์ฉ์ ๋๋ค. ์ ์ ์ผ๋ก ๋์ํฉ๋๋ค. ๊ทธ๋ฌ๋ ๊ทธ๊ฒ์ ๊ฐ๋จํ์ง ์์ผ๋ฉฐ ์ฐ๋ฆฌ๊ฐ ์ด ๋ฌธ์ ์์ ๊ทธ๋ฐ ๊ฒ๋ค์ ์ป๊ณ ์ ํ๋ค๋ฉด ์ด ๋ฌธ์ ๋ ์ด๋ณด์๋ฅผ ์ํ ๊ฒ์ด ์๋๋๋ค. ๋ฌผ๋ก ์ด๋ณด์๋ ์ด ๋ชจ๋ ์์ ์ ํ ๋ฒ์ ์ํํ ํ์๊ฐ ์์ง๋ง ์ฃผ์ฅ์ ์ถ๊ฐํ๋ PR์ด ์๋ฌด ์์ ๋ ์ํํ์ง ์๊ณ "ํ์ฌ ์ค๋ฅ ๋ฉ์์ง๋ฅผ pytest.raises ํธ์ถ์ ๋งน๋ชฉ์ ์ผ๋ก ์ถ๊ฐ"ํ๋ ๊ฒฝ์ฐ๊ฐ ์ข ์ข ์๋ค๋ ๋๋์ด ๋ญ๋๋ค. ๋ ๋์๊ฐ(์์ ์ฌํญ).
๋ํ, ์์ ์ฌํญ๋ค์ด ์ด ์ฐ์ต์ ์ ์ฉํ๊ฒ ๋ง๋ ๋ค๋ฉด, ์ด ๋ฌธ์ ์ ๋งจ ์์ ๋๋ ๊ฒ์ด ์ ์ฉํ ์ด์ ๋ํ ๋ณด๋ค ๊ตฌ์ฒด์ ์ธ ์ง์นจ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.
๋ถ๋ช
ํ ํ์๋ฉด, ์ ๋ ๋ ๋์ ์ค๋ฅ ๋ฉ์์ง์ ๋ ๋์ ํ
์คํธ๋ฅผ ํตํด ์ด๋ฌํ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ์
IMO, ๋์ "์ค๋ฅ ๋ฉ์์ง ๊ฐ์ "์ ์ด์ ์ ๋ง์ถ๋ ๊ฒ๋ณด๋ค "๋ฒ ์ด pytest ๋ฐ์ ์์ "์ ์ด์ ์ ๋ง์ถ๋ ๊ฒ์ด ๋ ์ ์ฉํ ๊ฒ์
๋๋ค(์ด๋ ๊ฒ ํ๋ ๋์ ๋ ์ ํ
์คํธ).
๋ํ, ์์ ์ฌํญ๋ค์ด ์ด ์ฐ์ต์ ์ ์ฉํ๊ฒ ๋ง๋ ๋ค๋ฉด, ์ด ๋ฌธ์ ์ ๋งจ ์์ ๋๋ ๊ฒ์ด ์ ์ฉํ ์ด์ ๋ํ ๋ณด๋ค ๊ตฌ์ฒด์ ์ธ ์ง์นจ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.
์ด๋ฅผ ์ถ์ ํ๊ธฐ ์ํด ๋ ํฐ ๋ฌธ์ ๋ฅผ ๋ง๋๋ ๊ฒ์ด ํฉ๋ฆฌ์ ์ผ ์ ์์ต๋๋ค(์ด๋ฌํ ๋ฌธ์ ์ ํฌํจํ ๊ฐ์น๊ฐ ์๋ ๋ค๋ฅธ ๋ฌธ์ ๋ https://github.com/pandas-dev/pandas/issues/19159 ๋ฐ https://github.com/pandas-์ ๋๋ค. dev/pandas/issues/21575).
์ด ๋ถ๋ถ ์์ฒด๊ฐ ๋ ๋ฆฝ์ ์ด๋ฉฐ ์ด๋ณด์๊ฐ ์ ๊ทผํ๊ธฐ ๋งค์ฐ ์ฝ์ต๋๋ค.
@gfyoung ์ด ํ ๋ก ๊ณผ ๊ด๋ จํ์ฌ ๋งํฌํ ๋ฌธ์ ๋ ์ด๋ป์ต๋๊น?
@simonjayhawkins ์์ ๋ช ์์ ์ผ๋ก ์๊ฐํ ๋๊ธ๊ณผ ๊ด๋ จ์ด ์์ต๋๋ค.
stata.py
์ ํ๋์ ๋๋ฝ๋ ์ผ์น ํญ๋ชฉ์ด ์์ต๋๋ค.์ฌ๊ธฐ์์ ๋งํ๋ฏ์ด https://github.com/pandas-dev/pandas/pull/31091#issuecomment -575422207 ์ ๋ @jorisvandenbossche ์ ์์ด๋์ด์
ํน์ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ํ ์คํธํ๊ณ ์ถ์ง ์๋ค๋ฉด(์ธ๋ถ ๋ฉ์์ง์ ๋ํด ์ด๋ ์ชฝ์ด๋ ๊ณต์ ํ๊ฒ ์งํํ ์ ์์) ๋ค์๊ณผ ๊ฐ์ ๋์ฐ๋ฏธ ํจ์๋ฅผ ๋ง๋ค์ด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
~ํ์ด์ฌdef ์ธ๋ถ ์ค๋ฅ ๋ฐ์(์์_์์ธ):๋ฐํ pytest.raises(์์_์์ธ, ์ผ์น=์์)~
์ด๊ฒ์ ์ด๊ฒ์ด ํฌ๋๊ฐ ์๋ ์ค๋ฅ๋ผ๋ ๊ฒ์ ์ฐ๋ฆฌ์ ๋ฏธ๋ ์์์๊ฒ ๋ถ๋ช
ํ ํ ๊ฒ์ด๋ฉฐ match=None
๋ ์ฐ๋ฆฌ๊ฐ ๋ฒ๊ฑฐ๋ฒ์ pytest
์ธ์์ ์ํด ๊ฐ๋ฐํ ๋ชจ๋ ๋ฆฐํธ ๊ฒ์ฌ๋ฅผ ์ง์ ์ํค๋ ์ญํ ์ ํฉ๋๋ค.
ํน์ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ํ ์คํธํ๊ณ ์ถ์ง ์๋ค๋ฉด(์ธ๋ถ ๋ฉ์์ง์ ๋ํด ์ด๋ ์ชฝ์ด๋ ๊ณต์ ํ๊ฒ ์งํํ ์ ์์) ๋ค์๊ณผ ๊ฐ์ ๋์ฐ๋ฏธ ํจ์๋ฅผ ๋ง๋ค์ด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
def external_error_raised(expected_exception): return pytest.raises(expected_exception, match=None)
์ด๊ฒ์ ์ด๊ฒ์ด ํฌ๋๊ฐ ์๋ ์ค๋ฅ๋ผ๋ ๊ฒ์ ์ฐ๋ฆฌ์ ๋ฏธ๋ ์์์๊ฒ ๋ช ๋ฐฑํ๊ฒ ํ ๊ฒ์ด๋ฉฐ
match=None
๋ ์ฐ๋ฆฌ๊ฐ ๋ฒ๊ฑฐ๋ฒ์pytest
์ธ์์ ์ํด ๊ฐ๋ฐํ ๋ชจ๋ ๋ณดํ ํ์ธ์ ์ง์ ์ํค๋ ์ญํ ์ ํฉ๋๋ค.
+1
.
๋๋ ๊ทธ ์์ด๋์ด๊ฐ ์ ๋ง ๋ง์์ ๋ญ๋๋ค. ์ฐ๋ฆฌ ํ ์คํธ๋ฅผ ์ํ ๊ด๋ก๋ก ๋ง๋ค ์ ์์ต๋๊น?
ํจ์/๋ฉ์๋์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋์ง ํ
์คํธํ๋ ์ค์ด๊ณ ์ค๋ฅ๊ฐ ์ธ๋ถ ์ค๋ฅ์ธ ๊ฒฝ์ฐ "pytest.raises```์ match=None
๋ฅผ ๋ฃ์ผ๋ฉด ๋ฉ๋๋ค.
ํ ์คํธ๋ฅผ ์ํ ๊ท์น์ผ๋ก ๋ง๋ค ์ ์์ต๋๊น?
๊ทธ ๋ง์ ๊ธฐ์ฌ ๊ฐ์ด๋ ์ ์น์ ์ ๋ฃ๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค.
ํจ์/๋ฉ์๋์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋์ง ํ ์คํธํ๋ ์ค์ด๊ณ ์ค๋ฅ๊ฐ ์ธ๋ถ ์ค๋ฅ์ธ ๊ฒฝ์ฐ "pytest.raises```์ match=None์ ๋ฃ์ผ๋ฉด ๋ฉ๋๋ค.
๋๋ ๋น์ ์ด ๊ทธ๊ฒ์ ์ถ๊ฐํ๋ ๊ฒ์ ๋ํด ์๊ฐํ ํ์๊ฐ ์๊ธฐ ๋๋ฌธ์ ๋์ฐ๋ฏธ ๊ธฐ๋ฅ์ ์ ํธํฉ๋๋ค. ๋ํ ๋์ฐ๋ฏธ ์ด๋ฆ์ ์ฐ๋ฆฌ๊ฐ ์ ํ๋์ง์ ๋ํด ํจ์ฌ ๋ ๋ช ํํฉ๋๋ค.
ํน์ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ํ ์คํธํ๊ณ ์ถ์ง ์๋ค๋ฉด(์ธ๋ถ ๋ฉ์์ง์ ๋ํด ์ด๋ ์ชฝ์ด๋ ๊ณต์ ํ๊ฒ ์งํํ ์ ์์) ๋ค์๊ณผ ๊ฐ์ ๋์ฐ๋ฏธ ํจ์๋ฅผ ๋ง๋ค์ด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
def external_error_raised(expected_exception): return pytest.raises(expected_exception, match=None)
์ด๊ฒ์ ์ด๊ฒ์ด ํฌ๋๊ฐ ์๋ ์ค๋ฅ๋ผ๋ ๊ฒ์ ์ฐ๋ฆฌ์ ๋ฏธ๋ ์์์๊ฒ ๋ช ๋ฐฑํ๊ฒ ํ ๊ฒ์ด๋ฉฐ
match=None
๋ ์ฐ๋ฆฌ๊ฐ ๋ฒ๊ฑฐ๋ฒ์pytest
์ธ์์ ์ํด ๊ฐ๋ฐํ ๋ชจ๋ ๋ณดํ ํ์ธ์ ์ง์ ์ํค๋ ์ญํ ์ ํฉ๋๋ค.
@gfyoung ์ด ๋์ฐ๋ฏธ ๊ธฐ๋ฅ์ ์ด๋์ ๋๋ ๊ฒ์ด ์ข์ต๋๊น? (์ด๋ค ํ์ผ์ ์๋ ๊ฒ์ฒ๋ผ?)
pandas._testing
์๋ ํ์ญ๋๊น,
๋ค์ ์์ ์ ํ๊ณ ์ถ์ต๋๋ค.
ํฌ๋/ํ
์คํธ/๋ฐฐ์ด/๊ฐ๊ฒฉ/test_ops.py
ํฌ๋/ํ
์คํธ/๋ฐฐ์ด/test_array.py
ํฌ๋/ํ
์คํธ/๋ฐฐ์ด/test_boolean.py
์๋ ํ์ธ์ - ์ ๋ ๋ค์๊ณผ ๊ฐ์ ์ผ์ ํ๊ณ ์ถ์ต๋๋ค.
ํฌ๋/ํ
์คํธ/์ฐ์ /test_period.py
ํฌ๋/ํ
์คํธ/์ฐ์ /test_timedelta64.py
์๋ ํ์ธ์ ์ฌ๋ฌ๋ถ, ๋ค์๊ณผ ๊ฐ์ด ํ๊ฒ ์ต๋๋ค.
ํฌ๋/ํ
์คํธ/๊ณ์ฐ/test_compat.py
ํฌ๋/ํ
์คํธ/๊ณ์ฐ/test_eval.py
ํฌ๋/ํ
์คํธ/dtypes/cast/test_upcast.py
ํฌ๋/ํ
์คํธ/dtypes/test_dtypes.py
@MomIsBestFriend ์ด๊ฒ์ ์ด๋ฏธ ์๋ฃ๋์์ง๋ง ์๋ฃ๋ก ํ์๋์ง ์์์ต๋๋ค.
ํฌ๋/ํ
์คํธ/์ฐ์ /test_numeric.py
@MomIsBestFriend ์ด๊ฒ๋ค๋:
ํฌ๋/ํ
์คํธ/์ฐ์ /test_period.py
ํฌ๋/ํ
์คํธ/๋ฐฐ์ด/test_integer.py
ํฌ๋/ํ
์คํธ/๋ฐฐ์ด/test_period.py
์ด๋ค์ #31852์ ํฌํจ๋์ด ์์ต๋๋ค.
ํฌ๋/tests/extension/decimal/test_decimal.py
ํฌ๋/ํ
์คํธ/ํ์ฅ/json/test_json.py
ํฌ๋/ํ
์คํธ/ํ์ฅ/test_boolean.py
ํฌ๋/ํ
์คํธ/ํ์ฅ/test_categorical.py
ํฌ๋/ํ
์คํธ/ํ๋ ์/์ธ๋ฑ์ฑ/test_categorical.py
ํฌ๋/ํ
์คํธ/ํ๋ ์/์ธ๋ฑ์ฑ/test_indexing.py
ํฌ๋/ํ
์คํธ/ํ๋ ์/์ธ๋ฑ์ฑ/test_where.py
ํฌ๋/ํ
์คํธ/ํ๋ ์/๋ฉ์๋/test_explode.py
ํฌ๋/ํ
์คํธ/ํ๋ ์/๋ฉ์๋/test_isin.py
ํฌ๋/ํ
์คํธ/ํ๋ ์/๋ฉ์๋/test_quantile.py
ํฌ๋/ํ
์คํธ/ํ๋ ์/๋ฉ์๋/test_round.py
ํฌ๋/ํ
์คํธ/ํ๋ ์/๋ฉ์๋/test_sort_values.py
ํฌ๋/ํ
์คํธ/ํ๋ ์/๋ฉ์๋/test_to_dict.py
๋ด๊ฐ ๊ฐ์ ธ๊ฐ๊ฒ
ํฌ๋/ํ
์คํธ/io/excel/test_readers.py
ํฌ๋/ํ
์คํธ/io/excel/test_writers.py
ํฌ๋/ํ
์คํธ/io/excel/test_xlwt.py
ํฌ๋/ํ
์คํธ/io/formats/test_format.py
ํฌ๋/tests/io/formats/test_style.py
ํฌ๋/tests/io/formats/test_to_latex.py
@MomIsBestFriend
๋ค์์ ํ์ ์์ด ์ํ๋ฉ๋๋ค.
pandas/tests/indexes/datetimes/test_tools.py๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค
๋ด๊ฐ ํ ๊ฑฐ์ผ:
pytest raises
๋ฅผ ๊ฐ์งํ๋ ์คํฌ๋ฆฝํธ๊ฐ ์์ผ๋ฏ๋ก ์๋ณธ ๊ฒ์๋ฌผ์ ์
๋ฐ์ดํธํ์ต๋๋ค. ์ฌ์ฉ ๋ฐฉ๋ฒ์ ๋ํ ์ง์นจ์ด ํฌํจ๋์ด ์์ต๋๋ค. ์ฌ์ ํ ์ง๋ฌธ์ด ์๋ ์ฌ๋์ด ์์ผ๋ฉด ์ธ์ ๋ ์ง ๋ฌผ์ด๋ณผ ์ ์์ต๋๋ค. :)
๋ด๊ฐ ๊ฐ์ ธ๊ฐ๊ฒ,
ํฌ๋/ํ ์คํธ/์ฐ์ /test_timedelta64.py
ํฌ๋/ํ
์คํธ/์ค์นผ๋ผ/ํ์์คํฌํ/test_arithmetic.py
ํฌ๋/ํ
์คํธ/์ค์นผ๋ผ/ํ์์คํฌํ/test_comparisons.py
ํฌ๋/ํ
์คํธ/์ค์นผ๋ผ/ํ์์คํฌํ/test_constructors.py
ํฌ๋/ํ
์คํธ/์ค์นผ๋ผ/ํ์์คํฌํ/test_timezones.py
ํฌ๋/ํ
์คํธ/์ค์นผ๋ผ/ํ์์คํฌํ/test_unary_ops.py
pandas/tests/scalar/timestamp/์ ๋ชจ๋ ํ ์คํธ๊ฐ ์ด๋ฏธ ์์ ๋ ๊ฒ ๊ฐ์ต๋๋ค.
$ git checkout master
Already on 'master'
$ python scripts/validate_unwanted_patterns.py -vt="bare_pytest_raises" pandas/tests/scalar/timestamp/
$
pandas/tests/arrays/test_boolean.py =>์ด(๊ฐ) ์์ต๋๋ค.
๋ด๊ฐ ์ฑ๊ธธ๊ฑฐ๋ค
ํฌ๋/ํ
์คํธ/๋ฐฐ์ด/๊ฐ๊ฒฉ/test_ops.py
ํฌ๋/ํ
์คํธ/๋ฐฐ์ด/test_datetimelike.py
ํฌ๋/tests/groupby/test_categorical.py
ํฌ๋/tests/groupby/test_groupby.py
ํฌ๋/tests/groupby/test_timegrouper.py
ํฌ๋/ํ ์คํธ/์ฐ์ /test_timedelta64.py => #33010
pandas/tests/scalar/timestamp/test_arithmetic.py => ๋ฌธ์ ์์
pandas/tests/scalar/timestamp/test_comparisons.py => ๋ฌธ์ ์์
pandas/tests/scalar/timestamp/test_constructors.py => ๋ฌธ์ ์์
pandas/tests/scalar/timestamp/test_timezones.py => ๋ฌธ์ ์์
pandas/tests/scalar/timestamp/test_unary_ops.py => ๋ฌธ์ ์์
pandas/tests/arrays/test_boolean.py =>์ด(๊ฐ) ์์ต๋๋ค.
pandas/tests/arrays/interval/test_ops.py => #33010
ํฌ๋/ํ
์คํธ/๋ฐฐ์ด/test_datetimelike.py => #33010
pandas/tests/groupby/test_categorical.py => #33144
pandas/tests/groupby/test_groupby.py => ๋ฌธ์ ์์
pandas/tests/groupby/test_timegrouper.py => ๋ฌธ์ ์์
pandas/tests/indexes/categorical/test_category.py => ๋ฌธ์ ์์
ํฌ๋/ํ
์คํธ/์ธ๋ฑ์ค/common.py #33144
ํฌ๋/ํ
์คํธ/์ธ๋ฑ์ค/datetimelike.py #33144
pandas/tests/indexes/interval/test_astype.py => ์ํฅ์ ๋ฐ๋ ๋ชจ๋ ํ ์คํธ๊ฐ xfailed๋ก ํ์๋ฉ๋๋ค. ์ฌ์ ํ ์์ ํด์ผ ํฉ๋๊น? ์ด๋ป๊ฒ ํฉ๋๊น?
pandas/tests/indexes/multi/test_compat.py #33144
pandas/tests/indexes/multi/test_duplicates.py => ๋ฌธ์ ์์
pandas/tests/indexes/multi/test_format.py => ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค.
pandas/tests/indexes/multi/test_reshape.py #33144
pandas/tests/indexes/multi/test_setops.py => ๋ฌธ์ ์์
pandas/tests/indexes/multi/test_sorting.py #33144
@sumanau7 ์ฌ์ฉ ์ค์ธ ํ์ผ์ ๋์ดํ์ต๋๊น? ๋ณํฉ๋ ํ์ผ ์ค ์ผ๋ถ๋ฅผ ์์ ์ค์ ๋๋ค.
์๋ฃ
pandas/tests/indexes/categorical/test_category.py
pandas/tests/indexes/period/test_constructors.py
pandas/tests/indexes/period/test_join.py
pandas/tests/indexes/period/test_partial_slicing.py
pandas/tests/indexes/period/test_setops.py
pandas/tests/indexes/timedeltas/test_delete.py
๋๋ ํจ๊ป ์ผํ๊ณ ์๋ค
pandas/tests/indexes/ranges/test_constructors.py
ํฌ๋/ํ
์คํธ/์ธ๋ฑ์ค/๋ฒ์/test_range.py
ํฌ๋/ํ
์คํธ/์ธ๋ฑ์ฑ/๋ค์ค ์ธ๋ฑ์ค/test_chaining_and_caching.py
ํฌ๋/ํ
์คํธ/์ธ๋ฑ์ฑ/๋ค์ค ์ธ๋ฑ์ค/test_partial.py
ํฌ๋/ํ
์คํธ/์๋ฆฌ์ฆ/์ธ๋ฑ์ฑ/test_alter_index.py
ํฌ๋/ํ
์คํธ/๋ฐฐ์ด/๋ถ์ธ/test_function.py
์์ :
pandas/tests/reshape/merge/test_multi.py
๋ด๊ฐ ๊ฑธ๋ฆด ๊ฒ์
๋๋ค:
ํฌ๋/ํ
์คํธ/์ฐฝ/์๊ฐ/test_moments_ewm.py
ํฌ๋/tests/window/moments/test_moments_rolling.py
ํฌ๋/ํ
์คํธ/์ฐฝ/test_dtypes.py
ํฌ๋/ํ
์คํธ/์ฐฝ/test_ewm.py
ํฌ๋/ํ
์คํธ/์ฐฝ/test_expanding.py
ํฌ๋/tests/window/test_timeseries_window.py
๋ํ ๋ค์์ ์ทจํฉ๋๋ค.
์๋
ํ์ธ์,
์ ๋ ์ด ํ๋ก์ ํธ์ ์๋ก์ด ๊ฐ๋ฐ์์ด๋ฉฐ ์ด ๋ฌธ์ ๋ฅผ ๋๊ณ ์ถ์ต๋๋ค. ๋๋จธ์ง ํ
์คํธ ์ค ์ด๋ณด์์๊ฒ ๊ฐ์ฅ ์ ํฉํ ํ
์คํธ๋ ๋ฌด์์
๋๊น?
๊ฐ์ฌ ํด์,
์ผ๋น
์๋ ํ์ธ์,
์ ๋ ์ด ํ๋ก์ ํธ์ ์๋ก์ด ๊ฐ๋ฐ์์ด๋ฉฐ ์ด ๋ฌธ์ ๋ฅผ ๋๊ณ ์ถ์ต๋๋ค. ๋๋จธ์ง ํ ์คํธ ์ค ์ด๋ณด์์๊ฒ ๊ฐ์ฅ ์ ํฉํ ํ ์คํธ๋ ๋ฌด์์ ๋๊น?๊ฐ์ฌ ํด์,
์ผ๋น
ํ์ํฉ๋๋ค - ์ด ์ค ์ด๋ ๊ฒ๋ ๋ค๋ฅธ ๊ฒ๋ณด๋ค ์ฝ๊ฑฐ๋ ์ด๋ ต์ง ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ์์ํ๊ธฐ์ ์ข์ ๊ณณ์ด ๋ ๊ฒ์ ๋๋ค.
validate_unwanted_patterns.py ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๋ ๋์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
Traceback (most recent call last):
File "C:\Users\Kevom\git\pandas\scripts\validate_unwanted_patterns.py", line 397, in <module>
main(
File "C:\Users\Kevom\git\pandas\scripts\validate_unwanted_patterns.py", line 352, in main
for line_number, msg in function(file_obj):
File "C:\Users\Kevom\git\pandas\scripts\validate_unwanted_patterns.py", line 88, in bare_pytest_raises
contents = file_obj.read()
File "C:\Program Files (x86)\Python\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 76843: character maps to <undefined>
'pandas/tests/test_strings.py'๋ฅผ ์ฝ์ ๋ ๋ฐ์ํฉ๋๋ค. ๋ชจ๋ ํ์ผ์ cp1252๋ก ์ธ์ฝ๋ฉ๋ฉ๋๋ค.
์ค๋ณต ์์ ์ ํผํ๊ธฐ ์ํด ์์ง ์๋ฃ๋์ง ์์ ํ ์คํธ๋ฅผ ๋ค์ ํ์ธํ๊ธฐ ์ํด ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๊ณ ์ถ์์ต๋๋ค.
๋๋ถ๋ถ์ NotImplementedError
์๋ ์ผ์น์ํฌ ํน์ ๋ฉ์์ง๊ฐ ์์ต๋๋ค. ๋ชฉ์ ์ ์ด๊ธ๋๋ค๋ ๊ฒ์ ์๊ณ ์์ง๋ง ๋ฆฐํฐ๋ฅผ ์นจ๋ฌต์ํค๊ธฐ ์ํด pytest.raises(NotImplementedError, match=None)
๋ก ๋ณ๊ฒฝํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ?
๋ด๊ฐ ๊ฑธ๋ฆด ๊ฒ์ ๋๋ค:
์์ํ๋ค.
- ์ผ๋น
๋๋ ์ด๊ฒ์ ์ต์ํ์ง ์์ผ๋ฏ๋ก ๋ค์๊ณผ ๊ฐ์ด ์์ํ ๊ฒ์ ๋๋ค.
์๋
ํ์ธ์, ์ ๋ ๊ธฐ์ฌ์ ์ฒ์์
๋๋ค. ๋ฌธ์ ์ ๋ํด ๋ช
ํํ๊ฒ ์์ฑํด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. pandas/tests/generic/test_duplicate_labels.py
๋ถํฐ ์์ํ๊ณ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋๋ฉด ๋ช ๊ฐ์ง ๋ ๋ค๋ฃฐ ๊ฒ์
๋๋ค.
๋๋ pandas/tests/arrays/test_datetimelike.py๋ฅผ ์์์ผ๋ก ์ฌ์ฉํ ๊ฒ์
๋๋ค.
๋ํ python scripts/validate_unwanted_patterns.py -vt="bare_pytest_raises" pandas/tests/
์ฑ๊ณต์ ์ผ๋ก ์คํํ ์ ์์ผ๋ฉด ๋ค์์ ์๋ํ์ญ์์ค.
๋์ python scripts/validate_unwanted_patterns.py -vt="bare_pytest_raises" pandas/tests/**/*.py
์ง๊ธ ์คํํ๋ ๊ฐ์ฅ ์ฌ์ด ๋ฐฉ๋ฒ์ ๋ค์์ ์ถ๊ฐํ๋ ๊ฒ์ ๋๋ค.
- id: unwanted-patterns-bare-pytest-raises
name: Check for use of bare use of pytest raises
language: python
entry: python scripts/validate_unwanted_patterns.py --validation-type="bare_pytest_raises"
types: [python]
files: ^pandas/tests/
- repo: local
์น์
์์ .pre-commit-config.yaml
๋ก ๋ณ๊ฒฝํ ๋ค์ ์คํ
pre-commit run unwanted-patterns-bare-pytest-raises --all-files.
๋๋จธ์ง ๋ฏธํด๊ฒฐ ํ์ผ๋ก ๋ฌธ์ ๋ฅผ ์ ๋ฐ์ดํธํ์ต๋๋ค.
๋๋ ์ด๊ฒ์ ๊ฐ์ง๊ณ ๊ฐ ์ ์๋ค:
์ด๋ค์ ์ค๋ ํ์ฌ ๋ชฉ๋ก์์ ์์ 5๊ฐ์ ๋๋ค.
@marktgraham ์์ง test_datetime.py
์ ํ์ง ์์๋ค๋ฉด. PR์ ํ๋ ค๊ณ ํ๋ ๊ทธ๋ฅ ๋์ธ์.
@liaoaoyuan97 ๊ฑฑ์ ํ์ง ๋ง์ธ์. ์์ง test_datetimelike.py
๊ฑด๋๋ฆฌ์ง ์์์ต๋๋ค.
๋์ pandas/tests/extension/base/getitem.py๋ฅผ ์ฌ์ฉํ๊ฒ ์ต๋๋ค.
validate_unwanted_patterns.py
๋ด ์ชฝ์์ ์ค๋ฅ ๋ฐ์
$ python scripts/validate_unwanted_patterns.py -vt="bare_pytest_raises" pandas/tests/
Traceback (most recent call last):
File "scripts/validate_unwanted_patterns.py", line 479, in <module>
output_format=args.format,
File "scripts/validate_unwanted_patterns.py", line 435, in main
with open(file_path, encoding="utf-8") as file_obj:
IsADirectoryError: [Errno 21] Is a directory: 'pandas/tests/'
์๋ง๋ #37419์ ๊ด๋ จ์ด ์๋ ๊ฒ ๊ฐ์๋ฐ์?
@MarcoGorelli๊ฐ ์ ์ํ ์ ๊ทผ ๋ฐฉ์์ ์๋ํ๊ณ ์๋ฒฝํ๊ฒ ์๋ํ์ต๋๋ค.
์ง๊ธ ์คํํ๋ ๊ฐ์ฅ ์ฌ์ด ๋ฐฉ๋ฒ์ ๋ค์์ ์ถ๊ฐํ๋ ๊ฒ์ ๋๋ค.
- id: unwanted-patterns-bare-pytest-raises name: Check for use of bare use of pytest raises language: python entry: python scripts/validate_unwanted_patterns.py --validation-type="bare_pytest_raises" types: [python] files: ^pandas/tests/
- repo: local
์น์ ์์.pre-commit-config.yaml
๋ก ๋ณ๊ฒฝํ ๋ค์ ์คํpre-commit run unwanted-patterns-bare-pytest-raises --all-files.
์ด๊ฒ์ .pre-commit-config.yaml
์ ์ถ๊ฐํ ๋ค์ ์ด ์ค๋ ๋์ ์ง์นจ์ ์
๋ฐ์ดํธํ๋ ๊ฒ์ด ํฉ๋ฆฌ์ ์
๋๊น?
์ด๊ฒ์ .pre-commit-config.yaml์ ์ถ๊ฐํ ๋ค์ ์ด ์ค๋ ๋์ ์ง์นจ์ ์ ๋ฐ์ดํธํ๋ ๊ฒ์ด ์๋ฏธ๊ฐ ์์ต๋๊น?
๋ฐ์ํ๋ ๋ชจ๋ ์ค๋ฅ๊ฐ ์์ ๋๋ฉด .pre-commit-config.yaml
์ถ๊ฐํฉ๋๋ค. ์
์๋ง๋ #37419์ ๊ด๋ จ์ด ์๋ ๊ฒ ๊ฐ์๋ฐ์?
์๋์, #37379์ ๊ด๋ จ์ด ์์ต๋๋ค(์ด ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ ์ปค๋ฐ์ผ๋ก ์ฎ๊ฒผ์ผ๋ฏ๋ก ๋ ์ด์ ๋๋ ํฐ๋ฆฌ์์ ์คํํ ํ์๊ฐ ์์์ต๋๋ค)