-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Test pytables refactor #28746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test pytables refactor #28746
Conversation
…ated test_hdf_store.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. just the 2 changes on moving the tests in already separately files. all other comments are for future PRs. ping on green.
pass | ||
|
||
|
||
def safe_close(store): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a future PR, we want to have doc-strings & typing for these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type errors in tests directories are not reported by mypy
Lines 133 to 134 in 75c9783
[mypy-pandas.conftest,pandas.tests.*] | |
ignore_errors=True |
so should typing be added? does help grok functions but equally if not correct (since not checked) could be confusing.
import pandas as pd | ||
from pandas import DataFrame, DatetimeIndex, Series, Timestamp, date_range | ||
from pandas.tests.io.pytables.common import ( | ||
_maybe_remove, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a future PR we can likely completely remove _maybe_remove
6c71670
to
6375977
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good. one more change then i think good to do. ping on green.
|
||
from pandas.io.pytables import read_hdf | ||
|
||
# TODO: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move these tables imports and mods (lines 15-22) from these individual files and put in common instead.
that way we only do these one and skip appropriately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback I think pytest.importorskip("tables") should be in each module and common.py should be pytest agnostic.
but that does mean duplication of parameter setting unless we add that to the module scoped fixture.
@@ -94,24 +94,25 @@ def test_logical_operators_int_dtype_with_int_scalar(self): | |||
def test_logical_operators_int_dtype_with_float(self): | |||
# GH#9016: support bitwise op for integer types | |||
s_0123 = Series(range(4), dtype="int64") | |||
|
|||
with pytest.raises(TypeError): | |||
msg = r"cannot compare a dtyped \[int64\] array with a scalar of type \[float\]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you changing things here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apologies, this shouldn't have been a change here as I was working on another branch working on the bare pytest_raises issue.
@tolaa001 you have some failing checks, if you can fixup we should merge this soon to prevent conflicts. |
|
||
from pandas.io.pytables import read_hdf | ||
|
||
tables = pytest.importorskip("tables") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right can you move these to common.py (the tables.parameters.*) that are repeated across files.
you can also move the pytest.importorskip to common.py as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this would mean having to import pytest in your common module, is this something you'd be ok with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback would this be acceptable?
diff --git a/pandas/tests/io/pytables/conftest.py b/pandas/tests/io/pytables/conftest.py
index 6164f5d07..db00b1e33 100644
--- a/pandas/tests/io/pytables/conftest.py
+++ b/pandas/tests/io/pytables/conftest.py
@@ -15,3 +15,14 @@ def setup_mode():
tm.reset_testing_mode()
yield
tm.set_testing_mode()
+
+
+@pytest.fixture(scope="module", autouse=True)
+def set_parameters():
+ """
+ Set pytables parameters so we don't have file sharing.
+ """
+ tables = pytest.importorskip("tables")
+ tables.parameters.MAX_NUMEXPR_THREADS = 1
+ tables.parameters.MAX_BLOSC_THREADS = 1
+ tables.parameters.MAX_THREADS = 1
diff --git a/pandas/tests/io/pytables/test_complex.py b/pandas/tests/io/pytables/test_complex.py
index 96c4a3042..37739b1fd 100644
--- a/pandas/tests/io/pytables/test_complex.py
+++ b/pandas/tests/io/pytables/test_complex.py
@@ -14,10 +14,6 @@ from pandas.util.testing import assert_frame_equal
from pandas.io.pytables import read_hdf
tables = pytest.importorskip("tables")
-# set these parameters so we don't have file sharing
-tables.parameters.MAX_NUMEXPR_THREADS = 1
-tables.parameters.MAX_BLOSC_THREADS = 1
-tables.parameters.MAX_THREADS = 1
# GH10447
diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py
index 97fd89903..e31cb0cf6 100644
--- a/pandas/tests/io/pytables/test_store.py
+++ b/pandas/tests/io/pytables/test_store.py
@@ -56,10 +56,6 @@ from pandas.io.pytables import TableIterator # noqa: E402 isort:skip
tables = pytest.importorskip("tables")
-# set these parameters so we don't have file sharing
-tables.parameters.MAX_NUMEXPR_THREADS = 1
-tables.parameters.MAX_BLOSC_THREADS = 1
-tables.parameters.MAX_THREADS = 1
_default_compressor = "blosc"
diff --git a/pandas/tests/io/pytables/test_timezones.py b/pandas/tests/io/pytables/test_timezones.py
index 3e91c6381..b18fdc7b6 100644
--- a/pandas/tests/io/pytables/test_timezones.py
+++ b/pandas/tests/io/pytables/test_timezones.py
@@ -16,10 +16,6 @@ import pandas.util.testing as tm
from pandas.util.testing import assert_frame_equal, set_timezone
tables = pytest.importorskip("tables")
-# set these parameters so we don't have file sharing
-tables.parameters.MAX_NUMEXPR_THREADS = 1
-tables.parameters.MAX_BLOSC_THREADS = 1
-tables.parameters.MAX_THREADS = 1
def _compare_with_tz(a, b):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the other alternative is to monkeypatch..
@pytest.fixture(autouse=True)
def set_parameters(monkeypatch):
"""
Set pytables parameters so we don't have file sharing.
"""
monkeypatch.setattr("tables.parameters.MAX_NUMEXPR_THREADS", 1, raising=False)
monkeypatch.setattr("tables.parameters.MAX_BLOSC_THREADS", 1, raising=False)
monkeypatch.setattr("tables.parameters.MAX_THREADS", 1, raising=False)
but this needs to be a function scoped fixture, see pytest-dev/pytest#363
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in theory it would be better as a fixture but just trying to avoid code duplication
this was always somewhat leaky because it globally patches
it could be nicer but can do later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. but IMO common.py should not have pytest imported.
also, some of the functions in common could be fixturized (and maybe eventually remove common.py)
i'm not convinced from the pytest docs that pytest.importorskip should be used outside the module, but it seems to work.
but we need to merge ASAP to avoid merge conflicts, so i'll not block this further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so what is the verdict on tables for this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so what is the verdict on tables for this PR?
see #28746 (comment)
thanks @tolaa001 very nice. love to have the followups as discussed above. |
@simonjayhawkins and @jreback as promised, this PR contains the following new and EXCITING changes:
There has been no amendments to the body of the code. The next PR will involve focusing on removing the class in test_timezone and making it strictly functional. Followed by me doing this to the other 2 new modules i.e. test_hdf_store and test_hdf_complex_values.
Once the code base is strictly functional, I can start working on more fun refactoring of the functions :)