Skip to content

Commit 4f8bb2b

Browse files
authored
TST: misplaced tests (#56424)
1 parent 536ce30 commit 4f8bb2b

File tree

4 files changed

+57
-59
lines changed

4 files changed

+57
-59
lines changed

pandas/tests/io/parser/test_parse_dates.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
from io import StringIO
1313

1414
from dateutil.parser import parse as du_parse
15-
from hypothesis import given
1615
import numpy as np
1716
import pytest
1817
import pytz
1918

2019
from pandas._libs.tslibs import parsing
21-
from pandas._libs.tslibs.parsing import py_parse_datetime_string
2220

2321
import pandas as pd
2422
from pandas import (
@@ -30,7 +28,6 @@
3028
Timestamp,
3129
)
3230
import pandas._testing as tm
33-
from pandas._testing._hypothesis import DATETIME_NO_TZ
3431
from pandas.core.indexes.datetimes import date_range
3532
from pandas.core.tools.datetimes import start_caching_at
3633

@@ -1838,49 +1835,6 @@ def test_parse_multiple_delimited_dates_with_swap_warnings():
18381835
pd.to_datetime(["01/01/2000", "31/05/2000", "31/05/2001", "01/02/2000"])
18391836

18401837

1841-
def _helper_hypothesis_delimited_date(call, date_string, **kwargs):
1842-
msg, result = None, None
1843-
try:
1844-
result = call(date_string, **kwargs)
1845-
except ValueError as err:
1846-
msg = str(err)
1847-
return msg, result
1848-
1849-
1850-
@given(DATETIME_NO_TZ)
1851-
@pytest.mark.parametrize("delimiter", list(" -./"))
1852-
@pytest.mark.parametrize("dayfirst", [True, False])
1853-
@pytest.mark.parametrize(
1854-
"date_format",
1855-
["%d %m %Y", "%m %d %Y", "%m %Y", "%Y %m %d", "%y %m %d", "%Y%m%d", "%y%m%d"],
1856-
)
1857-
def test_hypothesis_delimited_date(
1858-
request, date_format, dayfirst, delimiter, test_datetime
1859-
):
1860-
if date_format == "%m %Y" and delimiter == ".":
1861-
request.applymarker(
1862-
pytest.mark.xfail(
1863-
reason="parse_datetime_string cannot reliably tell whether "
1864-
"e.g. %m.%Y is a float or a date"
1865-
)
1866-
)
1867-
date_string = test_datetime.strftime(date_format.replace(" ", delimiter))
1868-
1869-
except_out_dateutil, result = _helper_hypothesis_delimited_date(
1870-
py_parse_datetime_string, date_string, dayfirst=dayfirst
1871-
)
1872-
except_in_dateutil, expected = _helper_hypothesis_delimited_date(
1873-
du_parse,
1874-
date_string,
1875-
default=datetime(1, 1, 1),
1876-
dayfirst=dayfirst,
1877-
yearfirst=False,
1878-
)
1879-
1880-
assert except_out_dateutil == except_in_dateutil
1881-
assert result == expected
1882-
1883-
18841838
# ArrowKeyError: Column 'fdate1' in include_columns does not exist in CSV file
18851839
@skip_pyarrow
18861840
@pytest.mark.parametrize(

pandas/tests/io/sas/test_sas7bdat.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ def data_test_ix(request, dirpath):
4141
class TestSAS7BDAT:
4242
@pytest.mark.slow
4343
def test_from_file(self, dirpath, data_test_ix):
44-
df0, test_ix = data_test_ix
44+
expected, test_ix = data_test_ix
4545
for k in test_ix:
4646
fname = os.path.join(dirpath, f"test{k}.sas7bdat")
4747
df = pd.read_sas(fname, encoding="utf-8")
48-
tm.assert_frame_equal(df, df0)
48+
tm.assert_frame_equal(df, expected)
4949

5050
@pytest.mark.slow
5151
def test_from_buffer(self, dirpath, data_test_ix):
52-
df0, test_ix = data_test_ix
52+
expected, test_ix = data_test_ix
5353
for k in test_ix:
5454
fname = os.path.join(dirpath, f"test{k}.sas7bdat")
5555
with open(fname, "rb") as f:
@@ -59,37 +59,37 @@ def test_from_buffer(self, dirpath, data_test_ix):
5959
buf, format="sas7bdat", iterator=True, encoding="utf-8"
6060
) as rdr:
6161
df = rdr.read()
62-
tm.assert_frame_equal(df, df0)
62+
tm.assert_frame_equal(df, expected)
6363

6464
@pytest.mark.slow
6565
def test_from_iterator(self, dirpath, data_test_ix):
66-
df0, test_ix = data_test_ix
66+
expected, test_ix = data_test_ix
6767
for k in test_ix:
6868
fname = os.path.join(dirpath, f"test{k}.sas7bdat")
6969
with pd.read_sas(fname, iterator=True, encoding="utf-8") as rdr:
7070
df = rdr.read(2)
71-
tm.assert_frame_equal(df, df0.iloc[0:2, :])
71+
tm.assert_frame_equal(df, expected.iloc[0:2, :])
7272
df = rdr.read(3)
73-
tm.assert_frame_equal(df, df0.iloc[2:5, :])
73+
tm.assert_frame_equal(df, expected.iloc[2:5, :])
7474

7575
@pytest.mark.slow
7676
def test_path_pathlib(self, dirpath, data_test_ix):
77-
df0, test_ix = data_test_ix
77+
expected, test_ix = data_test_ix
7878
for k in test_ix:
7979
fname = Path(os.path.join(dirpath, f"test{k}.sas7bdat"))
8080
df = pd.read_sas(fname, encoding="utf-8")
81-
tm.assert_frame_equal(df, df0)
81+
tm.assert_frame_equal(df, expected)
8282

8383
@td.skip_if_no("py.path")
8484
@pytest.mark.slow
8585
def test_path_localpath(self, dirpath, data_test_ix):
8686
from py.path import local as LocalPath
8787

88-
df0, test_ix = data_test_ix
88+
expected, test_ix = data_test_ix
8989
for k in test_ix:
9090
fname = LocalPath(os.path.join(dirpath, f"test{k}.sas7bdat"))
9191
df = pd.read_sas(fname, encoding="utf-8")
92-
tm.assert_frame_equal(df, df0)
92+
tm.assert_frame_equal(df, expected)
9393

9494
@pytest.mark.slow
9595
@pytest.mark.parametrize("chunksize", (3, 5, 10, 11))

pandas/tests/io/test_feather.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"ignore:Passing a BlockManager to DataFrame:DeprecationWarning"
1616
)
1717

