Skip to content

Commit 067b8ac

Browse files
authored
TEST-#2292: Cover by tests Datetime Handling parameters of read_csv (#2336)
Signed-off-by: Alexander Myskov <alexander.myskov@intel.com>
1 parent f1f82ee commit 067b8ac

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

modin/pandas/test/test_io.py

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
get_random_string,
3939
insert_lines_to_csv,
4040
IO_OPS_DATA_DIR,
41+
io_ops_bad_exc,
4142
)
4243

4344
from modin.config import Engine, Backend
@@ -176,13 +177,12 @@ def _csv_file_maker(
176177
add_nan_lines=False,
177178
thousands_separator=None,
178179
decimal_separator=None,
179-
lineterminator=None,
180180
comment_col_char=None,
181181
quoting=csv.QUOTE_MINIMAL,
182182
quotechar='"',
183183
doublequote=True,
184184
escapechar=None,
185-
line_terminator=os.linesep,
185+
line_terminator=None,
186186
):
187187
if os.path.exists(filename) and not force:
188188
pass
@@ -248,7 +248,7 @@ def _csv_file_maker(
248248
"delimiter": delimiter,
249249
"doublequote": doublequote,
250250
"escapechar": escapechar,
251-
"lineterminator": line_terminator,
251+
"lineterminator": line_terminator if line_terminator else os.linesep,
252252
"quotechar": quotechar,
253253
"quoting": quoting,
254254
}
@@ -524,6 +524,75 @@ def test_read_csv_delimiters(
524524
**kwargs,
525525
)
526526

527+
# Datetime Handling tests
528+
@pytest.mark.parametrize(
529+
"parse_dates",
530+
[
531+
True,
532+
False,
533+
["col2"],
534+
["col2", "col4"],
535+
[1, 3],
536+
pytest.param(
537+
{"foo": ["col2", "col4"]},
538+
marks=pytest.mark.xfail(
539+
Engine.get() != "Python",
540+
reason="Exception: Internal Error - issue #2073",
541+
),
542+
),
543+
],
544+
)
545+
@pytest.mark.parametrize("infer_datetime_format", [True, False])
546+
@pytest.mark.parametrize("keep_date_col", [True, False])
547+
@pytest.mark.parametrize(
548+
"date_parser", [None, lambda x: pd.datetime.strptime(x, "%Y-%m-%d")]
549+
)
550+
@pytest.mark.parametrize("dayfirst", [True, False])
551+
@pytest.mark.parametrize("cache_dates", [True, False])
552+
def test_read_csv_datetime(
553+
self,
554+
make_csv_file,
555+
request,
556+
parse_dates,
557+
infer_datetime_format,
558+
keep_date_col,
559+
date_parser,
560+
dayfirst,
561+
cache_dates,
562+
):
563+
if request.config.getoption("--simulate-cloud").lower() != "off":
564+
pytest.xfail(
565+
"The reason of tests fail in `cloud` mode is unknown for now - issue #2340"
566+
)
567+
568+
raising_exceptions = io_ops_bad_exc # default value
569+
if isinstance(parse_dates, dict) and callable(date_parser):
570+
# In this case raised TypeError: <lambda>() takes 1 positional argument but 2 were given
571+
raising_exceptions = list(io_ops_bad_exc)
572+
raising_exceptions.remove(TypeError)
573+
574+
kwargs = {
575+
"parse_dates": parse_dates,
576+
"infer_datetime_format": infer_datetime_format,
577+
"keep_date_col": keep_date_col,
578+
"date_parser": date_parser,
579+
"dayfirst": dayfirst,
580+
"cache_dates": cache_dates,
581+
}
582+
583+
unique_name = get_unique_filename("test_read_csv_datetime", kwargs)
584+
make_csv_file(
585+
filename=unique_name,
586+
)
587+
588+
eval_io(
589+
filepath_or_buffer=unique_name,
590+
fn_name="read_csv",
591+
check_kwargs_callable=not callable(date_parser),
592+
raising_exceptions=raising_exceptions,
593+
**kwargs,
594+
)
595+
527596

528597
def test_from_parquet(make_parquet_file):
529598
make_parquet_file(SMALL_ROW_SIZE)

modin/pandas/test/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ def eval_general(
642642
__inplace__=False,
643643
check_exception_type=True,
644644
raising_exceptions=None,
645+
check_kwargs_callable=True,
645646
**kwargs,
646647
):
647648
if raising_exceptions:
@@ -670,7 +671,7 @@ def execute_callable(fn, inplace=False, md_kwargs={}, pd_kwargs={}):
670671
return (md_result, pd_result) if not __inplace__ else (modin_df, pandas_df)
671672

672673
for key, value in kwargs.items():
673-
if callable(value):
674+
if check_kwargs_callable and callable(value):
674675
values = execute_callable(value)
675676
# that means, that callable raised an exception
676677
if values is None:
@@ -696,6 +697,7 @@ def eval_io(
696697
cast_to_str=False,
697698
check_exception_type=True,
698699
raising_exceptions=io_ops_bad_exc,
700+
check_kwargs_callable=True,
699701
*args,
700702
**kwargs,
701703
):
@@ -732,6 +734,7 @@ def applyier(module, *args, **kwargs):
732734
applyier,
733735
check_exception_type=check_exception_type,
734736
raising_exceptions=raising_exceptions,
737+
check_kwargs_callable=check_kwargs_callable,
735738
*args,
736739
**kwargs,
737740
)

0 commit comments

Comments
 (0)