Skip to content

Commit

Permalink
TEST-modin-project#2290: Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Anatoly Myachev <45976948+anmyachev@users.noreply.github.com>

TEST-modin-project#2290: addressing review comments

Signed-off-by: Alexander Myskov <alexander.myskov@intel.com>
  • Loading branch information
amyskov committed Dec 1, 2020
1 parent dd25126 commit bb7f5ed
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ jobs:
- shell: bash -l {0}
run: bash <(curl -s https://codecov.io/bash)

test-all-except-io:
test-ubuntu-all-except-io:
needs: [lint-commit, lint-flake8, lint-black, test-api, test-headers]
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -364,7 +364,7 @@ jobs:
- shell: bash -l {0}
run: bash <(curl -s https://codecov.io/bash)

test-io:
test-ubuntu-io:
needs: [lint-commit, lint-flake8, lint-black, test-api, test-headers]
runs-on: ubuntu-latest
strategy:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ jobs:
- shell: bash -l {0}
run: bash <(curl -s https://codecov.io/bash)

test-all-except-io:
test-ubuntu-all-except-io:
needs: prepare-cache
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -235,7 +235,7 @@ jobs:
- shell: bash -l {0}
run: bash <(curl -s https://codecov.io/bash)

test-io:
test-ubuntu-io:
needs: [lint-commit, lint-flake8, lint-black, test-api, test-headers]
runs-on: ubuntu-latest
strategy:
Expand Down
67 changes: 48 additions & 19 deletions modin/pandas/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@
if not os.path.exists(IO_OPS_DATA_DIR):
os.mkdir(IO_OPS_DATA_DIR)

str_initial_spaces = """col1,col2,col3,col4
five, six, seven, eight
five, six, seven, eight
five, six, seven, eight
"""


@pytest.fixture
def make_parquet_file():
Expand Down Expand Up @@ -600,36 +594,69 @@ def test_read_csv_col_handling(
},
],
)
@pytest.mark.parametrize("skipfooter", [0, 10])
def test_read_csv_parsing_1(
self,
make_csv_file,
request,
dtype,
engine,
converters,
skipfooter,
):
if request.config.getoption("--simulate-cloud").lower() != "off":
pytest.xfail(
"The reason of tests fail in `cloud` mode is unknown for now - issue #2340"
)
kwargs = {
"dtype": dtype,
"engine": engine,
"converters": converters,
"skipfooter": skipfooter,
}

unique_name = get_unique_filename("test_read_csv_parsing", kwargs)
make_csv_file(
filename=unique_name,
)
if kwargs["dtype"]:
kwargs["dtype"] = {
col: "object" for col in pandas.read_csv(unique_name, nrows=1).columns
}

eval_io(
filepath_or_buffer=unique_name,
fn_name="read_csv",
check_exception_type=None, # issue #2320
raising_exceptions=None,
check_kwargs_callable=not callable(converters),
**kwargs,
)

@pytest.mark.parametrize("true_values", [["Yes"], ["Yes", "true"], None])
@pytest.mark.parametrize("false_values", [["No"], ["No", "false"], None])
@pytest.mark.parametrize("skiprows", [2, lambda x: x % 2])
@pytest.mark.parametrize("skipfooter", [0, 10])
@pytest.mark.parametrize("nrows", [123, None])
@pytest.mark.parametrize("names", [["c1", "c2", "c3", "c4"], None])
def test_read_csv_parsing(
def test_read_csv_parsing_2(
self,
make_csv_file,
request,
dtype,
engine,
converters,
true_values,
false_values,
skiprows,
skipfooter,
nrows,
names,
):
if nrows and (false_values or true_values):
if nrows and (false_values or true_values) and Engine.get() != "Python":
pytest.xfail("modin and pandas dataframes differs - issue #2446")
if request.config.getoption("--simulate-cloud").lower() != "off":
pytest.xfail(
"The reason of tests fail in `cloud` mode is unknown for now - issue #2340"
)
kwargs = {
"dtype": dtype,
"engine": engine,
"converters": converters,
"true_values": true_values,
"false_values": false_values,
"skiprows": skiprows,
Expand All @@ -645,22 +672,24 @@ def test_read_csv_parsing(
if true_values or false_values
else None,
)
if kwargs["dtype"]:
kwargs["dtype"] = {
col: "object" for col in pandas.read_csv(unique_name, nrows=1).columns
}

eval_io(
filepath_or_buffer=unique_name,
fn_name="read_csv",
check_exception_type=None, # issue #2320
raising_exceptions=None,
check_kwargs_callable=not (callable(skiprows) or callable(converters)),
check_kwargs_callable=not callable(skiprows),
**kwargs,
)

def test_read_csv_skipinitialspace(self, make_csv_file):
unique_filename = get_unique_filename("test_read_csv_skipinitialspace")
str_initial_spaces = (
"col1,col2,col3,col4\n"
"five, six, seven, eight\n"
" five, six, seven, eight\n"
"five, six, seven, eight\n"
)

eval_io_from_str(str_initial_spaces, unique_filename, skipinitialspace=True)

Expand Down
35 changes: 3 additions & 32 deletions modin/pandas/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,36 +868,6 @@ def generate_none_dfs():
return df, df2


def make_dict_hash(dict_to_hash):
"""Makes a hash from a dictionary considering nested
dictionaries, lists, sets or callables.
Parameters
----------
dict_to_hash: dict
Dictionary that should be hashed.
Returns
-------
Dictionary hash.
"""

def _make_hash(obj):
if isinstance(obj, (set, list, dict)):
object_hash = hash(frozenset(obj))
elif callable(obj):
object_hash = hash(obj.__name__)
else:
# conversion to str is done because hash(5) == hash(5.0)
object_hash = hash(obj if isinstance(obj, str) else str(obj))

return object_hash

# process unhashed values from dict_to_hash
new_dict = {key: _make_hash(value) for key, value in dict_to_hash.items()}
return hash(frozenset(new_dict))


def get_unique_filename(
test_name: str,
kwargs: dict = {},
Expand Down Expand Up @@ -954,9 +924,10 @@ def get_unique_filename(
)
return os.path.join(data_dir, parameters_values + suffix_part + f".{extension}")
else:
unique_id = make_dict_hash(kwargs)
import uuid

return os.path.join(
data_dir, (test_name + f"_{str(unique_id)}" + suffix_part + f".{extension}")
data_dir, (uuid.uuid1().hex + suffix_part + f".{extension}")
)


Expand Down

0 comments on commit bb7f5ed

Please sign in to comment.