Skip to content

Commit 96d15e4

Browse files
patrick-mullerigorborgest
authored andcommitted
Changin the lastmodified variable name
1 parent fbc4465 commit 96d15e4

File tree

5 files changed

+117
-78
lines changed

5 files changed

+117
-78
lines changed

awswrangler/s3/_delete.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Amazon S3 CopDeletey Module (PRIVATE)."""
22

33
import concurrent.futures
4+
import datetime
45
import itertools
56
import logging
6-
from datetime import datetime
77
from typing import Dict, List, Optional, Union
88

99
import boto3 # type: ignore
@@ -42,9 +42,9 @@ def _delete_objects(bucket: str, keys: List[str], client_s3: boto3.client) -> No
4242
def delete_objects(
4343
path: Union[str, List[str]],
4444
use_threads: bool = True,
45+
last_modified_begin: Optional[datetime.datetime] = None,
46+
last_modified_end: Optional[datetime.datetime] = None,
4547
boto3_session: Optional[boto3.Session] = None,
46-
lastModified_begin: Optional[datetime] = None,
47-
lastModified_end: Optional[datetime] = None,
4848
) -> None:
4949
"""Delete Amazon S3 objects from a received S3 prefix or list of S3 objects paths.
5050
@@ -54,7 +54,7 @@ def delete_objects(
5454
5555
Note
5656
----
57-
The filter by lastModified begin lastModified end is applied after list all S3 files
57+
The filter by last_modified begin last_modified end is applied after list all S3 files
5858
5959
Parameters
6060
----------
@@ -63,10 +63,14 @@ def delete_objects(
6363
use_threads : bool
6464
True to enable concurrent requests, False to disable multiple threads.
6565
If enabled os.cpu_count() will be used as the max number of threads.
66+
last_modified_begin
67+
Filter the s3 files by the Last modified date of the object.
68+
The filter is applied only after list all s3 files.
69+
last_modified_end: datetime, optional
70+
Filter the s3 files by the Last modified date of the object.
71+
The filter is applied only after list all s3 files.
6672
boto3_session : boto3.Session(), optional
6773
Boto3 Session. The default boto3 session will be used if boto3_session receive None.
68-
lastModified_begin lastModified_end: datetime, optional
69-
Filter the s3 files by the Last modified date of the object
7074
7175
Returns
7276
-------
@@ -81,7 +85,10 @@ def delete_objects(
8185
8286
"""
8387
paths: List[str] = path2list(
84-
path=path, boto3_session=boto3_session, lastModified_begin=lastModified_begin, lastModified_end=lastModified_end
88+
path=path,
89+
boto3_session=boto3_session,
90+
last_modified_begin=last_modified_begin,
91+
last_modified_end=last_modified_end,
8592
)
8693
if len(paths) < 1:
8794
return

awswrangler/s3/_describe.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Amazon S3 Describe Module (INTERNAL)."""
22

33
import concurrent.futures
4+
import datetime
45
import itertools
56
import logging
67
import time
7-
from datetime import datetime
88
from typing import Any, Dict, List, Optional, Tuple, Union
99

1010
import boto3 # type: ignore
@@ -44,13 +44,13 @@ def describe_objects(
4444
path: Union[str, List[str]],
4545
wait_time: Optional[Union[int, float]] = None,
4646
use_threads: bool = True,
47+
last_modified_begin: Optional[datetime.datetime] = None,
48+
last_modified_end: Optional[datetime.datetime] = None,
4749
boto3_session: Optional[boto3.Session] = None,
48-
lastModified_begin: Optional[datetime] = None,
49-
lastModified_end: Optional[datetime] = None,
5050
) -> Dict[str, Dict[str, Any]]:
5151
"""Describe Amazon S3 objects from a received S3 prefix or list of S3 objects paths.
5252
53-
Fetch attributes like ContentLength, DeleteMarker, LastModified, ContentType, etc
53+
Fetch attributes like ContentLength, DeleteMarker, last_modified, ContentType, etc
5454
The full list of attributes can be explored under the boto3 head_object documentation:
5555
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.head_object
5656
@@ -60,7 +60,7 @@ def describe_objects(
6060
6161
Note
6262
----
63-
The filter by lastModified begin lastModified end is applied after list all S3 files
63+
The filter by last_modified begin last_modified end is applied after list all S3 files
6464
6565
Parameters
6666
----------
@@ -73,10 +73,14 @@ def describe_objects(
7373
use_threads : bool
7474
True to enable concurrent requests, False to disable multiple threads.
7575
If enabled os.cpu_count() will be used as the max number of threads.
76+
last_modified_begin
77+
Filter the s3 files by the Last modified date of the object.
78+
The filter is applied only after list all s3 files.
79+
last_modified_end: datetime, optional
80+
Filter the s3 files by the Last modified date of the object.
81+
The filter is applied only after list all s3 files.
7682
boto3_session : boto3.Session(), optional
7783
Boto3 Session. The default boto3 session will be used if boto3_session receive None.
78-
lastModified_begin lastModified_end: datetime, optional
79-
Filter the s3 files by the Last modified date of the object
8084
8185
Returns
8286
-------
@@ -94,7 +98,10 @@ def describe_objects(
9498
9599
"""
96100
paths: List[str] = path2list(
97-
path=path, boto3_session=boto3_session, lastModified_begin=lastModified_begin, lastModified_end=lastModified_end
101+
path=path,
102+
boto3_session=boto3_session,
103+
last_modified_begin=last_modified_begin,
104+
last_modified_end=last_modified_end,
98105
)
99106
if len(paths) < 1:
100107
return {}

awswrangler/s3/_list.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Amazon S3 List Module (PRIVATE)."""
22

3+
import datetime
34
import logging
4-
from datetime import datetime
55
from typing import Any, Dict, List, Optional
66

77
import boto3 # type: ignore
@@ -15,22 +15,24 @@
1515
def path2list(
1616
path: object,
1717
boto3_session: boto3.Session,
18+
last_modified_begin: Optional[datetime.datetime] = None,
19+
last_modified_end: Optional[datetime.datetime] = None,
1820
suffix: str = None,
19-
lastModified_begin: Optional[datetime] = None,
20-
lastModified_end: Optional[datetime] = None,
2121
) -> List[str]:
2222
"""Convert Amazon S3 path to list of objects."""
2323
if isinstance(path, str): # prefix
2424
paths: List[str] = list_objects(
2525
path=path,
2626
suffix=suffix,
2727
boto3_session=boto3_session,
28-
lastModified_begin=lastModified_begin,
29-
lastModified_end=lastModified_end,
28+
last_modified_begin=last_modified_begin,
29+
last_modified_end=last_modified_end,
3030
)
3131
elif isinstance(path, list):
32-
if lastModified_begin or lastModified_end:
33-
raise exceptions.InvalidArgumentType("Specify a list of files or (lastModified_begin and lastModified_end)")
32+
if last_modified_begin or last_modified_end:
33+
raise exceptions.InvalidArgumentType(
34+
"Specify a list of files or (last_modified_begin and last_modified_end)"
35+
)
3436
paths = path if suffix is None else [x for x in path if x.endswith(suffix)]
3537
else:
3638
raise exceptions.InvalidArgumentType(f"{type(path)} is not a valid path type. Please, use str or List[str].")
@@ -41,9 +43,9 @@ def _list_objects(
4143
path: str,
4244
delimiter: Optional[str] = None,
4345
suffix: Optional[str] = None,
46+
last_modified_begin: Optional[datetime.datetime] = None,
47+
last_modified_end: Optional[datetime.datetime] = None,
4448
boto3_session: Optional[boto3.Session] = None,
45-
lastModified_begin: Optional[datetime] = None,
46-
lastModified_end: Optional[datetime] = None,
4749
) -> List[str]:
4850
bucket: str
4951
prefix: str
@@ -56,15 +58,15 @@ def _list_objects(
5658
response_iterator = paginator.paginate(**args)
5759
paths: List[str] = []
5860

59-
# validations for lastModified_begin and lastModified_end
61+
# validations for last_modified_begin and last_modified_end
6062
filtering_by_date = False
61-
if lastModified_begin or lastModified_end:
62-
if not (hasattr(lastModified_begin, "tzinfo") and hasattr(lastModified_begin, "tzinfo")):
63+
if last_modified_begin or last_modified_end:
64+
if hasattr(last_modified_begin, "tzinfo") is None or hasattr(last_modified_begin, "tzinfo") is None:
6365
raise exceptions.InvalidArgumentType("Timezone is not defined")
64-
if not lastModified_begin or not lastModified_end:
65-
raise exceptions.InvalidArgumentType("Both lastModified_begin and lastModified_end needs to be provided.")
66-
if lastModified_begin > lastModified_end:
67-
raise exceptions.InvalidArgumentType("lastModified_begin is bigger than lastModified_end.")
66+
if last_modified_begin is None or last_modified_end is None:
67+
raise exceptions.InvalidArgumentType("Both last_modified_begin and last_modified_end needs to be provided.")
68+
if last_modified_begin > last_modified_end:
69+
raise exceptions.InvalidArgumentType("last_modified_begin is bigger than last_modified_end.")
6870
filtering_by_date = True
6971

7072
for page in response_iterator: # pylint: disable=too-many-nested-blocks
@@ -75,8 +77,8 @@ def _list_objects(
7577
key: str = content["Key"]
7678
if filtering_by_date:
7779
if (
78-
content["LastModified"] >= lastModified_begin
79-
and content["LastModified"] <= lastModified_end
80+
content["LastModified"] >= last_modified_begin
81+
and content["LastModified"] <= last_modified_end
8082
):
8183
if (content is not None) and ("Key" in content):
8284
if (suffix is None) or key.endswith(suffix):
@@ -180,26 +182,30 @@ def list_directories(path: str, boto3_session: Optional[boto3.Session] = None) -
180182
def list_objects(
181183
path: str,
182184
suffix: Optional[str] = None,
185+
last_modified_begin: Optional[datetime.datetime] = None,
186+
last_modified_end: Optional[datetime.datetime] = None,
183187
boto3_session: Optional[boto3.Session] = None,
184-
lastModified_begin: Optional[datetime] = None,
185-
lastModified_end: Optional[datetime] = None,
186188
) -> List[str]:
187189
"""List Amazon S3 objects from a prefix.
188190
189191
Note
190192
----
191-
The filter by lastModified begin lastModified end is applied after list all S3 files
193+
The filter by last_modified begin last_modified end is applied after list all S3 files
192194
193195
Parameters
194196
----------
195197
path : str
196198
S3 path (e.g. s3://bucket/prefix).
197199
suffix: str, optional
198200
Suffix for filtering S3 keys.
201+
last_modified_begin
202+
Filter the s3 files by the Last modified date of the object.
203+
The filter is applied only after list all s3 files.
204+
last_modified_end: datetime, optional
205+
Filter the s3 files by the Last modified date of the object.
206+
The filter is applied only after list all s3 files.
199207
boto3_session : boto3.Session(), optional
200208
Boto3 Session. The default boto3 session will be used if boto3_session receive None.
201-
lastModified_begin lastModified_end: datetime, optional
202-
Filter the s3 files by the Last modified date of the object
203209
204210
Returns
205211
-------
@@ -227,7 +233,7 @@ def list_objects(
227233
delimiter=None,
228234
suffix=suffix,
229235
boto3_session=boto3_session,
230-
lastModified_begin=lastModified_begin,
231-
lastModified_end=lastModified_end,
236+
last_modified_begin=last_modified_begin,
237+
last_modified_end=last_modified_end,
232238
)
233239
return [p for p in paths if not p.endswith("/")]

0 commit comments

Comments
 (0)