Skip to content

Commit

Permalink
Get rid of Python2 numeric relics (#33050)
Browse files Browse the repository at this point in the history
  • Loading branch information
eumiro authored Aug 3, 2023
1 parent 1c7472d commit e3d82c6
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion airflow/example_dags/example_python_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def my_sleeping_function(random_base):
"""This is a function that will run within the DAG execution"""
time.sleep(random_base)

sleeping_task = my_sleeping_function(random_base=float(i) / 10)
sleeping_task = my_sleeping_function(random_base=i / 10)

run_this >> log_the_sql >> sleeping_task
# [END howto_operator_python_kwargs]
Expand Down
2 changes: 1 addition & 1 deletion airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ def next_retry_datetime(self):
# If the min_backoff calculation is below 1, it will be converted to 0 via int. Thus,
# we must round up prior to converting to an int, otherwise a divide by zero error
# will occur in the modded_hash calculation.
min_backoff = int(math.ceil(delay.total_seconds() * (2 ** (self.try_number - 2))))
min_backoff = math.ceil(delay.total_seconds() * (2 ** (self.try_number - 2)))

# In the case when delay.total_seconds() is 0, min_backoff will not be rounded up to 1.
# To address this, we impose a lower bound of 1 on min_backoff. This effectively makes
Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/celery/executors/celery_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def _num_tasks_per_send_process(self, to_send_count: int) -> int:
:return: Number of tasks that should be sent per process
"""
return max(1, int(math.ceil(1.0 * to_send_count / self._sync_parallelism)))
return max(1, math.ceil(to_send_count / self._sync_parallelism))

def _process_tasks(self, task_tuples: list[TaskTuple]) -> None:
from airflow.providers.celery.executors.celery_executor_utils import execute_command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _get_many_using_multiprocessing(self, async_results) -> Mapping[str, EventBu
num_process = min(len(async_results), self._sync_parallelism)

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

task_id_to_states_and_info = list(
sync_pool.map(fetch_celery_task_state, async_results, chunksize=chunksize)
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/common/sql/operators/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,8 @@ class SQLIntervalCheckOperator(BaseSQLOperator):
ui_color = "#fff7e6"

ratio_formulas = {
"max_over_min": lambda cur, ref: float(max(cur, ref)) / min(cur, ref),
"relative_diff": lambda cur, ref: float(abs(cur - ref)) / ref,
"max_over_min": lambda cur, ref: max(cur, ref) / min(cur, ref),
"relative_diff": lambda cur, ref: abs(cur - ref) / ref,
}

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/docker/operators/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def _run_image_with_mounts(self, target_mounts, add_tmp_variable: bool) -> list[
shm_size=self.shm_size,
dns=self.dns,
dns_search=self.dns_search,
cpu_shares=int(round(self.cpus * 1024)),
cpu_shares=round(self.cpus * 1024),
port_bindings=self.port_bindings,
mem_limit=self.mem_limit,
cap_add=self.cap_add,
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/google/cloud/hooks/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3261,8 +3261,8 @@ def interval_check(
raise AirflowException("The first SQL query returned None")

ratio_formulas = {
"max_over_min": lambda cur, ref: float(max(cur, ref)) / min(cur, ref),
"relative_diff": lambda cur, ref: float(abs(cur - ref)) / ref,
"max_over_min": lambda cur, ref: max(cur, ref) / min(cur, ref),
"relative_diff": lambda cur, ref: abs(cur - ref) / ref,
}

metrics_sorted = sorted(metrics_thresholds.keys())
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/google/cloud/hooks/gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def download(
raise

# Wait with exponential backoff scheme before retrying.
timeout_seconds = 1.0 * 2 ** (num_file_attempts - 1)
timeout_seconds = 2 ** (num_file_attempts - 1)
time.sleep(timeout_seconds)
continue

Expand Down Expand Up @@ -524,7 +524,7 @@ def _call_with_retry(f: Callable[[], None]) -> None:
raise e

# Wait with exponential backoff scheme before retrying.
timeout_seconds = 1.0 * 2 ** (num_file_attempts - 1)
timeout_seconds = 2 ** (num_file_attempts - 1)
time.sleep(timeout_seconds)
continue

Expand Down
4 changes: 2 additions & 2 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ def index(self):
"error",
)

num_of_pages = int(math.ceil(num_of_all_dags / float(dags_per_page)))
num_of_pages = math.ceil(num_of_all_dags / dags_per_page)

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

logs_per_page = PAGE_SIZE
audit_logs_count = get_query_count(query, session=session)
num_of_pages = int(math.ceil(audit_logs_count / float(logs_per_page)))
num_of_pages = math.ceil(audit_logs_count / logs_per_page)

start = current_page * logs_per_page
end = start + logs_per_page
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/src/airflow_breeze/utils/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def bytes2human(n):
prefix[s] = 1 << (i + 1) * 10
for s in reversed(symbols):
if n >= prefix[s]:
value = float(n) / prefix[s]
value = n / prefix[s]
return f"{value:.1f}{s}"
return f"{n}B"

Expand Down
5 changes: 2 additions & 3 deletions dev/stats/get_important_pr_candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,11 @@ def score(self):
self.adjust_interaction_score()

return round(
1.0
* self.interaction_score
self.interaction_score
* self.label_score
* self.length_score
* self.change_score
/ (math.log10(self.num_changed_files) if self.num_changed_files > 20 else 1.0),
/ (math.log10(self.num_changed_files) if self.num_changed_files > 20 else 1),
3,
)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils/perf/perf_kit/repeat_and_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ def monte_carlo(total=10000):
for _ in range(0, total):
x_val = random.random() ** 2
y_val = random.random() ** 2
if math.sqrt(x_val + y_val) < 1.0:
if math.sqrt(x_val + y_val) < 1:
inside += 1

return (float(inside) / total) * 4
return (inside / total) * 4

# Example 1:s
with timeout(1):
Expand Down

0 comments on commit e3d82c6

Please sign in to comment.