|
5 | 5 | from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union
|
6 | 6 |
|
7 | 7 | import boto3
|
| 8 | +import botocore.exceptions |
8 | 9 | import pandas as pd
|
9 | 10 | import pandas.io.parsers
|
10 | 11 | from pandas.io.common import infer_compression
|
@@ -77,18 +78,23 @@ def _read_text_file(
|
77 | 78 | ) -> pd.DataFrame:
|
78 | 79 | boto3_session = _utils.ensure_session(boto3_session)
|
79 | 80 | mode, encoding, newline = _get_read_details(path=path, pandas_kwargs=pandas_kwargs)
|
80 |
| - with open_s3_object( |
81 |
| - path=path, |
82 |
| - version_id=version_id, |
83 |
| - mode=mode, |
84 |
| - use_threads=use_threads, |
85 |
| - s3_block_size=-1, # One shot download |
86 |
| - encoding=encoding, |
87 |
| - s3_additional_kwargs=s3_additional_kwargs, |
88 |
| - newline=newline, |
89 |
| - boto3_session=boto3_session, |
90 |
| - ) as f: |
91 |
| - df: pd.DataFrame = parser_func(f, **pandas_kwargs) |
| 81 | + try: |
| 82 | + with open_s3_object( |
| 83 | + path=path, |
| 84 | + version_id=version_id, |
| 85 | + mode=mode, |
| 86 | + use_threads=use_threads, |
| 87 | + s3_block_size=-1, # One shot download |
| 88 | + encoding=encoding, |
| 89 | + s3_additional_kwargs=s3_additional_kwargs, |
| 90 | + newline=newline, |
| 91 | + boto3_session=boto3_session, |
| 92 | + ) as f: |
| 93 | + df: pd.DataFrame = parser_func(f, **pandas_kwargs) |
| 94 | + except botocore.exceptions.ClientError as e: |
| 95 | + if e.response["Error"]["Code"] == "404": |
| 96 | + raise exceptions.NoFilesFound(f"No files Found on: {path}.") |
| 97 | + raise e |
92 | 98 | return _apply_partitions(df=df, dataset=dataset, path=path, path_root=path_root)
|
93 | 99 |
|
94 | 100 |
|
|
0 commit comments