Skip to content

Commit 786bfd9

Browse files
authored
TST: show_versions test with unmerged commits (#32139)
1 parent 2eca9e8 commit 786bfd9

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

pandas/tests/util/test_show_versions.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
import re
22

3+
import pytest
4+
35
import pandas as pd
46

57

8+
@pytest.mark.filterwarnings(
9+
# openpyxl
10+
"ignore:defusedxml.lxml is no longer supported:DeprecationWarning"
11+
)
12+
@pytest.mark.filterwarnings(
13+
# html5lib
14+
"ignore:Using or importing the ABCs from:DeprecationWarning"
15+
)
16+
@pytest.mark.filterwarnings(
17+
# fastparquet
18+
"ignore:pandas.core.index is deprecated:FutureWarning"
19+
)
20+
@pytest.mark.filterwarnings(
21+
# pandas_datareader
22+
"ignore:pandas.util.testing is deprecated:FutureWarning"
23+
)
624
def test_show_versions(capsys):
725
# gh-32041
826
pd.show_versions()

pandas/util/_print_versions.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,31 @@
44
import os
55
import platform
66
import struct
7-
import subprocess
87
import sys
98
from typing import List, Optional, Tuple, Union
109

1110
from pandas.compat._optional import VERSIONS, _get_version, import_optional_dependency
1211

1312

13+
def _get_commit_hash() -> Optional[str]:
14+
"""
15+
Use vendored versioneer code to get git hash, which handles
16+
git worktree correctly.
17+
"""
18+
from pandas._version import get_versions
19+
20+
versions = get_versions()
21+
return versions["full-revisionid"]
22+
23+
1424
def get_sys_info() -> List[Tuple[str, Optional[Union[str, int]]]]:
1525
"""
1626
Returns system information as a list
1727
"""
1828
blob: List[Tuple[str, Optional[Union[str, int]]]] = []
1929

2030
# get full commit hash
21-
commit = None
22-
if os.path.isdir(".git") and os.path.isdir("pandas"):
23-
try:
24-
pipe = subprocess.Popen(
25-
'git log --format="%H" -n 1'.split(" "),
26-
stdout=subprocess.PIPE,
27-
stderr=subprocess.PIPE,
28-
)
29-
so, serr = pipe.communicate()
30-
except (OSError, ValueError):
31-
pass
32-
else:
33-
if pipe.returncode == 0:
34-
commit = so.decode("utf-8").strip().strip('"')
31+
commit = _get_commit_hash()
3532

3633
blob.append(("commit", commit))
3734

0 commit comments

Comments
 (0)