I’m using kafka-python library for my fastapi consumer app and I’m consuming messages in batch with maximum of 100 records. Since the topic has huge traffic and have only one partition, consuming, processing and committing should be as quick as possible hence I want to use commit_async(), instead of synchronous commit(). But I’m not able to find a good example
Generating an interval set in hypothesis
I have some code that works with intervals, which are really just python dicts with the following structure: Writing a strategy for a single interval is relatively straightforward. I’d like to write a strategy to generate interval sets. An interval set is a list of intervals, such that: The list contains an arbitrary number of intervals. The interval names are
Find elements by class name with Selenium in Python
I want to click on elements whose class is “innerImageWrapper editlink”. I use this code but it’s not working. it’s working. but I dont want use xpath. I want use class name Answer By.CLASS_NAME receives single value while here you trying to pass 2 values: innerImageWrapper and editlink. To locate element by 2 class names you can use CSS Selector
Python: Crypto package error: “No module called ‘_number_new'”
I have a software which installs its own local Python 3.9. Included in its python39/lib/site-packages is Crypto package, which causes errors and seems old and incompatible with Python 3.9. It includes long integers, like 1L, which I fixed by removing the “L”. But I’m still getting the error below, even though the file exists. For now, I’m trying to fix
Reducing number of repeated queries in Django when creating new objects in a loop
I’m populating a database using Django from an Excel sheet. In the example below, the purchases list simulates the format of that sheet. My problem is that I’m repeatedly using Customer.objects.get to retrieve the same Customer object when creating new Purchase entries. This results in repeated database queries for the same information. I’ve tried using customers = Customer.objects.all() to read
Get the most consecutive day from Date column with PySpark
Original dataframe: member_id AccessDate 111111 2020-02-03 111111 2022-03-05 222222 2015-03-04 333333 2021-11-23 333333 2021-11-24 333333 2021-11-25 333333 2022-10-11 333333 2022-10-12 333333 2022-10-13 333333 2022-07-07 444444 2019-01-21 444444 2019-04-21 444444 2019-04-22 444444 2019-04-23 444444 2019-04-24 444444 2019-05-05 444444 2019-05-06 444444 2019-05-07 Result dataframe: member_id Most_Consecutive_AccessDate total 111111 2022-03-05 1 222222 2015-03-04 1 333333 2022-10-11, 2022-10-12, 2022-10-13 3 444444 2019-04-21, 2019-04-22, 2019-04-23,
Matrix row masking at different indices
I have an 2-D array that I want to find the max value per row and then find the next max-value that is not within +/- n of the previous value. For example I have the following matrix: Now I’d like to get the next max value not within say +/- 2 of the current max. Here is what I
How to extract link to Package Sources from Arch User Repository (AUR) website
I’m using BeautifulSoup to extract this line: from a webpage. Specifically, I want this part: iwgtk-0.8.tar.gz I’ve written this code: and I assume it is this line that fails. I’ve tried but that failed too. Answer Try to select your elements more specific: or more comfortable via css selector and use get(‘href’) to get the url or text / get_text()
can’t replace duplicate values with new values in xlsx with pandas
I have an xlsx file containing too much data. however the data contains duplicate values in column named UniversalIDS which I wanted to replace it with a randomly generated IDS with Pandas. So far I’ve tried different scenarios which I googled but did not work. for example I tried this: also I tried other alternatives seen on this site like
While loop not taking ‘if’ statement into account
I’m trying to write a program in Python where the user is asked to input a number of hours after which a countdown starts in seconds, however I want to also make sure that no floats/strings are inputted and if they are, the user needs to be prompted with the same question and input a correct value. If an integer