Skip to content

Commit 52fa043

Browse files
committed
TST: Update tests for 1.5
1 parent a739249 commit 52fa043

File tree

5 files changed

+53
-128
lines changed

5 files changed

+53
-128
lines changed

tests/__init__.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
from __future__ import annotations
22

3+
import os
4+
import platform
35
from typing import (
46
TYPE_CHECKING,
57
Final,
68
)
79

8-
from packaging.version import parse
9-
import pandas as pd
10-
1110
from pandas._typing import T
1211

1312
TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING
14-
PD_LT_15 = parse(pd.__version__) < parse("1.5.0")
13+
WINDOWS = os.name == "nt" or "cygwin" in platform.system().lower()
1514

1615

1716
def check(actual: T, klass: type, dtype: type | None = None, attr: str = "left") -> T:

tests/test_errors.py

+40-100
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,9 @@
1-
import os
2-
import platform
3-
from typing import TYPE_CHECKING
41
import warnings
52

63
from pandas import errors
74
import pytest
85

9-
from tests import PD_LT_15
10-
11-
if TYPE_CHECKING or PD_LT_15:
12-
# TODO: Remove all imports below after switch to 1.5.x, these moved to pandas.errors
13-
from pandas.core.base import (
14-
DataError,
15-
SpecificationError,
16-
)
17-
from pandas.core.common import (
18-
SettingWithCopyError,
19-
SettingWithCopyWarning,
20-
)
21-
from pandas.core.computation.engines import NumExprClobberingError
22-
from pandas.core.computation.ops import UndefinedVariableError
23-
from pandas.core.indexing import IndexingError
24-
25-
from pandas.io.clipboard import (
26-
PyperclipException,
27-
PyperclipWindowsException,
28-
)
29-
from pandas.io.formats.css import CSSWarning
30-
from pandas.io.pytables import (
31-
AttributeConflictWarning,
32-
ClosedFileError,
33-
IncompatibilityWarning,
34-
PossibleDataLossError,
35-
)
36-
from pandas.io.sql import DatabaseError
37-
from pandas.io.stata import (
38-
CategoricalConversionWarning,
39-
InvalidColumnName,
40-
PossiblePrecisionLoss,
41-
ValueLabelTypeMismatch,
42-
)
43-
else:
44-
from pandas.errors import (
45-
AttributeConflictWarning,
46-
CategoricalConversionWarning,
47-
ClosedFileError,
48-
CSSWarning,
49-
DatabaseError,
50-
DataError,
51-
IncompatibilityWarning,
52-
IndexingError,
53-
InvalidColumnName,
54-
NumExprClobberingError,
55-
PossibleDataLossError,
56-
PossiblePrecisionLoss,
57-
PyperclipException,
58-
PyperclipWindowsException,
59-
SettingWithCopyError,
60-
SettingWithCopyWarning,
61-
SpecificationError,
62-
UndefinedVariableError,
63-
ValueLabelTypeMismatch,
64-
)
65-
66-
WINDOWS = os.name == "nt" or "cygwin" in platform.system().lower()
6+
from tests import WINDOWS
677

688

699
def test_abstract_method_error() -> None:
@@ -160,96 +100,96 @@ def test_unsupported_function_call() -> None:
160100

161101

162102
def test_data_error() -> None:
163-
with pytest.raises(DataError):
164-
raise DataError()
103+
with pytest.raises(errors.DataError):
104+
raise errors.DataError()
165105

166106

167107
def test_specification_error() -> None:
168-
with pytest.raises(SpecificationError):
169-
raise SpecificationError()
108+
with pytest.raises(errors.SpecificationError):
109+
raise errors.SpecificationError()
170110

171111

172112
def test_setting_with_copy_error() -> None:
173-
with pytest.raises(SettingWithCopyError):
174-
raise SettingWithCopyError()
113+
with pytest.raises(errors.SettingWithCopyError):
114+
raise errors.SettingWithCopyError()
175115

176116

177117
def test_setting_with_copy_warning() -> None:
178-
with pytest.warns(SettingWithCopyWarning):
179-
warnings.warn("", SettingWithCopyWarning)
118+
with pytest.warns(errors.SettingWithCopyWarning):
119+
warnings.warn("", errors.SettingWithCopyWarning)
180120

181121

182122
def test_numexpr_clobbering_error() -> None:
183-
with pytest.raises(NumExprClobberingError):
184-
raise NumExprClobberingError()
123+
with pytest.raises(errors.NumExprClobberingError):
124+
raise errors.NumExprClobberingError()
185125

186126

