|
38 | 38 | get_random_string, |
39 | 39 | insert_lines_to_csv, |
40 | 40 | IO_OPS_DATA_DIR, |
| 41 | + io_ops_bad_exc, |
41 | 42 | ) |
42 | 43 |
|
43 | 44 | from modin.config import Engine, Backend |
@@ -176,13 +177,12 @@ def _csv_file_maker( |
176 | 177 | add_nan_lines=False, |
177 | 178 | thousands_separator=None, |
178 | 179 | decimal_separator=None, |
179 | | - lineterminator=None, |
180 | 180 | comment_col_char=None, |
181 | 181 | quoting=csv.QUOTE_MINIMAL, |
182 | 182 | quotechar='"', |
183 | 183 | doublequote=True, |
184 | 184 | escapechar=None, |
185 | | - line_terminator=os.linesep, |
| 185 | + line_terminator=None, |
186 | 186 | ): |
187 | 187 | if os.path.exists(filename) and not force: |
188 | 188 | pass |
@@ -248,7 +248,7 @@ def _csv_file_maker( |
248 | 248 | "delimiter": delimiter, |
249 | 249 | "doublequote": doublequote, |
250 | 250 | "escapechar": escapechar, |
251 | | - "lineterminator": line_terminator, |
| 251 | + "lineterminator": line_terminator if line_terminator else os.linesep, |
252 | 252 | "quotechar": quotechar, |
253 | 253 | "quoting": quoting, |
254 | 254 | } |
@@ -524,6 +524,75 @@ def test_read_csv_delimiters( |
524 | 524 | **kwargs, |
525 | 525 | ) |
526 | 526 |
|
| 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 | + |
527 | 596 |
|
528 | 597 | def test_from_parquet(make_parquet_file): |
529 | 598 | make_parquet_file(SMALL_ROW_SIZE) |
|
0 commit comments