18-
pyarrow = pytest.importorskip("pyarrow")
18+
pa = pytest.importorskip("pyarrow")
1919

2020

2121
@pytest.mark.single_cpu
@@ -169,7 +169,6 @@ def test_http_path(self, feather_file, httpserver):
169169

170170
def test_read_feather_dtype_backend(self, string_storage, dtype_backend):
171171
# GH#50765
172-
pa = pytest.importorskip("pyarrow")
173172
df = pd.DataFrame(
174173
{
175174
"a": pd.Series([1, np.nan, 3], dtype="Int64"),

pandas/tests/tslibs/test_parsing.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from dateutil.parser import parse as du_parse
88
from dateutil.tz import tzlocal
9+
from hypothesis import given
910
import numpy as np
1011
import pytest
1112

@@ -21,6 +22,7 @@
2122
import pandas.util._test_decorators as td
2223

2324
import pandas._testing as tm
25+
from pandas._testing._hypothesis import DATETIME_NO_TZ
2426

2527

2628
@pytest.mark.skipif(
@@ -367,3 +369,46 @@ def test_guess_datetime_format_f(input):
367369
result = parsing.guess_datetime_format(input)
368370
expected = "%Y-%m-%dT%H:%M:%S.%f"
369371
assert result == expected
372+
373+
374+
def _helper_hypothesis_delimited_date(call, date_string, **kwargs):
375+
msg, result = None, None
376+
try:
377+
result = call(date_string, **kwargs)
378+
except ValueError as err:
379+
msg = str(err)
380+
return msg, result
381+
382+
383+
@given(DATETIME_NO_TZ)
384+
@pytest.mark.parametrize("delimiter", list(" -./"))
385+
@pytest.mark.parametrize("dayfirst", [True, False])
386+
@pytest.mark.parametrize(
387+
"date_format",
388+
["%d %m %Y", "%m %d %Y", "%m %Y", "%Y %m %d", "%y %m %d", "%Y%m%d", "%y%m%d"],
389+
)
390+
def test_hypothesis_delimited_date(
391+
request, date_format, dayfirst, delimiter, test_datetime
392+
):
393+
if date_format == "%m %Y" and delimiter == ".":
394+
request.applymarker(
395+
pytest.mark.xfail(
396+
reason="parse_datetime_string cannot reliably tell whether "
397+
"e.g. %m.%Y is a float or a date"
398+
)
399+
)
400+
date_string = test_datetime.strftime(date_format.replace(" ", delimiter))
401+
402+
except_out_dateutil, result = _helper_hypothesis_delimited_date(
403+
parsing.py_parse_datetime_string, date_string, dayfirst=dayfirst
404+
)
405+
except_in_dateutil, expected = _helper_hypothesis_delimited_date(
406+
du_parse,
407+
date_string,
408+
default=datetime(1, 1, 1),
409+
dayfirst=dayfirst,
410+
yearfirst=False,
411+
)
412+
413+
assert except_out_dateutil == except_in_dateutil
414+
assert result == expected

0 commit comments

Comments
 (0)