187127
def test_undefined_variable_error() -> None:
188-
with pytest.raises(UndefinedVariableError):
189-
raise UndefinedVariableError("x")
128+
with pytest.raises(errors.UndefinedVariableError):
129+
raise errors.UndefinedVariableError("x")
190130

191131

192132
def test_indexing_error() -> None:
193-
with pytest.raises(IndexingError):
194-
raise IndexingError()
133+
with pytest.raises(errors.IndexingError):
134+
raise errors.IndexingError()
195135

196136

197137
def test_pyperclip_exception() -> None:
198-
with pytest.raises(PyperclipException):
199-
raise PyperclipException()
138+
with pytest.raises(errors.PyperclipException):
139+
raise errors.PyperclipException()
200140

201141

202-
@pytest.mark.skipif(not PD_LT_15 or not WINDOWS, reason="Feature moved in 1.5.0")
142+
@pytest.mark.skipif(not WINDOWS, reason="Windows only")
203143
def test_pyperclip_windows_exception() -> None:
204-
with pytest.raises(PyperclipWindowsException):
205-
raise PyperclipWindowsException("message")
144+
with pytest.raises(errors.PyperclipWindowsException):
145+
raise errors.PyperclipWindowsException("message")
206146

207147

208148
def test_css_warning() -> None:
209-
with pytest.warns(CSSWarning):
210-
warnings.warn("", CSSWarning)
149+
with pytest.warns(errors.CSSWarning):
150+
warnings.warn("", errors.CSSWarning)
211151

212152

213153
def test_possible_data_loss_error() -> None:
214-
with pytest.raises(PossibleDataLossError):
215-
raise PossibleDataLossError()
154+
with pytest.raises(errors.PossibleDataLossError):
155+
raise errors.PossibleDataLossError()
216156

217157

218158
def test_closed_file_error() -> None:
219-
with pytest.raises(ClosedFileError):
220-
raise ClosedFileError()
159+
with pytest.raises(errors.ClosedFileError):
160+
raise errors.ClosedFileError()
221161

222162

223163
def test_incompatibility_warning() -> None:
224-
with pytest.warns(IncompatibilityWarning):
225-
warnings.warn("", IncompatibilityWarning)
164+
with pytest.warns(errors.IncompatibilityWarning):
165+
warnings.warn("", errors.IncompatibilityWarning)
226166

227167

228168
def test_attribute_conflict_warning() -> None:
229-
with pytest.warns(AttributeConflictWarning):
230-
warnings.warn("", AttributeConflictWarning)
169+
with pytest.warns(errors.AttributeConflictWarning):
170+
warnings.warn("", errors.AttributeConflictWarning)
231171

232172

233173
def test_database_error() -> None:
234-
with pytest.raises(DatabaseError):
235-
raise DatabaseError()
174+
with pytest.raises(errors.DatabaseError):
175+
raise errors.DatabaseError()
236176

237177

238178
def test_possible_precision_loss() -> None:
239-
with pytest.warns(PossiblePrecisionLoss):
240-
warnings.warn("", PossiblePrecisionLoss)
179+
with pytest.warns(errors.PossiblePrecisionLoss):
180+
warnings.warn("", errors.PossiblePrecisionLoss)
241181

242182

243183
def test_value_label_type_mismatch() -> None:
244-
with pytest.warns(ValueLabelTypeMismatch):
245-
warnings.warn("", ValueLabelTypeMismatch)
184+
with pytest.warns(errors.ValueLabelTypeMismatch):
185+
warnings.warn("", errors.ValueLabelTypeMismatch)
246186

247187

248188
def test_invalid_column_name() -> None:
249-
with pytest.warns(InvalidColumnName):
250-
warnings.warn("", InvalidColumnName)
189+
with pytest.warns(errors.InvalidColumnName):
190+
warnings.warn("", errors.InvalidColumnName)
251191

252192

253193
def test_categorical_conversion_warning() -> None:
254-
with pytest.warns(CategoricalConversionWarning):
255-
warnings.warn("", CategoricalConversionWarning)
194+
with pytest.warns(errors.CategoricalConversionWarning):
195+
warnings.warn("", errors.CategoricalConversionWarning)

tests/test_io.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from typing_extensions import assert_type
4949

5050
from tests import (
51-
PD_LT_15,
51+
WINDOWS,
5252
check,
5353
)
5454

@@ -68,22 +68,22 @@
6868
CWD = os.path.split(os.path.abspath(__file__))[0]
6969

7070

71-
@pytest.mark.skipif(PD_LT_15, reason="pandas 1.5.0 or later required")
71+
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
7272
def test_orc():
7373
with ensure_clean() as path:
7474
check(assert_type(DF.to_orc(path), None), type(None))
7575
check(assert_type(read_orc(path), DataFrame), DataFrame)
7676

