QuestionId
int64
74.8M
79.8M
UserId
int64
56
29.4M
QuestionTitle
stringlengths
15
150
QuestionBody
stringlengths
40
40.3k
Tags
stringlengths
8
101
CreationDate
stringdate
2022-12-10 09:42:47
2025-11-01 19:08:18
AnswerCount
int64
0
44
UserExpertiseLevel
int64
301
888k
UserDisplayName
stringlengths
3
30
75,475,150
8,512,262
How can I update an attribute that's added to a method via a decorator?
<p>I've created a decorator that wraps tkinter's <code>after()</code> method to make looping functions easier (i.e., having a function call itself periodically)</p> <pre><code>import tkinter as tk from functools import wraps # decorator def after_loop(interval: int): &quot;&quot;&quot;Loop the decorated method at...
<python><tkinter><attributes><decorator><python-decorators>
2023-02-16 16:22:02
1
7,190
JRiggles
75,475,141
579,228
Using SQLite Python and Multithreading
<p>I'm desperately trying to get this code to work from about 70 threads, where it won't be run exactly at the same time, but pretty closely. All I really want is a way of saying, try to insert this, and if you can't back off for a while and try again, just doit without breaking the database. I'm using no options when ...
<python><sqlite>
2023-02-16 16:21:19
1
1,850
James
75,474,913
13,525,512
Launch different tkinter version from python app compiled with pyinstaller on Windows
<p>I have a tkinter GUI that allows me to start any kind of program:</p> <pre><code># main_app.py import tkinter as tk import subprocess root = tk.Tk() cmd_entry = tk.Entry(width=50) cmd_entry.pack(side='left') def run_script(): sp = subprocess.run(cmd_entry.get().split(), shell=True) run_btn = tk.Button(text=&...
<python><python-3.x><tkinter><tcl><pyinstaller>
2023-02-16 16:04:37
2
12,821
Tranbi
75,474,678
11,974,163
Pyodbc.connect is not connecting with created login and user
<p>Been stuck on this for a few days. Seen quite a few stack overflow posts on this which hasn't resolved for me and read the microsoft and pyodbc docs also but seems like my issue on this may be niche and would like some help.</p> <p><strong>Goal:</strong> I want to connect to sql server via a python script using <cod...
<python><sql-server><pyodbc>
2023-02-16 15:46:04
1
457
pragmatic learner
75,474,670
5,453,284
Is calling str.replace() twice the best solution for overlapping matches?
<p>When I execute the following code I expect all ' a ' to be replaced by ' b ' yet only non overlapping matches are replaced.</p> <pre><code>&quot; a a a a a a a a &quot;.replace(' a ', ' b ') &gt;&gt;&gt;' b a b a b a b a' </code></pre> <p>So I use the following:</p> <pre><code>&quot; a a a a a a a a &quot;.replace('...
<python><replace>
2023-02-16 15:45:32
2
327
thomas
75,474,642
12,875,823
Interpret hex as signed integer in Python
<p>I'm aware I could just do <code>0x0 - 9223372036854775807 - 1</code>, but is there a bit shift operation I could do instead to make this faster? Context: I'm fed a uint64 number in hex string form but I want to store this number inside an 8 byte signed integer attr in PostgreSQL. Also, I would need a way to convert ...
<python><python-3.x><bit-manipulation>
2023-02-16 15:43:21
0
998
acw
75,474,603
5,510,540
Python: replace numbers in an array
<p>I have the following array:</p> <pre><code>array = array([4., 0., 2., 8., 8., 8., 8., 2., 0.]) </code></pre> <p>and I would like to replace 0 by 0.5 so to get:</p> <pre><code>array = array([4., 0.5, 2., 8., 8., 8., 8., 2., 0.5]) </code></pre> <p>so far I have tried:</p> <pre><code>array.replace(0.5, 0) </code></pre>...
<python><arrays>
2023-02-16 15:40:36
1
1,642
Economist_Ayahuasca
75,474,589
4,494,781
How to download a file via https using QNetworkAccessManager
<p>I'm trying to write a class using <code>QtNetwork</code> to download a file without freezing my GUI. This seems to work with http URLs (tested with &quot;http://webcode.me&quot;), but not with the <code>https</code> URL from my example.</p> <pre><code>import os from typing import Optional import urllib.parse from P...
<python><qtnetwork>
2023-02-16 15:39:12
1
1,105
PiRK
75,474,511
2,061,944
How to select and click on option based on city name in mat-option-text?
<p>I need to find and click on a specific city from a drop down list using selenium. I have tried using the xpath but the id number for the city keeps changing with every refresh of the page. The element from the website is below:</p> <pre><code>&lt;mat-option role=&quot;option&quot; class=&quot;mat-option mat-focus-in...
<python><selenium-webdriver><xpath>
2023-02-16 15:33:10
2
329
user2061944
75,474,448
13,517,174
pytest: How can you use mocker.patch on a function that is defined inside of a test?
<p>I have a pytest file called <code>test_util</code> that looks like this:</p> <pre><code>import pytest class TestUtil: def test_split_kwargs(self, mocker): def testfunction_extra(e='5',f='6'): return e+f mocker.patch(...) </code></pre> <p>I would like to use the <code>assert_has_calls...
<python><mocking><pytest>
2023-02-16 15:28:23
1
453
Yes
75,474,347
9,911,256
Convert bytea to ndarray of nd.float32
<p>I have an ndarray of np.float32 that is saved in a Postgres database in the <a href="https://www.postgresql.org/docs/current/datatype-binary.html#id-1.5.7.12.9" rel="nofollow noreferrer"><em>bytea</em></a> format:</p> <pre><code>import pandas as pd import numpy as np import sqlite3 myndarray=np.array([-3.55219245e-...
<python><pandas><postgresql><numpy><bytea>
2023-02-16 15:20:32
1
954
RodolfoAP
75,474,316
4,700,367
Python threading memory error / bug / race condition
<p>I have an app where the following happens:</p> <ul> <li>starts a thread to generate &quot;work&quot; <ul> <li>this thread then starts a thread pool with 5 workers to generate &quot;work&quot; and put it on to a FIFO queue</li> </ul> </li> <li>starts a thread pool of 20 workers to get work from the FIFO queue and exe...
<python><python-3.x><multithreading><python-multithreading><data-race>
2023-02-16 15:18:21
1
438
Sam Wood
75,474,163
1,900,954
Disabling tf.function decorators for code coverage pytest run
<p>As discussed <a href="https://github.com/tensorflow/tensorflow/issues/33759" rel="nofollow noreferrer">here</a>, code coverage tools do not work nicely with tensorflow due to its code transformation. One suggested workaround is to use <code>tf.config.experimental_run_functions_eagerly(True)</code> when generating re...
<python><tensorflow><pytest><coverage.py><pytest-cov>
2023-02-16 15:06:05
1
1,974
Uri Granta
75,474,160
6,817,178
Python consume RabbitMQ and run SocketIO server
<p><strong>Setup</strong></p> <p>I have a python application, which should consume messages from a RabbitMQ and act as a SocketIO server to a Vue2 APP. When it receives messages from RabbitMQ it should send out a message over SocketIO to the Vue2 APP. Therefore I wrote 2 classes <code>RabbitMQHandler</code> and <code>S...
<python><socket.io><rabbitmq><python-multithreading>
2023-02-16 15:05:41
1
4,935
Raphael Hippe
75,474,110
2,397,711
How to fix vulnerabilities from AWS ECR Image Scans
<p>I'm trying to fix some Common Vulnerabilities and Exposures from my docker images hosted at AWS ECR.</p> <p>I have a Debian Bullseye that is basically a copy from the official python 3.11 bullseye slim image.</p> <p>When I run a scan in it, ECR shows the CVE-2019-8457 - SQLite3 from 3.6.0 to and including 3.27.2 is ...
<python><amazon-web-services><docker><security><amazon-ecr>
2023-02-16 15:01:29
0
1,874
Rafael Marques
75,474,093
6,364,850
How to read a spreadsheet using python API and Applications Default Credentials?
<p>I have the following code:</p> <pre><code> scope = ['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/spreadsheets.readonly'] credentials, project =...
<python><google-cloud-platform><scope><google-oauth><google-sheets-api>
2023-02-16 14:59:21
0
627
Matheus Oliveira
75,474,086
284,932
How to train FLAN-T5 to summarization task with a custom dataset of legal documents in pt-br?
<p>So, I would like to create a small proof-of-concept using (already extracted in txt files) +- 4.000 legal text divided in:</p> <ol> <li>2.000 initial petitions / complaints *.txt files</li> <li>2.000 summaries of each initial petition (txt files too)</li> </ol> <p>PS.: <strong>all text files are in brazilian portugu...
<python><nlp><transformer-model><summarization>
2023-02-16 14:58:59
2
474
celsowm
75,474,055
11,117,255
What can I do to pivot and group a dataframe?
<p>I have this dataframe</p> <pre><code>time id type value 9:04 1 A 23 9:04 1 B 12 9:10 2 A 81 9:10 2 B 17 9:12 3 A 11 9:12 3 B 2 9:14 4 A 88 9:14 4 B 17 </code></pre> <p>I can use this code to turn it into this dataframe</p> <pre><code>dataframe = dataframe.pivot(index = ['time', 'id'],...
<python><pandas><dataframe>
2023-02-16 14:56:53
0
2,759
Cauder
75,473,964
10,353,865
Pandas: "Zip-like" selection
<p>Currently, when using the lookup method on a df one obtains zip-like selection, e.g.</p> <pre><code>df.lookup([&quot;one&quot;,&quot;two&quot;],[&quot;a&quot;,&quot;b&quot;]) </code></pre> <p>will select two values: one with rowlabel &quot;one&quot; and collabel &quot;a&quot; and another with &quot;two&quot; and &q...
<python><pandas>
2023-02-16 14:49:16
1
702
P.Jo
75,473,891
11,809,811
make plt graph fill area without padding
<p>I am trying to integrate matplotlib into tkinter, this is doable with FigureCanvasTkAgg. However, in my case I want to remove the y axis ticks and then make the graph cover the entire available area (i.e. remove the padding). Removing the y axis was not difficult but I cannot find any information on removing the pad...
<python><matplotlib><tkinter>
2023-02-16 14:44:51
0
830
Another_coder
75,473,825
11,391,711
Ignored_column is not working when using grid search in h2o library - Python
<p>The parameter called <code>ignored_columns</code> (see <a href="https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/ignored_columns.html" rel="nofollow noreferrer">link</a>) helps user to keep a feature that you want to be ignored when building a model.</p> <p>When I build a simple ML model and a...
<python><debugging><h2o><hyperparameters>
2023-02-16 14:39:06
0
488
whitepanda
75,473,766
14,256,643
python fastapi can't create multiple variation object in database for parent product
<p>I am trying to create multiple size and color for each of my parent product. when sending post request using fastapi swagger docs getting error</p> <pre><code>{ &quot;detail&quot;: [ { &quot;loc&quot;: [ &quot;body&quot;, &quot;variations&quot;, 0 ], &quot;msg&quot;: &...
<python><python-3.x><fastapi>
2023-02-16 14:34:52
0
1,647
boyenec
75,473,633
11,402,025
Database Connection Timeout Issue
<p>I have a python code that takes a set of inputs ( possibly 250 ) and then looks up the values corresponding to that input in 2 databases.</p> <pre><code>engine = create_engine(database_url1) result = {} for input in input_list: sql_query = f&quot;&quot;&quot;SELECT * FROM table 1where name = input limit 1;&quo...
<python><mysql><sql><query-optimization><database-performance>
2023-02-16 14:25:04
0
1,712
Tanu
75,473,318
8,881,495
Running gpt-neo on GPU
<p>The following code runs the <code>EleutherAI/gpt-neo-1.3B</code> model. The model runs on CPUs, but I don't understand why it does not use my GPU. Did I missed something?</p> <pre><code>from transformers import AutoModelForCausalLM, AutoTokenizer model = AutoModelForCausalLM.from_pretrained(&quot;EleutherAI/gpt-neo...
<python><gpu>
2023-02-16 13:59:38
1
3,655
Fifi
75,473,244
11,913,986
Pyspark groupby and merge column values to get aggregated frequency of row count
<p>I have a spark dataframe like:</p> <p>df:</p> <pre><code>id name subregion streak 8103178 A Western Asia 1 8103178 A Southern Asia 1 8344002 B North America 1 5225081 B South America 1 5225081 C Eastern Europe 1 5225081 D Northern Europe 1 5225081 E ...
<python><pandas><list><dataframe><pyspark>
2023-02-16 13:53:29
1
739
Strayhorn
75,473,164
19,325,656
subprocess.CalledProcessError: Command 'netsh advfirewall returned non-zero exit status 1
<p>Hi guys Im trying to edit firewall rules via an executable script (.exe)</p> <p>this is the basic code snippet that I'm running</p> <pre class="lang-py prettyprint-override"><code>command = &quot;netsh advfirewall firewall add rule name=dupa8 action=allow profile=any localip=192.162.250.0/24 remoteip=192.162.250.0/2...
<python><firewall><netsh>
2023-02-16 13:46:15
0
471
rafaelHTML
75,473,145
3,030,875
How to configure pip so that pip install is always called with argument --user?
<p>I'm configuring a jupyterlab single-user instance. The users will need to install Python packages using</p> <pre><code>pip install &lt;package-name&gt; </code></pre> <p>I want to configure pip so that <code>pip install</code> is always called with argument <code>--user</code>, even if it is invoked without <code>--u...
<python><pip><persistence><jupyter-lab>
2023-02-16 13:44:32
2
1,778
Brainless
75,472,993
482,819
Proper work to specialize generic classes in Python
<p>I am having a hard time using python typing annotations when dealing with generics and compound types</p> <p>Consider the following class:</p> <pre class="lang-py prettyprint-override"><code>import typing as ty T = ty.TypeVar(&quot;T&quot;) CT = tuple[bool, T, str] class MyClass(ty.Generic[T]): internal1: tupl...
<python><generics><typing><specialized-annotation>
2023-02-16 13:28:34
1
6,143
Hernan
75,472,971
14,301,545
Python bytes to binary string - how 4 bytes can be 29 bits?
<p>I need to read time data from sensor. Here are the instructions from manual:</p> <p><a href="https://i.sstatic.net/3Udmf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3Udmf.png" alt="enter image description here" /></a></p> <p>I have written code in Python, but I feel like there should be some bette...
<python><binary><byte>
2023-02-16 13:27:14
4
369
dany
75,472,814
2,536,951
Python Bokeh Not Changing the Colour of the Text when Updating
<p>I am trying to update the colour of a text on a plot I am creating.</p> <p><a href="https://i.sstatic.net/REgYW.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/REgYW.jpg" alt="enter image description here" /></a></p> <p>The code looks like this:</p> <pre class="lang-py prettyprint-override"><code> plo...
<python><bokeh>
2023-02-16 13:14:05
1
597
Suliman Sharif
75,472,690
1,907,765
Python GUI - "<Return>" event only seems to run once
<p>I'm trying to create a Tkinter GUI that will take a value from a textbox and put another value in a second textbox when the user presses Enter. So far I'm stuck on binding the event correctly. Here is the code:</p> <pre><code># Event handler functions def get_input(event): print(&quot;hello world&quot;) inp...
<python><tkinter>
2023-02-16 13:02:50
1
2,527
Lou
75,472,688
2,964,170
How can we sync different databases and application in django
<p>How can we access other database tables into django application database. Here 'default' database is main application and 'cl_db' is other application which is developed in asp.net but using same database server here how can we sync 'cl_db' database into 'default' database.</p> <pre><code>DATABASES = { 'default'...
<python><django><postgresql><django-rest-framework><postgis>
2023-02-16 13:02:47
0
425
Vas
75,472,405
20,240,835
count interval length with overlap in a larger data
<p>I have a list of tuples representing genomic intervals, where each tuple contains the start and end coordinates of the interval. I want to compute the total length of all the intervals, but I need to account for overlapping regions only once. The problem is that the intervals may not be sorted, and some intervals ma...
<python><dataframe><algorithm><sorting>
2023-02-16 12:39:02
1
689
zhang
75,472,376
2,254,024
Postgres database includes a table but I can not see any table when I connect via command line in Docker container
<p>I try to keep postgresql in a separate service. This is the Dockerfile</p> <pre><code>FROM python:3.10.0-alpine WORKDIR /app RUN pip install --upgrade pip &amp;&amp; \ pip install poetry COPY poetry.lock pyproject.toml /app/ RUN poetry install COPY . /app/ RUN python manage.py makemigrations kapp &amp;&amp; \ ...
<python><postgresql><docker><docker-compose><dockerfile>
2023-02-16 12:36:32
0
422
Karimai
75,472,350
10,667,216
How to resolve "ERROR: Could not build wheels for matplotlib, which is required to install pyproject.toml-based projects" with Python 3.9.12?
<p>I am encountering the following error when attempting to install matplotlib in an alpine Docker image:</p> <pre class="lang-none prettyprint-override"><code> error: Failed to download any of the following: ['http://www.qhull.org/download/qhull-2020-src-8.0.2.tgz']. Please download one of these urls and extract it i...
<python><matplotlib><alpine-linux>
2023-02-16 12:34:25
2
483
Davood
75,472,331
6,357,916
Getting error "'list' object is not callable" for authentication_classes
<p>I have following method:</p> <pre><code>class AbcViewSet(viwesets.ModelViewSet): @action(detail=False, permission_classes=(IsOwnerOrReadOnly,)) @debugger_queries def get_xyz(self, request, pk=None): # ... </code></pre> <p>Inside this method, <code>request.user</code> was always <code>AnonymousUs...
<python><django><django-rest-framework><django-views><django-viewsets>
2023-02-16 12:33:01
1
3,029
MsA
75,472,184
16,981,638
how to use scrapy package with Juypter Notebook
<p>I'm trying to learn web scraping/crawling and trying to apply the below code on Juypter Notebook but it didn't show any outputs, So can anyone help me and guide me to how to use the scrapy package on Juypter notebook.</p> <p><strong>The code:</strong></p> <pre><code>import scrapy from scrapy.linkextractors import Li...
<python><pandas><web-scraping><scrapy><jupyter>
2023-02-16 12:21:08
1
303
Mahmoud Badr
75,472,089
6,134,218
Python unittest - assert called with is not working
<p>i do a gitlab api call to a put_request and for my test I want to mock this call and assert if this call was called with the specific input.</p> <p>The problem is I do two put requests in my question with different input. This causes problems in my test.</p> <p>Code:</p> <pre><code>def set_project_settings(project_i...
<python><pytest><python-unittest><gitlab-api>
2023-02-16 12:13:13
1
742
Shalomi90
75,471,806
5,931,672
Understanding Plotly Time Difference units
<p>So, I have a problem similar to <a href="https://stackoverflow.com/questions/66635281/fitting-timedelta-on-plotly-y-axis">this</a> question. I have a DataFrame with a column <code>'diff'</code> and a column <code>'date'</code> with the following dtypes:</p> <pre><code>delta_df['diff'].dtype &gt;&gt;&gt; dtype('&lt;m...
<python><pandas><plotly>
2023-02-16 11:46:39
1
4,192
J Agustin Barrachina
75,471,704
9,909,598
Masking a polars dataframe for complex operations
<p>If I have a polars Dataframe and want to perform masked operations, I currently see two options:</p> <pre class="lang-py prettyprint-override"><code># create data df = pl.DataFrame([[1, 2, 3, 4], [5, 6, 7, 8]], schema = ['a', 'b']).lazy() # create a second dataframe for added fun df2 = pl.DataFrame([[8, 6, 7, 5], [1...
<python><dataframe><python-polars>
2023-02-16 11:37:01
2
451
DataWiz
75,471,591
4,183,498
Python list.sort(key=lambda x: ...) type hints
<p>I am sorting a list of dicts based on a key like below</p> <pre><code>my_function() -&gt; list[dict]: data: list[dict] = [] # Populate data ... if condition: data.sort(key=lambda x: x[&quot;position&quot;]) return data </code></pre> <p>However mypy complains about <code>Returning Any from ...
<python><lambda><types><type-hinting><mypy>
2023-02-16 11:26:30
1
10,009
Dušan Maďar
75,471,585
6,775,670
How to create a class which can be initialized by its own instance
<p><strong>Task:</strong></p> <p>Implement some class that accepts at least one argument and can be either initialized by original data, or its own instance.</p> <p><strong>Minimal example of usage:</strong></p> <pre><code>arg = {} # whatever necessary for the real object instance1 = NewClass(arg) instance2 = NewClass...
<python><oop>
2023-02-16 11:25:55
3
1,312
Nikolay Prokopyev
75,471,540
6,560,267
What is the use of PyArrow Tensor class?
<p>In the Arrow documentation there is a class named <code>Tensor</code> that is created from numpy ndarrays. However, the documentation is pretty sparse, and after playing a bit I haven't found an use case for it. For example, you can't construct a table with it:</p> <pre class="lang-py prettyprint-override"><code>imp...
<python><pyarrow><apache-arrow>
2023-02-16 11:21:41
2
913
Adrian
75,471,448
12,814,680
Lists manipulation with indexs
<p>I have two lists.</p> <p>List A :</p> <pre><code>A = [&quot;apple&quot;,&quot;cherry&quot;,&quot;pear&quot;,&quot;mango&quot;,&quot;banana&quot;,&quot;grape&quot;,&quot;kiwi&quot;,&quot;orange&quot;,&quot;pineapple&quot;] </code></pre> <p>List B :</p> <pre><code>B = [{&quot;offset&quot;:0, &quot;xx&quot;:789},{&quot...
<python>
2023-02-16 11:13:48
3
499
JK2018
75,471,388
462,707
Sentry: rate limit errors sent to prevent depletion of error quota
<p>When an infrastructure incident happens, the application will start to generate thousands of occurrences of the same error. Is it possible to configure some kind of rate limiting or anything like that on the sentry client (or server) to avoid depleting the error quota?</p> <p>I'm using Python, Django and Celery most...
<python><django><celery><sentry>
2023-02-16 11:09:19
1
8,649
nemesifier
75,471,237
3,672,883
How can I interpret this Python memory profile?
<p>I am running a Python script and I use memray to watch the memory usage. I got the following graph:</p> <p><a href="https://i.sstatic.net/wNOl0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/wNOl0.png" alt="enter image description here" /></a></p> <p>I don't understand the difference between heap and...
<python><memory>
2023-02-16 10:54:55
1
5,342
Tlaloc-ES
75,471,070
7,959,614
Uncompress a payload using Python
<p>I have an encoded string, <code>payload</code>, of a request that I want to uncompress.</p> <pre><code>payload = 'H4sIAAAAAAAAA+19bXMcN5LmX2Fw76NIIZFAAvA3e+yddax3rPDobmPiYkJBiS2LNzKpoCh7dHP+7/dkVXX1C6pNAtWu6oqwpdFIbBIFoIAnM598+9f5q1cPnz+sbq9+Wp1/cf7Xd3cPX68erm7efzx/dn598/HD+6vPL/E5Pvvyu+/wtZtr/PUHaywbwxfM5OjC4esPd5...
<python><json><byte><decode><payload>
2023-02-16 10:40:24
1
406
HJA24
75,471,046
9,391,359
mlflow.exceptions.MlflowException: Could not find a registered artifact repository
<p>I have mlflow experiment on remote server.</p> <p>I user pytorch_lightning for creating experiment</p> <pre><code>from pytorch_lightning.loggers import MLFlowLogger logger = MLFlowLogger( experiment_name=EXPERIMENT_NAME, tracking_uri=MLFLOW_TRACKING_URI, run_name=args.prefix ) </code></pre> <p>I can suc...
<python><mlflow>
2023-02-16 10:38:53
1
941
Alex Nikitin
75,471,037
5,868,293
How to use dictionary on np.where clause in pandas
<p>I have the following dataframe</p> <pre><code>import pandas as pd foo = pd.DataFrame({'id': [1,1,1,2,2,2], 'time': [1,2,3,1,2,3], 'col_id': ['ffp','ffp','ffp', 'hie', 'hie', 'ttt'], 'col_a': [1,2,3,4,5,6], 'col_b': [-1,-2,-3,-4,-5,-6], 'col_c...
<python><pandas>
2023-02-16 10:38:12
4
4,512
quant
75,470,878
458,661
Passing results of BigQuery query task to the next task while using template macro
<p>This seems a peculiar struggle, so I'm sure I'm missing something. Somehow I can't seem to pass values using XCOM, unless I'm using functions to execute the tasks that provide and use the information and call them from PythonOperator. This works, so far so good.</p> <p>But now I need to use the execution date in the...
<python><airflow><google-cloud-composer>
2023-02-16 10:25:54
2
1,956
Chrisvdberge
75,470,756
13,517,174
How can you override the argspec of a python function, e.g. to make the result of the help() function more useful?
<p>I have a python function that only takes in keyword arguments:</p> <pre><code>def my_func(**kwargs): </code></pre> <p>I am splitting the keyword arguments among two separate functions, which have their keyword arguments defined explicitly:</p> <pre><code>def my_subfunc_1(a=None,b=None): def my_subfunc_2(c=None,d=Non...
<python><built-in>
2023-02-16 10:14:26
1
453
Yes
75,470,619
1,145,808
Python multprocessing callback
<p>Using <a href="https://stackoverflow.com/questions/11515944/how-to-use-multiprocessing-queue-in-python">this post</a> as inspiration, I am trying to add a callback. I am using GLib.add_timeout to poll for the result, as I want to use it in a Gtk app. However, the main_quit() is not called properly, and thus the foll...
<python><multiprocessing><glib>
2023-02-16 10:02:52
1
829
DobbyTheElf
75,470,473
9,720,161
Custom Network and Policy in Stable-Baselines3
<p>I am attempting to create a small working example of how to use MultiDiscrete actions spaces together with a Box observation space. One of the problems that I have run into is that the dimension returned by utilizing a normal policy does not fit with the Box dimensions. The base policy returns something of size 25, ...
<python><reinforcement-learning><openai-gym><stable-baselines>
2023-02-16 09:49:56
1
303
AliG
75,470,298
12,546,311
How to sum area if a threshold is reached in pandas dataframe?
<p>I have a pandas data frame <code>df</code> where I try to find the sum of hectares that need to be harvested <code>area</code> before the threshold day in the other pandas data frame <code>lst</code> is reached per state.</p> <pre><code>lst = pd.DataFrame() lst['ST'] = ['CA', 'MA', 'TX', 'FL', 'OH', 'WY', 'AK'] lst[...
<python><pandas><merge>
2023-02-16 09:34:43
2
501
Thomas
75,470,290
4,729,280
Adding a coroutine with a webcam feed to a running asyncio loop stops tasks from running
<p>If I run 1+n async greeting loops everything works fine. Whenever I add the runCamera method, it stops the greeting loops from running. Why is this happening? Or is this rather a case for threading? I want the greeting loops to run and the webcam image showing at the same time.</p> <pre><code> def main(): ...
<python><python-asyncio><video-capture><opencv>
2023-02-16 09:34:23
1
362
ill
75,470,010
3,922,727
Python unable to read excel file using openpyxl received from API call as FileStorage
<p>We are trying to read excel file coming within a request into python script from Angular web app.</p> <p>We read the file as follows:</p> <pre><code>if 'sfile' in req.files: sfile = (req.files['sfile'].read()) </code></pre> <p>We need to pass <code>sfile</code> into another function to read it with openpyxl and ...
<python><openpyxl>
2023-02-16 09:13:33
0
5,012
alim1990
75,469,860
1,394,590
Is it possible to add type hints to an object whose attributes are defined on instantiation?
<p>I'm trying to define a class whose attributes are (mostly) provided by its users on instantiation. (There's more functionality to it, but this is what matters for the question.) My approach so far has been to pass keyword arguments to <code>__init__</code> and then these kwargs are transformed into attributes (prett...
<python><python-typing>
2023-02-16 08:59:02
0
15,387
bgusach
75,469,596
3,337,994
why is Numba parallel is slower than normal python loop?
<p>Following is normal python loop (I copied example from official doc - <a href="https://numba.readthedocs.io/en/stable/user/parallel.html" rel="nofollow noreferrer">https://numba.readthedocs.io/en/stable/user/parallel.html</a>)</p> <pre><code>def two_d_array_reduction_prod(n): shp = (13, 17) result1 = 2 * np....
<python><numba>
2023-02-16 08:32:23
1
2,945
Krishna Sunuwar
75,469,573
15,023,255
Simple Neural Network Using Pytorch
<p>I want to build Simple Neural Network with pytorch. And I want to teach this network.</p> <p>the network has y = w(weight) * x + b(bias) with w = 3 and b = 0</p> <p>so I have the data x = [1,2,3,4,5,6] y = [3,6,9,12,15,18]</p> <p>But I have some problem while building this Simple Neural Network</p> <pre><code>import...
<python><deep-learning><pytorch><neural-network><gradient-descent>
2023-02-16 08:29:54
1
403
Umgee
75,469,506
8,406,122
Finding the difference in number of words in a sentence in python
<p>Say I have 2 sentences,</p> <pre><code>Ref: Q R CODE SCANNER APP EXIT KARE Hyp: WORKOUTS SCANNER APP EXIT KARE </code></pre> <p>Here we can see that the <code>Ref</code> has 3 different words from the <code>Hyp</code>, since the <code>Q R Code</code> is not present in Hyp. If there is any built-in function in Pyth...
<python>
2023-02-16 08:21:33
1
377
Turing101
75,469,436
11,267,783
Interpolation Scipy in Python with meshgrid
<p>I would like to do the same interpolation as MATLAB in Python with scipy. Here is an example of my code.</p> <p>This is what I have in MATLAB :</p> <pre class="lang-matlab prettyprint-override"><code>x = linspace(-10,10,10); y = linspace(-5,5,10); DATA = rand(10,10); [XX,YY] = ndgrid(x,y); XX2 = XX; YY2 = YY; DAT...
<python><numpy><matlab><scipy><interpolation>
2023-02-16 08:13:24
1
322
Mo0nKizz
75,469,194
1,409,374
How to filter DataFrame by any string column matching any regex pattern in a list?
<p>String columns can be selected with:</p> <pre class="lang-python prettyprint-override"><code>df.select(pl.col(pl.String)) </code></pre> <p>and a Dataframe's rows can be filtered with a regex pattern for a single column, with something like:</p> <pre class="lang-python prettyprint-override"><code>df.filter(pl.col(&qu...
<python><python-polars>
2023-02-16 07:46:49
2
12,042
rickhg12hs
75,468,967
8,406,122
Extracting and replacing a particular string from a sentence in python
<p>Say I have a string,</p> <pre><code>s1=&quot;Hey Siri open call up duty&quot; </code></pre> <p>and another string</p> <p><code>s2=&quot;call up duty&quot;</code>.</p> <p>Now I know that &quot;call up duty&quot; should be replaced by &quot;call of duty&quot;.</p> <p>Say <code>s3=&quot;call of duty&quot;</code>.</p> <...
<python><string>
2023-02-16 07:21:02
2
377
Turing101
75,468,853
10,097,229
Calculate difference of rows in Pandas
<p>I have a timeseries dataframe where there are alerts for some particular rows. The dataframe looks like-</p> <pre><code>machineID time vibration alerts 1 2023-02-15 220 1 11:45 1 2023-02-15 221 0 12:00 1 2023-02-15 219 0 ...
<python><pandas><datetime><time-series>
2023-02-16 07:06:34
1
1,137
PeakyBlinder
75,468,851
7,873,570
BigQuery : Python Client not capturing errors found in audit logs when running multiple statements in a single query
<p>BigQuery : Python Client not capturing errors found in audit logs , when running multiple statements in a single query (for eg a declare variable statement before a create table statement ).</p> <p>There was a syntax issue in variable declaration in the query , The python client is not able to catch the error and it...
<python><exception><google-cloud-platform><google-bigquery>
2023-02-16 07:06:32
2
330
Nixon Raphy
75,468,753
18,096,205
python -v and python3 -V give different results
<p>python -v and python3 -V give different results</p> <h1>Current status.</h1> <pre><code>$ python -V Python 3.10.10 </code></pre> <pre><code>$ python3 -V Python 3.9.16 </code></pre> <p>Output results will be different.</p> <h1>What I did</h1> <p>Switched versions in pyenv.</p> <pre><code>$ pyenv global 3.10.10 </code...
<python><python-3.x><pyenv>
2023-02-16 06:53:19
0
349
Tdayo
75,468,689
13,142,245
How to define an MDP as a python function?
<p>I’m interested in defining a Markov Decision Process as a python function. It would need to interface with PyTorch API for reinforcement learning, however that constraint shapes the function’s form, inputs and outputs.</p> <p>For context, my problem involves optimally placing items in a warehouse, not knowing the va...
<python><optimization><pytorch><reinforcement-learning><markov-decision-process>
2023-02-16 06:44:26
1
1,238
jbuddy_13
75,468,512
9,768,643
Create DataFrame from df1 and df2 and take empty value from df2 for column value if not exist in df1 column value
<pre><code>df1 = pd.DataFrame({'call_sign': ['ASD','BSD','CDSF','GFDFD','FHHH'],'frn':['123','124','','656','']}) df2 = pd.DataFrame({'call_sign': ['ASD','CDSF','BSD','GFDFD','FHHH'],'frn':['1234','','124','','765']}) </code></pre> <p>need to get a new df like</p> <pre><code>df2 = pd.DataFrame({'call_sign': ['ASD','BS...
<python><pandas><dataframe>
2023-02-16 06:18:43
3
836
abhi krishnan
75,468,349
498,739
requirements.txt: any version < 1.5 (incl dev and rc versions)
<p>I am looking for a pattern for Python's requirement.txt (for usage with pip and python 3.10), which will cover all versions available up to a version 1.5, e.g.</p> <ul> <li>1.4.2.dev5+g470a8b8</li> <li>1.4.dev22+g2be722f</li> <li>1.4</li> <li>1.4rc0</li> <li>1.5rc1</li> </ul> <p>And: is there a clever way to test th...
<python><pip><python-packaging>
2023-02-16 05:54:07
1
2,793
herrjeh42
75,468,333
8,481,155
Apache Beam Find Top N elements Python SDK
<p>My requirement is to read from a BQ table, do some processing, select the Top N rows on the &quot;score&quot; column and write it to the BQ Table and also publish the rows as a PubSub message.</p> <p>I made a sample below to create a PCollection and select top 5 rows from this PCollection based on the value of &quot...
<python><google-cloud-dataflow><apache-beam>
2023-02-16 05:52:05
1
701
Ashok KS
75,468,249
6,013,016
Deleting elements from list or recreating new list (python)
<p>What it the best/fastest way to delete objects from list? Deleting some objects:</p> <pre><code>[objects.remove(o) for o in objects if o.x &lt;= 0] </code></pre> <p>or recreating new object:</p> <pre><code>new_objects = [o for o in objects if o.x &gt; 0] </code></pre>
<python><list><object>
2023-02-16 05:39:30
3
5,926
Scott
75,467,961
2,399,453
docker compose Flask app returning empty response
<p>I am trying to play with a dockerized flask container using docker-compose. The flask app is a hello world app that works correctly when I test it on my host.</p> <p>The docker-compose file looks like this:</p> <pre><code>version: '3' services: web: image: ubuntu build: context: ./ dockerfile: ...
<python><flask><docker-compose><dockerfile>
2023-02-16 04:48:17
1
3,152
user2399453
75,467,927
887,290
AttributeError: 'str' object has no attribute 'items' when using RawframeDataset with mvit in mmaction2
<p>I am using <a href="https://github.com/open-mmlab/mmaction2/tree/1.x" rel="nofollow noreferrer">mmaction2 branch 1.x</a>. I recently migrated from <a href="https://github.com/open-mmlab/mmaction2/tree/v0.24.1" rel="nofollow noreferrer">0.24</a> and want to use <a href="https://github.com/open-mmlab/mmaction2/blob/1....
<python><machine-learning><pytorch><computer-vision>
2023-02-16 04:42:01
2
2,153
ThomasEdwin
75,467,533
7,267,480
access to the row of a dataframe using the conditions and values for unnamed columns
<p>I have a dataframe:</p> <pre><code>params = pd.DataFrame({ 'dE' : {'3.0':20.0, '4.0':15.0, '-4.0':15.0}, 'Gg' : {'3.0':80.0, '4.0':55.0, '-4.0':55.0}, 'gn2' : {'3.0':50.0, '4.0':10.0, '-4.0':10.0} }) </code></pre> <p>The data ins...
<python><pandas><dataframe>
2023-02-16 03:23:48
2
496
twistfire
75,467,411
2,762,570
conda: what difference does it make if we set pip_interop_enabled=True?
<p>There are many posts on this site which reference, typically in passing, the idea of setting <code>pip_interop_enabled=True</code> within some environment. This makes conda and pip3 somehow interact better, I am told. To be precise, people say conda will search PyPI for packages that don't exist in the main channels...
<python><pip><anaconda><conda><pypi>
2023-02-16 03:00:38
1
405
Mike Battaglia
75,467,304
417,896
Python Eel - Close windows from js when connection to eel is lost
<p>During dev it's a pain to close all the eel windows when you need to restart eel for python code changes.</p> <p>For development purposes, and since we don't yet have live-reload for python using eel, it would be helpful to close all the windows when the python program is quit.</p> <p>I have the limitation that I am...
<javascript><python><eel>
2023-02-16 02:38:28
0
17,480
BAR
75,467,166
18,096,205
I want to switch python versions in paperspace
<p>I want to switch my python version from 3.9.6 to 3.10 in paperspace. But it doesn't work. So I need your help.</p> <h1>device info</h1> <pre><code>$root@nu1mmmnfz5:/notebooks/LoRA# cat /etc/*release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04 DISTRIB_CODENAME=focal DISTRIB_DESCRIPTION=&quot;Ubuntu 20.04.5 LTS&quot; NAM...
<python><python-3.x><linux><ubuntu>
2023-02-16 02:07:43
5
349
Tdayo
75,466,856
3,431,407
How to close clickable popup to continue scraping through Selenium in python
<p>I'm trying to scrape some information from clickable popups in a table on a website into a <code>pandas</code> dataframe using <code>Selenium</code> in <code>python</code> and it seems to be able to do this if the popups have information.</p> <pre><code>from selenium import webdriver from selenium.webdriver.support....
<python><selenium-webdriver><web-scraping>
2023-02-16 01:01:48
2
661
Funkeh-Monkeh
75,466,824
2,062,269
Python: Conditionally throwing an exception based on module-level variable
<p>I have a quite sizeable chunk of logic (say 100k lines of code) that are intended to validate a Python object which makes refactoring when <code>Exceptions</code> are thrown hard if not done incrementally.</p> <p>The logic above will throw an <code>Exception</code> when an invalid object is passed in.</p> <p>The log...
<python>
2023-02-16 00:54:23
0
960
Andy
75,466,731
2,690,251
Python int dunder methods return NotImplemented
<p>What really happens under the hood with <code>1/3.5</code> (or <code>1+3.5</code> or <code>1-3.5</code>)?</p> <h2>Preface</h2> <p>I will use division as example but this is true for all the methods</p> <p>In my code I need to use operations as functions.<br /> I found method <code>__truediv__</code> inside both <cod...
<python><magic-methods>
2023-02-16 00:30:52
0
377
Raikoug
75,466,701
9,663,207
SQLAlchemy relationship() via intermediary table
<p>I am struggling to define methods in SQLAlchemy to retrieve related records via an intermediary table.</p> <p>Consider the following schema:</p> <ul> <li>Users can create multiple posts, each post belongs to 1 user</li> <li>Each post can have multiple comments on it, with each comment belonging to 1 post</li> </ul> ...
<python><sqlalchemy><orm>
2023-02-16 00:24:43
1
724
g_t_m
75,466,507
3,059,546
How can you wait for an end-to-end Step Function test to finish when triggered by EventBridge?
<p>We are currently using an event-based approach to process files loaded into S3. When a file is uploaded it triggers an EventBridge S3 event, which kicks off a Step Function. When the data is moved to the target the Step Function finishes.</p> <p>We are interested in implementing an automated end-to-end test in our P...
<python><testing><aws-step-functions><aws-event-bridge>
2023-02-15 23:51:49
1
1,010
WarSame
75,466,461
1,447,953
xarray/numpy how to create large views on arrays?
<p>For later processing convenience, I want to be able to create a very large view onto an xarray DataArray. Here's a small example that works:</p> <pre><code>data = xr.DataArray([list(i+np.arange(10,20)) for i in range(5)], dims=[&quot;t&quot;, &quot;x&quot;]) indices = xr.DataArray(list([i]*20 for i in range(len(data...
<python><numpy><python-xarray>
2023-02-15 23:44:22
1
2,974
Ben Farmer
75,466,349
1,818,059
From ansi encoding to utf8 (and hex bytes)
<p>I have some texts encoded in ansi windows codepage. It is known which codepage it is.</p> <p>The data is stored in text files.</p> <p>I would like to do the following:</p> <ul> <li>convert the to utf-8</li> <li>print the resulting utf-8 as bytes</li> </ul> <p>Did read <a href="https://realpython.com/python-encodings...
<python><encoding><utf-8>
2023-02-15 23:23:10
1
1,176
MyICQ
75,466,209
7,873,949
How can PyPDF2 read the correct size of a PDF page
<p>I tried to get width and height of pdf with PyPDF2 with</p> <pre><code>w, h = page.mediaBox.getWidth(), page.mediaBox.getHeight() print(w, h) # showing 595 842 </code></pre> <p>However, the pdf is actually 842 X 595(11.7 X 8.27 inch) <a href="https://i.sstatic.net/vtJah.png" rel="nofollow noreferrer"><img src="https...
<python><python-3.x><pypdf>
2023-02-15 22:58:33
1
601
Mas Zero
75,466,013
12,106,577
Matplotlib major and minor ticks misaligned when using pandas date_range
<p>I am trying to use pandas <code>date_range</code> in the x-axis of a matplotlib.pyplot graph, while setting years to be the major ticks and months to be the minor ticks (for a timeline plot).</p> <p>I came across a seemingly unexpected behaviour (noticed also as part of <a href="https://stackoverflow.com/questions/2...
<python><pandas><matplotlib><date-range><xticks>
2023-02-15 22:28:41
1
399
John Karkas
75,465,692
19,491,471
Jupyter packages
<p>I am trying to import certain packages as I am working with Jupyter notebook files, and most of the packages seem to be missing, even though I have installed them. For example, when I do the command: <code>from bs4 import BeautifulSoup</code> or <code>import requests</code> I get the error saying <code>ModuleNotFoun...
<python><jupyter-notebook><pip><jupyter>
2023-02-15 21:40:01
2
327
Amin
75,465,666
8,474,432
What causes neural network accuracy to sharply increase after only one epoch?
<p>I'm using a relatively simple neural network with fully connected layers in keras. For some reason, the accuracy drastically increases basically to its final value after only one training epoch (likewise, the loss sharply decreases). I've tried architectures with larger and smaller numbers of hidden layers too. This...
<python><tensorflow><keras><deep-learning><neural-network>
2023-02-15 21:35:19
1
1,216
curious_cosmo
75,465,503
10,006,534
How do I reshape my data so that IDs with multiple observations are grouped as all possible pairs of observations by ID?
<p>Given a data frame like this:</p> <pre><code>import pandas as pd pd.DataFrame({'id':[1,1,1,2,2], 'letter':['a','b','c','b','d'], 'value':[0,0,0,1,1]}) id let val 0 1 a 0 1 1 b 0 2 1 c 0 3 2 b 1 4 2 d 1 </code></pre> <p>I want to generate a version where the...
<python><pandas><group-by><transformation>
2023-02-15 21:16:33
1
581
Slash
75,465,299
6,035,977
Undo Marking Folder as Source Directory in PyCharm
<p>So I've developed a larger package <code>my_package</code> in PyCharm and throughout the development process, I had marked the <code>my_package</code> directory as a source directory, and PyCharm automatically set up the import statements like</p> <pre><code>from path1.to.module import something from path2.to.anothe...
<python><installation><import><pycharm><packaging>
2023-02-15 20:49:03
1
333
Corram
75,465,032
4,218,755
Displaying a shared bar chart from groupby results
<p>I have this type of Dataframe :</p> <pre><code> origin delta month 2021-09 admin -1000 2021-09 ext 20 2021-10 ext 648 2021-11 admin -1000 2021-11 ext 590 monthframe (32,3) </code></pre> <p>(I reprocessed &quot;month&quot; index from dates in a colum, parsed as datetime init...
<python><pandas><matplotlib><group-by>
2023-02-15 20:14:55
1
1,049
Ando Jurai
75,464,990
12,014,637
Speeding up numpy operations
<p>Using a 2D numpy array, I want to create a new array that expands the original one using a moving window. Let me explain what I mean using an example code:</p> <pre class="lang-py prettyprint-override"><code># Simulate some data import numpy as np np.random.seed(1) t = 20000 # total observations location = np.ran...
<python><numpy>
2023-02-15 20:10:30
2
618
Amin Shn
75,464,972
9,210,912
Is there a way to parse Golang printed maps in Python?
<p>I mean something like</p> <pre class="lang-py prettyprint-override"><code>go_map = 'map[customer_ids:[Test1 Test2]]' parse(go_map) # = {'customer_ids': ['Test1', 'Test2']} </code></pre>
<python><go><parsing>
2023-02-15 20:08:39
0
319
LiaVa
75,464,959
912,757
RSA_private_decrypt padding
<p>I'm encrypting a key with a public key with the <code>cryptography</code> library, in Python.</p> <pre><code>key_path = &quot;key.bin&quot; key = secrets.token_bytes(32) with open(key_path, &quot;w&quot;) as key_file: key_file.write(key.hex()) with open(public_key, &quot;rb&quot;) as public_key_file: public...
<python><rust><openssl><cryptography>
2023-02-15 20:06:53
1
2,397
Nil
75,464,957
5,235,665
Detecting Excel column data types in Python Pandas
<p>New to Python and Pandas here. I am trying to read an Excel file off of S3 (using boto3) and read the headers (first row of the spreadsheet) and determine what data type each header is, <em>if this is possible to do</em>. If it is, I need a map of key-value pairs where each key is the header name and value is its da...
<python><pandas>
2023-02-15 20:06:36
2
845
hotmeatballsoup
75,464,834
18,091,372
What do I need to change so my tornado code can post successfully?
<p>I have the following (with some strings modified) which works when using the <code>requests</code> library.</p> <pre><code>import requests from pprint import pprint import json PEM = '/full/path/to/my.pem' client_id='cliendID' client_secret='clientSecret' USER='myuser' PSWD='mypwd' url = 'https://theurl.com/requ...
<python><curl><python-requests><tornado>
2023-02-15 19:54:23
1
796
Eric G
75,464,642
10,963,057
3d animated line plot with plotly in python
<p>I saw this 3d plot. it was animated and added a new value every day. i have not found an example to recreate it with plotly in python.</p> <p><a href="https://i.sstatic.net/p2XUR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/p2XUR.png" alt="enter image description here" /></a></p> <p>the plot should...
<python><3d><plotly><interactive>
2023-02-15 19:32:41
1
1,151
Alex
75,464,574
14,900,791
Parallel downloading don't work in python threading
<p>I'm building a parallel download library using <code>threading</code> module.</p> <p>When I use my library, it downloads the file without error, but <strong>the video file doesn't have the same content as if I downloaded it through the browser</strong>.</p> <p>I use <code>threading</code> for parallel downloading an...
<python><multithreading><python-requests><download>
2023-02-15 19:25:03
1
1,171
Jurakin
75,464,250
217,586
Unable to move the Stable Diffusion pipeline to my M1 MacBook
<p>I am following the steps stated here: <a href="https://huggingface.co/docs/diffusers/optimization/mps#how-to-use-stable-diffusion-in-apple-silicon-m1m2" rel="nofollow noreferrer">How to use Stable Diffusion in Apple Silicon (M1/M2)</a>.</p> <p>At my local MacBook M1 machine, I saved the below script in stable-diffus...
<python><stable-diffusion>
2023-02-15 18:51:12
1
16,798
Devarshi
75,464,139
6,488,274
"ImportError: libta_lib.so.0: cannot open shared object file: No such file or directory" by restart the google colab
<p>I can successfully install the ta-lib in google colab as follow:</p> <pre><code>import os, sys from google.colab import drive drive.mount('/content/gdrive') nb_path = '/content/notebooks' os.symlink('/content/gdrive/My Drive/Colab Notebooks', nb_path) sys.path.insert(0, nb_path) # or append(nb_path) !wget http:...
<python><google-colaboratory><ta-lib>
2023-02-15 18:39:49
0
387
thomas2004ch