Skip to content

Commit 2634df1

Browse files
authored
fix: opensearch session (#3170)
* fix: opensearch session * fix: use session factory * fix: types * fix: types * fix: doc8
1 parent 234a285 commit 2634df1

File tree

9 files changed

+18
-36
lines changed

9 files changed

+18
-36
lines changed

awswrangler/_distributed.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from enum import Enum, unique
1010
from functools import wraps
1111
from importlib import reload
12-
from typing import Any, Callable, Literal, TypeVar, cast
12+
from typing import Any, Callable, Literal, TypeVar
1313

1414
EngineLiteral = Literal["python", "ray"]
1515
MemoryFormatLiteral = Literal["pandas", "modin"]
@@ -112,7 +112,7 @@ def wrapper(*args: Any, **kw: dict[str, Any]) -> Any:
112112
def register(cls, name: EngineLiteral | None = None) -> None:
113113
"""Register the distribution engine dispatch methods."""
114114
with cls._lock:
115-
engine_name = cast(EngineLiteral, name or cls.get().value)
115+
engine_name = name or cls.get().value
116116
cls.set(engine_name)
117117
cls._registry.clear()
118118

@@ -125,7 +125,7 @@ def register(cls, name: EngineLiteral | None = None) -> None:
125125
def initialize(cls, name: EngineLiteral | None = None) -> None:
126126
"""Initialize the distribution engine."""
127127
with cls._lock:
128-
engine_name = cast(EngineLiteral, name or cls.get_installed().value)
128+
engine_name = name or cls.get_installed().value
129129
if engine_name == EngineEnum.RAY.value:
130130
from awswrangler.distributed.ray import initialize_ray
131131

@@ -136,7 +136,7 @@ def initialize(cls, name: EngineLiteral | None = None) -> None:
136136
def is_initialized(cls, name: EngineLiteral | None = None) -> bool:
137137
"""Check if the distribution engine is initialized."""
138138
with cls._lock:
139-
engine_name = cast(EngineLiteral, name or cls.get_installed().value)
139+
engine_name = name or cls.get_installed().value
140140

141141
return False if not cls._initialized_engine else cls._initialized_engine.value == engine_name
142142

awswrangler/athena/_write_iceberg.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
import typing
88
import uuid
9-
from typing import Any, Dict, Literal, TypedDict, cast
9+
from typing import Any, Dict, Literal, TypedDict
1010

1111
import boto3
1212
import pandas as pd
@@ -501,10 +501,7 @@ def to_iceberg( # noqa: PLR0913
501501
merge_condition=merge_condition,
502502
)
503503

504-
glue_table_settings = cast(
505-
GlueTableSettings,
506-
glue_table_settings if glue_table_settings else {},
507-
)
504+
glue_table_settings = glue_table_settings if glue_table_settings else {}
508505

509506
try:
510507
# Create Iceberg table if it doesn't exist

awswrangler/catalog/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def sanitize_dataframe_columns_names(df: pd.DataFrame, handle_duplicate_columns:
196196
"""
197197
df.columns = [sanitize_column_name(x) for x in df.columns]
198198
df.index.names = [None if x is None else sanitize_column_name(x) for x in df.index.names]
199-
if df.columns.duplicated().any(): # type: ignore[attr-defined]
199+
if df.columns.duplicated().any():
200200
if handle_duplicate_columns == "warn":
201201
warnings.warn(
202202
"Duplicate columns were detected, consider using `handle_duplicate_columns='[drop|rename]'`",

awswrangler/opensearch/_write.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def index_json(
280280
path: str,
281281
index: str,
282282
doc_type: str | None = None,
283-
boto3_session: boto3.Session | None = boto3.Session(),
283+
boto3_session: boto3.Session | None = None,
284284
json_path: str | None = None,
285285
use_threads: bool | int = False,
286286
**kwargs: Any,
@@ -334,12 +334,9 @@ def index_json(
334334
"""
335335
_logger.debug("indexing %s from %s", index, path)
336336

337-
if boto3_session is None:
338-
raise ValueError("boto3_session cannot be None")
339-
340337
if path.startswith("s3://"):
341338
bucket, key = parse_path(path)
342-
s3 = boto3_session.client("s3")
339+
s3 = _utils.client(service_name="s3", session=boto3_session)
343340
obj = s3.get_object(Bucket=bucket, Key=key)
344341
body = obj["Body"].read()
345342
lines = body.splitlines()

awswrangler/quicksight/_get_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _list(
2828
client = _utils.client(service_name="quicksight", session=boto3_session)
2929
func: Callable[..., dict[str, Any]] = getattr(client, func_name)
3030
response: dict[str, Any] = func(AwsAccountId=account_id, **kwargs)
31-
next_token: str = response.get("NextToken", None)
31+
next_token: str | None = response.get("NextToken", None)
3232
result: list[dict[str, Any]] = response[attr_name]
3333
while next_token is not None:
3434
response = func(AwsAccountId=account_id, NextToken=next_token, **kwargs)

awswrangler/s3/_write_orc.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
import math
77
from contextlib import contextmanager
8-
from typing import TYPE_CHECKING, Any, Callable, Iterator, Literal, cast
8+
from typing import TYPE_CHECKING, Any, Callable, Iterator, Literal
99

1010
import boto3
1111
import pandas as pd
@@ -620,10 +620,7 @@ def to_orc(
620620
}
621621
622622
"""
623-
glue_table_settings = cast(
624-
GlueTableSettings,
625-
glue_table_settings if glue_table_settings else {},
626-
)
623+
glue_table_settings = glue_table_settings if glue_table_settings else {}
627624

628625
table_type = glue_table_settings.get("table_type")
629626
description = glue_table_settings.get("description")

awswrangler/s3/_write_parquet.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
import math
77
from contextlib import contextmanager
8-
from typing import TYPE_CHECKING, Any, Callable, Iterator, Literal, cast
8+
from typing import TYPE_CHECKING, Any, Callable, Iterator, Literal
99

1010
import boto3
1111
import pandas as pd
@@ -678,10 +678,7 @@ def to_parquet(
678678
}
679679
680680
"""
681-
glue_table_settings = cast(
682-
GlueTableSettings,
683-
glue_table_settings if glue_table_settings else {},
684-
)
681+
glue_table_settings = glue_table_settings if glue_table_settings else {}
685682

686683
table_type = glue_table_settings.get("table_type")
687684
description = glue_table_settings.get("description")

awswrangler/s3/_write_text.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import csv
66
import logging
77
import uuid
8-
from typing import TYPE_CHECKING, Any, Literal, cast
8+
from typing import TYPE_CHECKING, Any, Literal
99

1010
import boto3
1111
import pandas as pd
@@ -435,10 +435,7 @@ def to_csv( # noqa: PLR0912,PLR0915
435435
"e.g. wr.s3.to_csv(df, path, sep='|', na_rep='NULL', decimal=',', compression='gzip')"
436436
)
437437

438-
glue_table_settings = cast(
439-
GlueTableSettings,
440-
glue_table_settings if glue_table_settings else {},
441-
)
438+
glue_table_settings = glue_table_settings if glue_table_settings else {}
442439

443440
table_type = glue_table_settings.get("table_type")
444441
description = glue_table_settings.get("description")
@@ -885,10 +882,7 @@ def to_json( # noqa: PLR0912,PLR0915
885882
"e.g. wr.s3.to_json(df, path, lines=True, date_format='iso')"
886883
)
887884

888-
glue_table_settings = cast(
889-
GlueTableSettings,
890-
glue_table_settings if glue_table_settings else {},
891-
)
885+
glue_table_settings = glue_table_settings if glue_table_settings else {}
892886

893887
table_type = glue_table_settings.get("table_type")
894888
description = glue_table_settings.get("description")

docs/source/layers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,4 +607,4 @@ Version 3.12.1
607607
| cn-northwest-1 | 3.9 | x86_64| arn:aws-cn:lambda:cn-northwest-1:406640652441:layer:AWSSDKPandas-Python39:19 |
608608
+----------------+--------+-------+-----------------------------------------------------------------------------------+
609609
| cn-northwest-1 | 3.9 | arm64 | arn:aws-cn:lambda:cn-northwest-1:406640652441:layer:AWSSDKPandas-Python39-Arm64:3 |
610-
+----------------+--------+-------+-----------------------------------------------------------------------------------+
610+
+----------------+--------+-------+-----------------------------------------------------------------------------------+

0 commit comments

Comments
 (0)