Skip to content

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

Merged
merged 31 commits into from
Oct 5, 2019
Merged

Conversation

tolaa001
Copy link
Contributor

@tolaa001 tolaa001 commented Oct 2, 2019

@simonjayhawkins and @jreback as promised, this PR contains the following new and EXCITING changes:

  1. Created a contest.py in the pytables sub directory containing all the shared fixtures
  2. Created common.py which contains all the functions and variables used by the test classes such as tables, safe_remove, safe_close, create_tempfile, ensure_clean_path, ensure_clean_store, _maybe_remove
  3. Created separate modules for each of the test classes i.e. test_timezones, test_hdf_store, test_hdf_complex_values
  4. As a result of creating the common.py, I have update the ensure_clean_path import to the test_compat module to ensure safe deletion of the test_pytables module.

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 :)

@simonjayhawkins simonjayhawkins added Clean IO HDF5 read_hdf, HDFStore Testing pandas testing functions or related to the test suite labels Oct 2, 2019
Copy link
Contributor

@jreback jreback left a 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):
Copy link
Contributor

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

Copy link
Member

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

pandas/setup.cfg

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,
Copy link
Contributor

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

@jreback jreback added this to the 1.0 milestone Oct 2, 2019
@pep8speaks
Copy link

pep8speaks commented Oct 2, 2019

Hello @tolaa001! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-10-04 10:09:29 UTC

@tolaa001 tolaa001 force-pushed the test_pytables_refactor branch from 6c71670 to 6375977 Compare October 2, 2019 15:20
@tolaa001 tolaa001 requested a review from jreback October 2, 2019 16:14
Copy link
Contributor

@jreback jreback left a 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:
Copy link
Contributor

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.

Copy link
Member

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\]"
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@jreback
Copy link
Contributor

jreback commented Oct 3, 2019

@tolaa001 you have some failing checks, if you can fixup we should merge this soon to prevent conflicts.

@tolaa001
Copy link
Contributor Author

tolaa001 commented Oct 3, 2019

@tolaa001 you have some failing checks, if you can fixup we should merge this soon to prevent conflicts.

@jreback all green now and reverted my accidental changes to test_operators.py. Thank you again for reviewing this


from pandas.io.pytables import read_hdf

tables = pytest.importorskip("tables")
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Member

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):

Copy link
Member

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

Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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)

@tolaa001 tolaa001 requested a review from jreback October 4, 2019 10:47
@jreback jreback merged commit 2a429af into pandas-dev:master Oct 5, 2019
@jreback
Copy link
Contributor

jreback commented Oct 5, 2019

thanks @tolaa001 very nice.

love to have the followups as discussed above.

proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
bongolegend pushed a commit to bongolegend/pandas that referenced this pull request Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean IO HDF5 read_hdf, HDFStore Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants