You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "eumiro (via GitHub)" <gi...@apache.org> on 2023/08/02 20:06:37 UTC

[GitHub] [airflow] eumiro opened a new pull request, #33050: Get rid of Python2 numeric relics

eumiro opened a new pull request, #33050:
URL: https://github.com/apache/airflow/pull/33050

   Migration from Python2 to Python3 changes some numeric behavior. In Python3:
   
   - `round()`, `math.ceil()` and `math.floor()` return `int` instead of `float`
   - true division `int / int` returns `float` and therefore it is not necessary to convert one of the parts to `float` or to multiply the expression by `1.0`
   
   The code has been simplified. No functionality has been changed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] sethlm2 commented on a diff in pull request #33050: Get rid of Python2 numeric relics

Posted by "sethlm2 (via GitHub)" <gi...@apache.org>.
sethlm2 commented on code in PR #33050:
URL: https://github.com/apache/airflow/pull/33050#discussion_r1284937447


##########
airflow/providers/celery/executors/celery_executor_utils.py:
##########
@@ -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))

Review Comment:
   Exactly



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] uranusjr commented on a diff in pull request #33050: Get rid of Python2 numeric relics

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #33050:
URL: https://github.com/apache/airflow/pull/33050#discussion_r1282690948


##########
tests/test_utils/perf/perf_kit/repeat_and_time.py:
##########
@@ -120,10 +119,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 x_val + y_val < 1:

Review Comment:
   This doesn’t look right?



##########
tests/test_utils/perf/perf_kit/repeat_and_time.py:
##########
@@ -120,10 +119,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 x_val + y_val < 1:

Review Comment:
   This doesn’t look right?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] boring-cyborg[bot] commented on pull request #33050: Get rid of Python2 numeric relics

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #33050:
URL: https://github.com/apache/airflow/pull/33050#issuecomment-1662899549

   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (ruff, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/STATIC_CODE_CHECKS.rst#prerequisites-for-pre-commit-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/BREEZE.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#coding-style-and-best-practices).
   Apache Airflow is a community-driven project and together we are making it better 🚀.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] uranusjr commented on a diff in pull request #33050: Get rid of Python2 numeric relics

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #33050:
URL: https://github.com/apache/airflow/pull/33050#discussion_r1282689188


##########
airflow/providers/celery/executors/celery_executor_utils.py:
##########
@@ -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))

Review Comment:
   I wonder why the outer `floor` existed in the first place. That wouldn’t do anything on Python 2 either…



##########
airflow/providers/celery/executors/celery_executor_utils.py:
##########
@@ -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))

Review Comment:
   I wonder why the outer `floor` existed in the first place. That wouldn’t do anything on Python 2 either…



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] sethlm2 commented on a diff in pull request #33050: Get rid of Python2 numeric relics

Posted by "sethlm2 (via GitHub)" <gi...@apache.org>.
sethlm2 commented on code in PR #33050:
URL: https://github.com/apache/airflow/pull/33050#discussion_r1284937447


##########
airflow/providers/celery/executors/celery_executor_utils.py:
##########
@@ -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))

Review Comment:
   Exactly



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk merged pull request #33050: Get rid of Python2 numeric relics

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #33050:
URL: https://github.com/apache/airflow/pull/33050


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] boring-cyborg[bot] commented on pull request #33050: Get rid of Python2 numeric relics

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #33050:
URL: https://github.com/apache/airflow/pull/33050#issuecomment-1664747540

   Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional contributions.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] eumiro commented on a diff in pull request #33050: Get rid of Python2 numeric relics

Posted by "eumiro (via GitHub)" <gi...@apache.org>.
eumiro commented on code in PR #33050:
URL: https://github.com/apache/airflow/pull/33050#discussion_r1283578925


##########
tests/test_utils/perf/perf_kit/repeat_and_time.py:
##########
@@ -120,10 +119,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 x_val + y_val < 1:

Review Comment:
   Mathematically if `math.sqrt(x) < 1` then `x < 1` as well, but this is probably useless optimization that hides the original idea. So I have reverted this change (and only replaced `1.0` with `1`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org