7777

78-
@pytest.mark.skipif(PD_LT_15, reason="pandas 1.5.0 or later required")
78+
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
7979
def test_orc_path():
8080
with ensure_clean() as path:
8181
pathlib_path = Path(path)
8282
check(assert_type(DF.to_orc(pathlib_path), None), type(None))
8383
check(assert_type(read_orc(pathlib_path), DataFrame), DataFrame)
8484

8585

86-
@pytest.mark.skipif(PD_LT_15, reason="pandas 1.5.0 or later required")
86+
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
8787
def test_orc_buffer():
8888
with ensure_clean() as path:
8989
file_w = open(path, "wb")
@@ -95,14 +95,14 @@ def test_orc_buffer():
9595
file_r.close()
9696

9797

98-
@pytest.mark.skipif(PD_LT_15, reason="pandas 1.5.0 or later required")
98+
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
9999
def test_orc_columns():
100100
with ensure_clean() as path:
101101
check(assert_type(DF.to_orc(path, index=False), None), type(None))
102102
check(assert_type(read_orc(path, columns=["a"]), DataFrame), DataFrame)
103103

104104

105-
@pytest.mark.skipif(PD_LT_15, reason="pandas 1.5.0 or later required")
105+
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
106106
def test_orc_bytes():
107107
check(assert_type(DF.to_orc(index=False), bytes), bytes)
108108

@@ -190,7 +190,6 @@ def test_read_stata_df():
190190

191191

192192
# Remove test when pandas 1.5.0 is released
193-
@pytest.mark.skipif(not PD_LT_15, reason="Keyword only in 1.5.0")
194193
def test_read_stata_iterator_positional():
195194
with ensure_clean() as path:
196195
str_path = str(path)

tests/test_resampler.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121

2222
from pandas._typing import Scalar
2323

24-
from tests import (
25-
PD_LT_15,
26-
check,
27-
)
24+
from tests import check
2825

2926
DR = date_range("1999-1-1", periods=365, freq="D")
3027
DF_ = DataFrame(np.random.standard_normal((365, 1)), index=DR)
@@ -301,11 +298,8 @@ def s2scalar(val: Series) -> float:
301298

302299
check(S.resample("m").aggregate(np.sum), Series)
303300
check(S.resample("m").aggregate("sum"), Series)
304-
if PD_LT_15:
301+
with pytest.warns(FutureWarning, match="Not prepending group keys"):
305302
check(S.resample("m").aggregate(s2series), Series)
306-
else:
307-
with pytest.warns(FutureWarning, match="Not prepending group keys"):
308-
check(S.resample("m").aggregate(s2series), Series)
309303
check(S.resample("m").aggregate(s2scalar), Series)
310304
check(S.resample("m").aggregate([np.mean]), DataFrame)
311305
check(S.resample("m").aggregate(["sum", np.mean]), DataFrame)
@@ -325,11 +319,8 @@ def df2scalar(val: DataFrame) -> float:
325319

326320
check(DF.resample("m").aggregate(np.sum), DataFrame)
327321
check(DF.resample("m").aggregate("sum"), DataFrame)
328-
if PD_LT_15:
322+
with pytest.warns(FutureWarning, match="Not prepending group keys"):
329323
check(DF.resample("m").aggregate(df2frame), DataFrame)
330-
else:
331-
with pytest.warns(FutureWarning, match="Not prepending group keys"):
332-
check(DF.resample("m").aggregate(df2frame), DataFrame)
333324
check(DF.resample("m").aggregate(df2series), DataFrame)
334325
check(DF.resample("m").aggregate(df2scalar), DataFrame)
335326
check(DF.resample("m").aggregate([np.mean]), DataFrame)

tests/test_series.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
)
3434

3535
from tests import (
36-
PD_LT_15,
3736
TYPE_CHECKING_INVALID_USAGE,
3837
check,
3938
)
@@ -261,11 +260,8 @@ def test_types_rank() -> None:
261260
s.rank(method="min", pct=True)
262261
with pytest.warns(FutureWarning, match="Dropping of nuisance columns"):
263262
s.rank(method="dense", ascending=True)
264-
if PD_LT_15:
263+
with pytest.warns(FutureWarning, match="Calling Series.rank with numeric_only"):
265264
s.rank(method="first", numeric_only=True)
266-
else:
267-
with pytest.warns(FutureWarning, match="Calling Series.rank with numeric_only"):
268-
s.rank(method="first", numeric_only=True)
269265

270266

271267
def test_types_mean() -> None:

0 commit comments

Comments
 (0)