Skip to content

Commit e3d82c6

Browse files
authored
Get rid of Python2 numeric relics (#33050)
1 parent 1c7472d commit e3d82c6

File tree

12 files changed

+18
-19
lines changed

12 files changed

+18
-19
lines changed

β€Žairflow/example_dags/example_python_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def my_sleeping_function(random_base):
8181
"""This is a function that will run within the DAG execution"""
8282
time.sleep(random_base)
8383

84-
sleeping_task = my_sleeping_function(random_base=float(i) / 10)
84+
sleeping_task = my_sleeping_function(random_base=i / 10)
8585

8686
run_this >> log_the_sql >> sleeping_task
8787
# [END howto_operator_python_kwargs]

β€Žairflow/models/taskinstance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ def next_retry_datetime(self):
11951195
# If the min_backoff calculation is below 1, it will be converted to 0 via int. Thus,
11961196
# we must round up prior to converting to an int, otherwise a divide by zero error
11971197
# will occur in the modded_hash calculation.
1198-
min_backoff = int(math.ceil(delay.total_seconds() * (2 ** (self.try_number - 2))))
1198+
min_backoff = math.ceil(delay.total_seconds() * (2 ** (self.try_number - 2)))
11991199

12001200
# In the case when delay.total_seconds() is 0, min_backoff will not be rounded up to 1.
12011201
# To address this, we impose a lower bound of 1 on min_backoff. This effectively makes

β€Žairflow/providers/celery/executors/celery_executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def _num_tasks_per_send_process(self, to_send_count: int) -> int:
264264
265265
:return: Number of tasks that should be sent per process
266266
"""
267-
return max(1, int(math.ceil(1.0 * to_send_count / self._sync_parallelism)))
267+
return max(1, math.ceil(to_send_count / self._sync_parallelism))
268268

269269
def _process_tasks(self, task_tuples: list[TaskTuple]) -> None:
270270
from airflow.providers.celery.executors.celery_executor_utils import execute_command

β€Žairflow/providers/celery/executors/celery_executor_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def _get_many_using_multiprocessing(self, async_results) -> Mapping[str, EventBu
298298
num_process = min(len(async_results), self._sync_parallelism)
299299

300300
with ProcessPoolExecutor(max_workers=num_process) as sync_pool:
301-
chunksize = max(1, math.floor(math.ceil(1.0 * len(async_results) / self._sync_parallelism)))
301+
chunksize = max(1, math.ceil(len(async_results) / self._sync_parallelism))
302302

303303
task_id_to_states_and_info = list(
304304
sync_pool.map(fetch_celery_task_state, async_results, chunksize=chunksize)

β€Žairflow/providers/common/sql/operators/sql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,8 @@ class SQLIntervalCheckOperator(BaseSQLOperator):
903903
ui_color = "#fff7e6"
904904

905905
ratio_formulas = {
906-
"max_over_min": lambda cur, ref: float(max(cur, ref)) / min(cur, ref),
907-
"relative_diff": lambda cur, ref: float(abs(cur - ref)) / ref,
906+
"max_over_min": lambda cur, ref: max(cur, ref) / min(cur, ref),
907+
"relative_diff": lambda cur, ref: abs(cur - ref) / ref,
908908
}
909909

910910
def __init__(

β€Žairflow/providers/docker/operators/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def _run_image_with_mounts(self, target_mounts, add_tmp_variable: bool) -> list[
374374
shm_size=self.shm_size,
375375
dns=self.dns,
376376
dns_search=self.dns_search,
377-
cpu_shares=int(round(self.cpus * 1024)),
377+
cpu_shares=round(self.cpus * 1024),
378378
port_bindings=self.port_bindings,
379379
mem_limit=self.mem_limit,
380380
cap_add=self.cap_add,

β€Žairflow/providers/google/cloud/hooks/bigquery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3261,8 +3261,8 @@ def interval_check(
32613261
raise AirflowException("The first SQL query returned None")
32623262

32633263
ratio_formulas = {
3264-
"max_over_min": lambda cur, ref: float(max(cur, ref)) / min(cur, ref),
3265-
"relative_diff": lambda cur, ref: float(abs(cur - ref)) / ref,
3264+
"max_over_min": lambda cur, ref: max(cur, ref) / min(cur, ref),
3265+
"relative_diff": lambda cur, ref: abs(cur - ref) / ref,
32663266
}
32673267

32683268
metrics_sorted = sorted(metrics_thresholds.keys())

β€Žairflow/providers/google/cloud/hooks/gcs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def download(
356356
raise
357357

358358
# Wait with exponential backoff scheme before retrying.
359-
timeout_seconds = 1.0 * 2 ** (num_file_attempts - 1)
359+
timeout_seconds = 2 ** (num_file_attempts - 1)
360360
time.sleep(timeout_seconds)
361361
continue
362362

@@ -524,7 +524,7 @@ def _call_with_retry(f: Callable[[], None]) -> None:
524524
raise e
525525

526526
# Wait with exponential backoff scheme before retrying.
527-
timeout_seconds = 1.0 * 2 ** (num_file_attempts - 1)
527+
timeout_seconds = 2 ** (num_file_attempts - 1)
528528
time.sleep(timeout_seconds)
529529
continue
530530

β€Žairflow/www/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ def index(self):
939939
"error",
940940
)
941941

942-
num_of_pages = int(math.ceil(num_of_all_dags / float(dags_per_page)))
942+
num_of_pages = math.ceil(num_of_all_dags / dags_per_page)
943943

944944
state_color_mapping = State.state_color.copy()
945945
state_color_mapping["null"] = state_color_mapping.pop(None)
@@ -4003,7 +4003,7 @@ def audit_log(self, dag_id: str, session: Session = NEW_SESSION):
40034003

40044004
logs_per_page = PAGE_SIZE
40054005
audit_logs_count = get_query_count(query, session=session)
4006-
num_of_pages = int(math.ceil(audit_logs_count / float(logs_per_page)))
4006+
num_of_pages = math.ceil(audit_logs_count / logs_per_page)
40074007

40084008
start = current_page * logs_per_page
40094009
end = start + logs_per_page

β€Ždev/breeze/src/airflow_breeze/utils/parallel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def bytes2human(n):
209209
prefix[s] = 1 << (i + 1) * 10
210210
for s in reversed(symbols):
211211
if n >= prefix[s]:
212-
value = float(n) / prefix[s]
212+
value = n / prefix[s]
213213
return f"{value:.1f}{s}"
214214
return f"{n}B"
215215

0 commit comments

Comments
 (0)