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
βŒ€
78,614,505
6,328,506
How to decode a value stored in Firefox localStorage
<p>I'm trying to decode a value stored in Firefox localStorage on Linux Alpine. I know that Firefox stores localStorage data in <code>/config/.mozilla/firefox/*.default-release/storage/default/&lt;website&gt;/ls/data.sqlite</code>. After extracting the encrypted access_token value using the command <code>sqlite3 data.s...
<python><firefox><encryption><browser><alpine-linux>
2024-06-12 18:50:06
0
416
Kafka4PresidentNow
78,614,458
2,328,154
Snowflake SQLAlchemy - Create table with Timestamp?
<p>I am creating table definitions with SqlAlchemy in Python. I am able to successfully create a table with primary key which autoincrements and some other fields. However, I haven't been able to find any documentation on how to add a field with a timestamp which will be populated when a new record is added. For refere...
<python><sqlalchemy><snowflake-cloud-data-platform>
2024-06-12 18:42:06
1
421
MountainBiker
78,614,281
1,521,496
How does typing.Type work in Python? When can variables be used as types?
<p>I am using Python 3.11 and Pylance for this.</p> <pre><code>class Dog: pass </code></pre> <p>Example A:</p> <pre><code>DogType: type[Dog] = Dog # type[Dog] AnotherDogType: type[DogType] = Dog # Error # ^^^^^^^ variable not allowed in type expression </code></pre> <p>Example B:</p> <pre><code>...
<python><python-typing><pyright>
2024-06-12 17:54:46
1
666
Sidd Singal
78,614,047
3,533,721
Plotly - Renormalise data in response to zooming in on plotly figure
<p>I have some data like:</p> <pre><code>import pandas as pd import datetime as dt import plotly.graph_objects as go # Example data returns = pd.DataFrame({'time': [dt.date(2020,1,1), dt.date(2020,1,2), dt.date(2020,1,3), dt.date(2020,1,4), dt.date(2020,1,5), dt.date(2020,1,6)], 'longs': [0, 1,...
<python><plotly>
2024-06-12 16:52:33
1
1,502
Stuart
78,613,926
10,200,497
How can I merge two dataframes based on last date of each group?
<p>These are my DataFrames:</p> <pre><code>import pandas as pd df1 = pd.DataFrame( { 'close': [100, 150, 200, 55, 69, 221, 2210, 111, 120, 140, 150, 170], 'date': [ '2024-01-01', '2024-01-02', '2024-01-03', '2024-01-04', '2024-01-05', '2024-01-06', '2024-01-07', '2024-01-08',...
<python><pandas><dataframe>
2024-06-12 16:24:22
5
2,679
AmirX
78,613,817
15,461,255
ModuleNotFoundError: No module named '_ssl' running Python3.9
<p>I'm trying to configure a virtual environment with Python3.9 (with other distributions works without problem) in Ubuntu 20.04 LTS but I got the error:</p> <p><code>ModuleNotFoundError: No module named '_ssl'</code></p> <p>I tried with the following solutions found in different posts but none of them worked:</p> <ol>...
<python><ssl><python-3.9>
2024-06-12 16:04:16
0
350
Palinuro
78,613,442
1,882,711
linearly interpolate 1D array against n dimensional arrays over axis in parallel
<p>Is there any way to interpolate an 1D array against two n-dimensional arrays along certain axis?</p> <p>In particular, I have x and y arrays with shapes (6, 2, 10). I also have an x_in array with shape(10, ) that I would like to interpolate along first axis. Is there any elegant way to achieve this with any interpol...
<python><arrays><numpy><scipy><linear-interpolation>
2024-06-12 14:52:35
0
636
GioR
78,613,195
2,819,922
cron job to trigger something on a remote webserver
<p>I have a webserver with ssh access and the possibility to enter a cron job there.</p> <p>I have another second webserver, where I just can create web pages to do some work (via php) when they are called from outside.</p> <p>What's the best way to automate those tasks by using a cron job on the first one? I found pyt...
<python><shell><cron><webserver>
2024-06-12 14:05:54
1
1,835
datafiddler
78,613,148
14,282,714
Remove rows in your dataframe with filling option in streamlit
<p>I'm currently creating a <code>streamlit</code> app that shows the results of user's inputs. It may happen that the user accidentally submitted its results. So I want the user to allow removing its values in the dataframe. The most similar option I found was this <a href="https://discuss.streamlit.io/t/deleting-rows...
<python><streamlit>
2024-06-12 13:59:27
1
42,724
Quinten
78,613,142
2,304,916
Polars: Convert duration to integer number of hours/minutes/seconds
<p>I want to convert a duration to integer number of hour (or minute or seconds). I though the <code>.dt</code> namespace would work the same as for the datetimes, but I get an error instead.</p> <p>This example</p> <pre><code>from datetime import datetime import polars as pl pl.__version__ dx = pl.DataFrame({'dt1': d...
<python><python-polars>
2024-06-12 13:57:52
2
8,154
user2304916
78,612,997
1,427,758
Web uploader using python "requests" to upload 7G file occupies all CPU resources
<p>We have this snippet to upload a file to a web api</p> <pre><code>import requests import json api_url = &quot;https://ourserver/ourserverfolder/api/auth/Login&quot; dto = { &quot;username&quot;: &quot;ourusename&quot;, &quot;password&quot;: &quot;ourpassword&quot; } headers = { 'Content-Type': 'application/json', '...
<python>
2024-06-12 13:33:39
0
7,434
Anders LindΓ©n
78,612,905
12,550,643
Detection small object in game with yolov8 model
<p>I've just started learning about artificial intelligence image capture.I learned that I needed a dataset, so I took a few screenshots.I labeled the objects with roboflow and trained the model with yolov8. But no matter what I did, I could not detect the fish (small, moving, shadowy) object correctly.I think the Prep...
<python><yolov8><roboflow>
2024-06-12 13:14:51
1
479
zafer
78,612,486
329,829
Rolling aggregation in polars and also get the original column back without join or using .over
<p>Using polars <code>.rolling</code> and <code>.agg</code>, how do I get the original column back, without having to join back with the original column, or without having to use <code>.over</code>?</p> <p><strong>Example:</strong></p> <pre class="lang-py prettyprint-override"><code>import polars as pl dates = [ &...
<python><dataframe><window-functions><python-polars><rolling-computation>
2024-06-12 11:57:16
3
5,232
Olivier_s_j
78,612,429
13,349,539
Creating Pytest tests for async API calls with FastAPI and MongoDB
<p>I have an API using FastAPI as the backend and MongoDB as the database. I want to write tests for the API endpoints I have, I have been trying to get a single test up and running but with no luck. My minimum reproducible setup is the following:</p> <p><code>database.py</code>:</p> <pre><code>client = AsyncIOMotorCli...
<python><mongodb><pytest><fastapi>
2024-06-12 11:43:21
2
349
Ahmet-Salman
78,612,423
893,254
Can nonlocal be used to repeatedly reference names in higher levels of scope?
<p>In Python, the <code>nonlocal</code> keyword allows code in an inner scope to access a name in the enclosing scope.</p> <p>To explain this, we can observe the behaviour of this example code, taken from the <a href="https://docs.python.org/3/tutorial/classes.html#scopes-and-namespaces-example" rel="nofollow noreferre...
<python><python-nonlocal>
2024-06-12 11:42:10
1
18,579
user2138149
78,612,411
9,097,114
Python Selenium - Google has stopped working popup
<p>Hi I am trying to do web scraping and code processing successfully, but later after some time(~after 5-6 hours) I am getting error (pop-up) as &quot;Google chrome has stopped working&quot;.<br /> Below are <code>chrome_options</code> that I am using</p> <pre><code>chrome_options = Options() chrome_options.add_argume...
<python><selenium-webdriver><selenium-chromedriver>
2024-06-12 11:39:07
0
523
san1
78,612,335
6,708,508
Celery shared_task not working with pytest in fastapi
<p>I am struggling to test fastapi endpoint that contains a celery task. I would like to mock the celery task. The task is as follows</p> <pre><code>send_email.delay( user.email, &quot;Subject goes here&quot;, html_content, ) </code></pre> <p>Here is how the actual mock function</p> <pre><co...
<python><pytest><celery>
2024-06-12 11:21:38
1
1,408
Muteshi
78,612,251
610,569
How do we add/modify the normalizer in a pretrained Huggingface tokenizer?
<p>Given a Huggingface tokenizer that already have a normalizer, e.g. <code>&quot;mistralai/Mistral-7B-v0.1&quot;</code>, we can do this to modify the normalizer</p> <pre><code>import json from transformers import AutoTokenizer from tokenizers.normalizers import Sequence, Replace, Prepend tokenizer_name = &quot;mistr...
<python><nlp><large-language-model><huggingface-tokenizers>
2024-06-12 11:03:59
1
123,325
alvas
78,612,091
18,107,780
Error implementing a python IDropTarget wrapper for Flet
<p>I'm trying to create a wrapper around the <code>IDropTarget</code> to be able to drag and drop files directly into a <a href="https://flet.dev/" rel="nofollow noreferrer">flet</a> windows app.</p> <p>This is my current implementation, i'm using <code>pythoncom</code>, <code>win32 API</code>, <code>ctypes</code>:</p>...
<python><windows><winapi><memory><flet>
2024-06-12 10:30:50
0
457
Edoardo Balducci
78,612,045
1,259,330
GUI closing unexpectedly
<p>I'm using PyQT6, PyCharm and Python 3.11.</p> <p>Very briefly, I'm trying to convert (mentally) from VBA to Python.</p> <p>I made a GUI in pyQT6, let's call it <code>test.ui</code>. It has a number of buttons and a table. I convert this to a Python file using the pyuic6 utility. I now have a <code>Test.py</code> fil...
<python><pyqt6>
2024-06-12 10:25:09
1
412
perfo
78,611,921
18,618,577
How to exclude file less than x kB from a group read by glob
<p>I think it's very simple but I can't figure it out. In a python program to plot science meteo data I need to exclude some file of a list of text file. I have hundred of file downloaded from a datalogger on the field. Sometimes the LTE link is degraded and instead of receiving a normal text file with normal header, I...
<python><dataframe><glob>
2024-06-12 09:58:39
3
305
BenjiBoy
78,611,893
2,131,200
Drawing hierarchical clustering in scikit-learn
<p>I have an embedding matrix of shape <code>(4312, 1024)</code> (corresponding to 1024-dimensional embedding vectors of 4312 English sentences). I want to perform a clustering of these vectors and to visualize the results (in order to see if the distance threshold that I chose was good enough).</p> <p>The clustering i...
<python><scikit-learn><scipy>
2024-06-12 09:54:10
1
1,606
f10w
78,611,856
5,320,591
PyTest fixture : How to resolve FastAPI 'app' shortcut deprecated warning?
<p>I am trying to solve one for all, this Warning while executing pytests:</p> <pre><code>/usr/local/lib/python3.11/site-packages/httpx/_client.py:680: DeprecationWarning: The 'app' shortcut is now deprecated. Use the explicit style 'transport=WSGITransport(app=...)' instead. warnings.warn(message, DeprecationWarning...
<python><pytest><fastapi><suppress-warnings>
2024-06-12 09:45:34
2
1,546
RobyB
78,611,844
12,932,447
Choose between extras of the same dependency with Poetry
<p>I have a Python project managed with Poetry.</p> <p>I want to install either <code>psycopg[binary]</code> or <code>psycopg[c]</code> via</p> <pre class="lang-bash prettyprint-override"><code>$ poetry install -E pgbinary </code></pre> <p>or</p> <pre class="lang-bash prettyprint-override"><code>$ poetry install -E pgc...
<python><python-poetry><psycopg3>
2024-06-12 09:43:09
2
875
ychiucco
78,611,640
22,326,950
Does SAP GUI scripting with python3 require you to release the connection or is it handled by the garbage collection?
<p><strong>This Post is mainly about scripting in Python but also VBA input is welcome</strong></p> <p>Both in the SAP script recording and in forum posts (e.g. by <a href="https://community.sap.com/t5/technology-blogs-by-members/how-to-use-sap-gui-scripting-inside-python-programming-language/ba-p/13348848" rel="nofoll...
<python><vba><garbage-collection><sap-gui>
2024-06-12 09:04:25
0
884
Jan_B
78,611,602
891,919
How to mount the local filesystem with stlite
<p>I'm trying to create an executable from a streamlit app using <a href="https://github.com/whitphx/stlite" rel="nofollow noreferrer">stlite</a>. I need the app to read and write files on the local filesystem, so I followed <a href="https://github.com/whitphx/stlite/blob/main/packages/desktop/README.md#local-file-acce...
<python><streamlit>
2024-06-12 08:58:51
1
1,185
Erwan
78,611,591
13,942,929
How can I pass optional type from C++ to Cython?
<p>I'm trying to pass an optional argument from C++ to Cython files. I don't know how to write it in .pxd and .pyx file:</p> <p>[C++]</p> <pre><code>std::optional&lt;std::shared_ptr&lt;CPP_MyObject&gt;&gt; cpp_find_value(); </code></pre> <p>[Work.pxd]</p> <pre><code>shared_ptr[CPP_MyObject] cpp_find_value() # fix me ...
<python><c++><cython><cythonize>
2024-06-12 08:57:09
2
3,779
Punreach Rany
78,611,518
891,919
streamlit st.text_input: value not updating as expected
<p>New to streamlit, this is my issue: I’m trying to provide the user with an interface to annotate some data. For each item the user should give a label and may optionally leave a comment, and they can navigate across the different items with β€˜prev’ and β€˜next’ buttons. A basic version of the code is here:</p> <pre><co...
<python><streamlit>
2024-06-12 08:41:29
0
1,185
Erwan
78,611,328
7,396,306
Draw vertical line between points on twinned axes
<p>This question answers how to draw a vertical line between two points on the same axis: <a href="https://stackoverflow.com/questions/59582503/matplotlib-how-to-draw-vertical-line-between-two-y-points">Matplotlib how to draw vertical line between two Y points</a>. But what if we have two separate sets of points each o...
<python><matplotlib>
2024-06-12 07:59:49
1
859
DrakeMurdoch
78,611,287
3,502,079
What does 'nt' stand for in when you type `os.name` in Python on windows?
<p>The questions is basically in the title. Where does 'nt' come from?</p>
<python><windows><operating-system>
2024-06-12 07:52:09
0
392
AccidentalTaylorExpansion
78,611,217
5,014,959
grpc Greeter Service sample fails randomly
<p>I came across a problem with grpc sample code while I was testing waters with it. I noticed that client succeeds, let's say 75% of time but fails at a rate of 25% with following error:</p> <pre><code>grpc._channel._InactiveRpcError: &lt;_InactiveRpcError of RPC that terminated with: status = StatusCode.UNIMP...
<python><grpc><grpc-python>
2024-06-12 07:38:27
0
3,147
Alp
78,611,152
5,699,915
What is the alternative to Whis: 'range'?
<p>Earlier I used <code>whis = 'range'</code> like this:</p> <pre class="lang-py prettyprint-override"><code>box = plt.boxplot(data, whis = 'range', widths = 0.15, patch_artist = True, showfliers = False) </code></pre> <p>In the newer matplotlib versions, <code>whis</code> is a <code>float</code>. Wh...
<python><matplotlib><boxplot>
2024-06-12 07:24:35
2
567
Sri Sanketh Uppalapati
78,611,096
676,192
Trying to access Inkscape from d-bus fails (but works with Gio)
<p>I am trying to use dbus to drive Inkscape from scripts</p> <p>This code - which I got from here - works ok:</p> <pre><code> # Start after inkscape is running. print (&quot;DBus test&quot;) import gi gi.require_version(&quot;Gio&quot;, &quot;2.0&quot;) from gi.repository import Gio, GLib try: bus = Gio.bus_get...
<python><dbus>
2024-06-12 07:08:33
1
5,252
simone
78,610,544
1,822,700
Optimizing variable applied to discrete data in order to minimize error function
<p>I'm trying to optimize a function based on discrete data sets I got in the lab.</p> <p><code>Spectrum_1</code> and <code>Spectrum_2</code> are experimental data sets with length <code>N</code>. Those two arrays contain values taken for each lambda (wavelength) value in <code>lambdas</code> array.</p> <p>So:</p> <pre...
<python><scipy><curve-fitting><scipy-optimize><multivariate-testing>
2024-06-12 03:48:12
1
892
Yannick
78,610,508
1,347,170
Troubleshooting onnxruntime inference - X num_dims does not match W num_dims
<p>Using the nnhash.py script found here: <a href="https://github.com/AsuharietYgvar/AppleNeuralHash2ONNX" rel="nofollow noreferrer">https://github.com/AsuharietYgvar/AppleNeuralHash2ONNX</a></p> <pre class="lang-py prettyprint-override"><code># Copyright 2021 Asuhariet Ygvar # # Licensed under the Apache License, Ver...
<python><reshape><coreml><onnx>
2024-06-12 03:29:55
1
2,017
Joshua Terrill
78,610,246
968,132
Langchain: limiting message history length
<p>My goal is to limit the last N messages in a message history so I don't overload the LLM. My plan is to use use <code>RunnableWithMessageHistory</code> in conjunction with a filter function. Unfortunately I seem to have two problems: 1) getting the limiting function to work; and 2) passing the actual user message in...
<python><langchain><py-langchain>
2024-06-12 00:58:27
1
1,148
Peter
78,610,202
1,313,890
Configure PySpark to use Sunday as Start of Week
<p>According to the <a href="https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.functions.weekofyear.html" rel="nofollow noreferrer">pyspark docs</a> for <code>weekOfYear()</code>, Monday is considered to be the start of the week. However, <code>dayOfWeek()</code> uses Sunday as the s...
<python><apache-spark><date><pyspark><apache-spark-sql>
2024-06-12 00:32:30
0
547
Shane McGarry
78,609,812
202,862
OpenCV on Raspberry Pi Bookworm: cv2.windowMove() is not working
<p>Here's my code:</p> <pre><code>name = &quot;Player&quot; cv2.namedWindow(name, cv2.WINDOW_NORMAL) cv2.resizeWindow(name, 800, 600) cv2.moveWindow(name, 100, 50) </code></pre> <p><code>cv2.moveWindow()</code> does not have any effect at all - seems like it has something to do with Wayland Window Manager which does n...
<python><opencv><user-interface><raspberry-pi>
2024-06-11 21:27:02
1
7,595
Fuxi
78,609,706
13,336,872
ERROR: Could not build wheels for opencv-python, which is required to install pyproject.toml-based projects when installing gym in anaconda env
<p>I was following a chapter in the book <a href="https://github.com/PacktPublishing/Hands-On-Reinforcement-Learning-with-Python" rel="nofollow noreferrer">SUDHARSAN RAVICHANDIRAN - HANDS-ON REINFORCEMENT LEARNING WITH PYTHON - _ master reinforcement and deep reinforcement</a>. There's a handson exercise to work with G...
<python><opencv><pip><anaconda><python-wheel>
2024-06-11 20:52:45
1
832
Damika
78,609,695
6,849,363
Does hacker rank evaluate code for speed?
<p>I am practicing on hacker rank on the following question:</p> <blockquote> <p>Jesse loves cookies and wants the sweetness of some cookies to be greater than value . To do this, two cookies with the least sweetness are repeatedly mixed. This creates a special combined cookie with:</p> <p>sweetness Least sweet cookie...
<python><performance>
2024-06-11 20:50:37
1
470
Tanner Phillips
78,609,621
2,016,632
Since upgrading pandas I can no longer insert a row without a Future Warning. How to fix?
<p>I have a dataframe with a well populated column of datetimes called &quot;ds&quot;. My intention is to insert one row before the others:</p> <pre><code>start = df_p['ds'].iloc[0] - pd.Timedelta(1,&quot;d&quot;) if start not in df_p.index: df_p.loc[start] = np.NaN </code></pre> <p>What I get is:</p> <blockquote> ...
<python><pandas>
2024-06-11 20:26:21
1
619
Tunneller
78,609,465
5,092,134
Animating Yearly Data from Pandas in GeoPandas with Matplotlib FuncAnimation
<p>Using this dataset of % change by state, I have merged it with a cartographic boundary map of US states from the Census department: <a href="https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_state_500k.zip" rel="nofollow noreferrer">https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_state_500k.zip</a...
<python><pandas><matplotlib><geopandas><matplotlib-animation>
2024-06-11 19:36:46
2
1,233
Avery Freeman
78,609,293
3,390,466
How do I perform an atomic XREAD and XDEL on a Redis Stream?
<p>I am trying to design a system on Redis, where:</p> <ul> <li>There is a queue of messages</li> <li>There is a single writer to the queue</li> <li>There are multiple consumers of &quot;messages&quot; in the queue, each continuously reading and consuming messages as they arrive</li> <li>Each message MUST be received b...
<python><redis><stream><queue><publish-subscribe>
2024-06-11 18:47:36
1
4,209
Victor2748
78,609,106
4,669,905
Detect collision and run a function in pymunk
<p>I have a simple setup in pymunk where a circle collides with a segment. On every collision the radius of the circle should increase by an amount I specify (5% in this case). The circle should bounce correctly from the segment even after the radius increases. Here is my implementation but I am facing an issue where t...
<python><pygame><simulation><physics><pymunk>
2024-06-11 17:56:17
1
931
Broly
78,608,972
15,587,184
How can I optimize performance for my Pandas Agent using OpenAI Azure and LangChain?
<p>I have implemented a Pandas Agent using OpenAI Azure and LangChain to handle queries on a dataset. However, I'm encountering performance issues where a simple query takes between 8-12 seconds to execute. Here's a simplified version of my current setup:</p> <pre><code>import pandas as pd from time import time from op...
<python><langchain><agent><azure-openai>
2024-06-11 17:22:12
0
809
R_Student
78,608,874
1,818,935
How to write a FunctionTransformer that outputs a DataFrame with a different number of columns than of the input DataFrame?
<p>Is it possible to use FunctionTransformer to emulate OneHotEncoder? More generally, is it possible to write a FunctionTransformer such that the number of columns in the output DataFrame is different (either lower or higher) than the number of columns in the input DataFrame?</p>
<python><scikit-learn>
2024-06-11 16:56:52
0
6,053
Evan Aad
78,608,557
11,028,689
Color-Coded Time Series Plot Based on Value Sign
<p>I have a dataframe containing positive,negative and zero values.</p> <pre><code>import pandas as pd import numpy as np import matplotlib.pyplot as plt df1 = pd.DataFrame({'A': [-1, 3, 9, 5, 0, -1, -1], 'B': [4, -5, 5, 7, 9, 8, 6], 'C': [7, 5, -3,-1, 5, 9, 3], 'D...
<python><pandas><dataframe><matplotlib>
2024-06-11 15:39:36
3
1,299
Bluetail
78,608,434
7,408,848
cartesian coordinates to label
<p>Using coordinates for labelling? I was asked it was possible and to see for myself, I am trying to program it and read up more on it. I do not know what it is called or where to look but the general idea is as follows:</p> <p>labels are converted into an N-dimensional space and trajectories are calculated along the ...
<python><pandas><labeling>
2024-06-11 15:14:59
1
1,111
Hojo.Timberwolf
78,608,378
2,153,235
Difference between "levenshtein" and "python levenshtein" packages?
<p>I installed the <em>levenshtein</em> module from conda-forge. I don't recall the exact command used, but it was likely something similar to <code>conda install -c conda-forge PackageName</code>. I queried the package versions. I see <em>two</em> packages with exactly the same version number:</p> <pre><code>(py39)...
<python><package><anaconda><conda><levenshtein-distance>
2024-06-11 15:05:12
1
1,265
user2153235
78,608,348
6,912,069
Airflow task_group with list from previous task
<p>Based on the following <a href="https://stackoverflow.com/a/75876007/6912069">answer</a> to a similar question, I'm trying to create an airflow <code>task_group</code> based of an output from a previous task. More precisely, my first task uses the <code>ExecuteSQLQueryOperator</code> which returns a list. And I want...
<python><airflow>
2024-06-11 14:59:11
1
686
N. Maks
78,608,190
3,098,783
FastAPI lifespan event download model across multple gunicorn workers
<p>I want to load a ML model to a local folder. However, I'm using gunicorn with multiple workers, so on startup each of them downloads the model:</p> <pre class="lang-py prettyprint-override"><code>from contextlib import asynccontextmanager from fastapi import FastAPI @asynccontextmanager async def lifespan(app: Fast...
<python><fastapi><gunicorn>
2024-06-11 14:29:03
1
8,471
Jankapunkt
78,608,139
5,838,180
How to set independent parameters for subplots in Plotly?
<p>I’m working with Plotly in Python to create a figure with two subplots, each containing a density contour plot. I want to set different bin sizes (<code>nbinsx</code> and <code>nbinsy</code>) for each subplot. However, it seems that setting these parameters for one subplot affects the other, and I’m unable to have i...
<python><plotly><visualization><plotly-express>
2024-06-11 14:20:35
2
2,072
NeStack
78,608,134
4,994,781
Python namespace with unused attribute detection
<p>I want to refactor some constants so they share namespace in a Python project. Something like this:</p> <pre><code>class MyNamespace(): &quot;&quot;&quot; Does NOT need to be a class, this is just an example. &quot;&quot;&quot; AVOID_MAGIC_NUMBER: int = 10 SOME_TEXT_OUTPUT_MESSAGE: str = 'something' ...
<python><ide><lint>
2024-06-11 14:19:37
0
580
RaΓΊl NΓΊΓ±ez de Arenas Coronado
78,607,976
9,506,773
How do I read the original pdf file in set indexer datasource in a custom WebApiSkill after enabling "Allow Skillset to read file data"
<p>I see the following under my indexer settings:</p> <p><a href="https://i.sstatic.net/68WP1fBM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/68WP1fBM.png" alt="enter image description here" /></a></p> <p>When hovering over it I read the following:</p> <blockquote> <p>True means the original file data...
<python><azure><azure-cognitive-services>
2024-06-11 13:49:16
2
3,629
Mike B
78,607,910
21,612,376
subprocess.run() with capture_output=True
<p>I am very new to Python. I am trying to run some shell commands via Python's <code>subprocess.run()</code>. I would also like to capture the output of the shell commands. When I run the command with <code>capture_output=False</code>, it seems to run fine. But when I switch it to <code>True</code>, I get an error...
<python><subprocess>
2024-06-11 13:39:44
2
833
joshbrows
78,607,866
4,769,503
Why is python not able to find required modules after "pip install" inside a Docker-image?
<p>I have an issue with Python that it can't find any dependencies when running in a container. In my case, I have a fastAPI-based application that runs perfectly on my local machine. When I start the docker image, it complains about every single module as long as I don't do a separate &quot;pip install xyz&quot; with...
<python><docker><pip><fastapi><pipenv>
2024-06-11 13:33:15
1
19,350
delete
78,607,689
4,480,180
Unable to import module 'lambda_function': No module named 'tapo.tapo'
<p>I'm trying to import <a href="https://pypi.org/project/tapo/" rel="nofollow noreferrer">tapo</a> library in a Python Lambda with the following code (which works locally with an equivalent <code>main</code>):</p> <pre><code>import asyncio import os from tapo import ApiClient def lambda_handler(event, context): ...
<python><aws-lambda><pip>
2024-06-11 13:00:24
0
6,884
justHelloWorld
78,607,672
7,307,125
PyVisa lists my ethernet connected device, but error when trying to open resource [python3.11]
<p>I am trying to communicate with TTi power supply model QPX1200SP through ethernet connection.</p> <p>Here is my script:</p> <pre><code>import pyvisa as visa rm = visa.ResourceManager() print(rm.list_resources(query='TCP?*')) #specific query for anything over Ethernet #above line gives me an answer ('TCPIP0::10.10.0...
<python><windows><visa><pyvisa>
2024-06-11 12:57:26
1
351
smajli
78,607,642
2,736,559
How to remove motion blur from a given image in frequency domain (deconvolution)?
<p>I have read that if we have the <code>PSF</code> of a given image, using deconvolution we can reverse the distortion and get the original image. I tried to do the same thing, however, I'm getting an image that looks like complete noise:</p> <pre class="lang-py prettyprint-override"><code>def add_motion_blur(img, siz...
<python><image-processing><signal-processing><fft><deconvolution>
2024-06-11 12:52:43
1
26,332
Hossein
78,607,634
1,182,299
Python parsing a JSON file outputs only one result
<p>I'm pretty new to json, I try to parse two elements (multiple occurences), I'm pretty sure I don't iterate correctly.</p> <p>My json file:</p> <pre><code>{ &quot;data&quot;: { &quot;chapter&quot;: { &quot;bibleId&quot;: &quot;9f3cb709f9bded60-01&quot;, &quot;bookId&quot;: &quot;PSA&quot;, &qu...
<python><json><parsing>
2024-06-11 12:51:53
3
1,791
bsteo
78,607,624
9,261,745
databricks notebook pip install python wheel error
<p>I try to install the python wheel in the dbfs in databricks. I first run below to confirm that I have that python wheel.</p> <pre><code>display(dbutils.fs.ls(&quot;dbfs:/FileStore/python-wheels/&quot;)) </code></pre> <p><a href="https://i.sstatic.net/8MN83CtT.png" rel="nofollow noreferrer"><img src="https://i.sstati...
<python><databricks><python-wheel>
2024-06-11 12:50:13
1
457
Youshikyou
78,607,542
13,491,504
Simulation of a spring loaded pendulum on a spinning disk
<p>I want to write a simulation in Python similar to the one described in <a href="https://stackoverflow.com/questions/78227144/simulation-of-a-pendulum-hanging-on-a-spinning-disk">Simulation of a Pendulum hanging on a spinning Disk</a>.</p> <p>But I want the system to be spring loaded. So instead of the mass hanging f...
<python><sympy><simulation>
2024-06-11 12:38:57
1
637
Mo711
78,607,374
4,340,985
How to add (and use) a secondary y axis with subplot_mosaic?
<p>I'm setting up a somewhat elaborate plot (should end up as a pdf page at the end) and for that <a href="https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.subplot_mosaic.html#matplotlib.figure.Figure.subplot_mosaic" rel="nofollow noreferrer"><code>subplot_mosaic</code></a> seems like a great solution...
<python><matplotlib>
2024-06-11 12:06:40
0
2,668
JC_CL
78,607,283
6,195,489
How do I use numpys interpolation with xarrays
<p>I have some code that does a linear interpolation on data.</p> <p>In the case where the data is numpy arrays it works as I would expect.</p> <pre><code>amplitude = np.interp(reflected_times, times, trace) </code></pre> <p>gives (zoomed in to show the interpolation clearly):</p> <p><a href="https://i.sstatic.net/pBGC...
<python><numpy><interpolation><dask><python-xarray>
2024-06-11 11:46:06
0
849
abinitio
78,607,247
908,773
Python subprocess run hanging with psql result in kubernetes pod
<p>I'm trying to get a list of databases from a Kubernetes pod. This works and databases are printed in the terminal:</p> <pre><code> result = subprocess.run(['kubectl', '--context', 'my-context', '-n', 'mynamespace', 'exec', '-it', 'postgres-helper-58dc64d7f4-cmkxl', '--', '/bin/bash', '-c', 'psql postgresql://postgre...
<python><kubernetes><psql>
2024-06-11 11:37:16
0
4,767
martincho
78,607,175
13,123,667
Run Yolov8 for Python 3.6
<p>Yolov8 is build to run with 3.8 or above and <code>pip install ultralytics</code> is not compatible with prior versions.</p> <p>I have the constraint of using a prior version of Python to execute the code on a microcomputer like Jetson Nano or Jetson Xavier.</p> <p>I've seen on many issues of Yolov8 repository peopl...
<python><python-3.6><yolov8><nvidia-jetson><ultralytics>
2024-06-11 11:23:27
1
896
Timothee W
78,607,131
12,297,666
Different values in matplotlib piechart from the pandas dataframe
<p>Check this code:</p> <pre><code>import matplotlib.pyplot as plt import pandas as pd data = { 'RegiΓ£o': ['NORTE', 'SUDESTE', 'NORDESTE', 'CENTRO OESTE', 'SUL'], 'PNT &quot;Real&quot; sobre mercado BT (%)': [52.75, 15.04, 12.82, 8.23, 8.04] } data = pd.DataFrame(data) data.set_index('RegiΓ£o', inplace=True) p...
<python><matplotlib>
2024-06-11 11:16:43
2
679
Murilo
78,607,097
5,953,534
Python KeyError in x.get("key")
<p>This is a weird error I am seeing in a log file in python.</p> <pre class="lang-py prettyprint-override"><code>import traceback mat = [{&quot;a&quot;: 1, &quot;b&quot;: 2}, {&quot;a&quot;: 3, &quot;b&quot;: 4}] def fun(a, b, c): if c is None: return a + b else: return a + b + c try: fo...
<python><cpython>
2024-06-11 11:09:50
1
663
Florian
78,606,853
7,166,834
extract rows with change in consecutive values of a column from pandas dataframe
<p>I am trying to extract the rows where consecutive value changes for a particular column</p> <p>Ex:</p> <pre><code>sno A B 1 a yes 2 b yes 3 c No 4 d No 5 e No 6 f yes 7 g yes 8 h yes 9 I No </code></pre> <p>Output:</p> <pre><code>sno A B 2 b yes 3 c No 5 e ...
<python><pandas>
2024-06-11 10:19:42
3
1,460
pylearner
78,606,822
6,156,353
Build Python wheel for ARM macOS on Linux
<p>I would like to build a python wheel package for ARM macOS but I have only Linux server (Gitlab CI). Is it possible to build wheel for ARM Mac on Linux server? If so how? I did not find much relevant information using Google.</p>
<python><linux><macos><python-wheel>
2024-06-11 10:13:10
0
1,371
romanzdk
78,606,744
7,729,531
Find embedded document based on nested embedded document ID in MongoEngine
<p>I have the following schema:</p> <pre class="lang-py prettyprint-override"><code>class Feature(EmbeddedDocument): feature_name = StringField(required=True) geometry = PolygonField(required=True) id = ObjectIdField(required=True, default=ObjectId, unique=True, primary_key=True) class Label(EmbeddedDocume...
<python><mongodb><mongoengine>
2024-06-11 09:58:39
0
440
tvoirand
78,606,656
5,568,409
How to modify Arviz.Plot.Trace?
<p>With these small lines:</p> <pre><code>with model: az.plot_trace(data=idata, kind=&quot;trace&quot;, legend=True, figsize=(6, 3)) plt.suptitle(&quot;Model Trace&quot;, fontsize=20) </code></pre> <p>I can modify a bit (general title and size) the trace plot as shown below:</p> <p><a href="https://i.sstatic.ne...
<python><arviz>
2024-06-11 09:40:59
0
1,216
Andrew
78,606,535
4,767,829
statsmodels.graphics.mosaicplot of a MultiIndex DataFrame
<p>I have collected the frequencies in which combinations of certain categorical parameters occur in a DataFrame. Applying a groupby operation produced another DataFrame with a MultiIndex. Now I would like to visualize the frequencies in a mosaic plot. This is what I have tried:</p> <pre><code>rows=[ {&quot;Mode&qu...
<python><pandas><dataframe><mosaic-plot>
2024-06-11 09:21:17
2
705
Stefan Reisner
78,606,466
10,131,952
Regex Pattern to allow alphanumeric and square brackets with text insde it
<p>I am using regex to allow alphanumeric, underscore, hyphen and square brackets in a text box. regex i am using to validate input is</p> <pre><code> r'^[a-zA-Z0-9_\-\[\] ]*$. </code></pre> <p>I need to modify the regex such that if empty brackets are given it should return false.</p> <p>Sample cases</p> <p>&quot;You...
<python><django><regex>
2024-06-11 09:09:29
5
413
padmaja cherukuri
78,606,254
2,753,629
Escaping {} surrounding a variable to be formatted
<p>I need to generate a string where the variable should end up between {}. For instance, the result should be</p> <pre><code>{0.05} and {4} </code></pre> <p>I tried to get this using</p> <pre><code>&quot;{{}} and {{}}&quot;.format(0.05, 4) </code></pre> <p>However, this leads to</p> <pre><code>{} and {} </code></pre> ...
<python><format>
2024-06-11 08:28:07
2
4,349
Mike
78,606,238
12,304,000
escaping backslashes in MySQL for CSV interpretation
<p>In my S3, I have a CSV file that looks like this:</p> <pre><code>&quot;id&quot;,&quot;created_at&quot;,&quot;subject&quot;,&quot;description&quot;,&quot;priority&quot;,&quot;status&quot;,&quot;recipient&quot;,&quot;recipient_id&quot;, </code></pre> <p>Now, one of the <code>description</code> column's <strong>row<...
<python><mysql><csv>
2024-06-11 08:24:39
0
3,522
x89
78,606,105
676,192
Non-blocking loop inside an inkscape extension
<p>Is it possible to have a non-blocking loop constantly running from within an Inkscape extension?</p> <p>I would like - for example - to be able to pass information back and forth to another application every time I update the drawing.</p> <p>I have tried threads and forking, but neither releases control to Inkscape ...
<python><inkscape>
2024-06-11 07:54:41
0
5,252
simone
78,605,817
6,930,340
How to replace an individual level in a multi-level column index in pandas
<p>Consider the following multi-level column index dataframe:</p> <pre><code>import numpy as np import pandas as pd arrays = [ [&quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;B&quot;], [&quot;one&quot;, &quot;two&quot;, &quot;one&quot;, &quot;two&quot;], [&quot;1&quot;, &quot;2&quot;, &quot;1&quot;, &q...
<python><pandas><multi-index>
2024-06-11 06:48:45
4
5,167
Andi
78,605,727
5,130,253
Exception stack trace not clickable in PyCharm
<p>PyCharm suddenly changed the way it shows the stack trace on the run tab and does not let me click on the exception (or anywhere else) and go to the specific point of the error file anymore.</p> <p>How can I fix this?</p> <p>Running on OSX Sonoma, PyCharm 2022.2.3 (Community Edition)</p> <p><a href="https://i.sstati...
<python><pycharm><stack-trace><torchmetrics>
2024-06-11 06:24:12
1
502
sofia
78,605,344
5,003,606
How to fix grpc._channel._MultiThreadedRendezvous fails; StatusCode.UNAVAILABLE; Query timed out
<p>I have a Python function that takes a cloud Firestore collection name as an arg and streams thru every document in that collection to check for errors.</p> <p>In simplified form, it essentially looks something like this:</p> <pre><code>from firebase_admin import firestore def find_all_issues(collection: str) -&gt; ...
<python><google-cloud-firestore><timeout>
2024-06-11 04:03:16
0
951
HaroldFinch
78,605,165
14,046,126
Airflow: Failing to push data back into the pipeline
<p>I have setup a workflow, which consists of two tasks:</p> <p>In second, I am successfully pulling data pushed into the pipeline by the first task. However, after processing data, when I try to push data back into the pipeline, I get the error &quot;INFO - Task exited with return code -9&quot;.</p> <p>Here are the lo...
<python><airflow><etl><airflow-xcom>
2024-06-11 02:30:25
2
2,726
Pranav Rustagi
78,604,978
4,561,700
keras.utils.get_file() throws TypeError: '<' not supported between instances of 'int' and 'NoneType'
<p>I am trying to follow along with the book <strong>Applied Deep Learning and Computer Vision for Self-Driving Cars</strong>. I am running into issues with keras while running some of the example code. When trying to grab a file using the get_file() function, I am getting a type error.</p> <p>System: Windows 10 | Pyth...
<python><python-3.x><tensorflow><keras>
2024-06-11 00:46:00
1
310
RPBruiser
78,604,957
770,513
Undoing a migration for a duplicate field
<p>We have had a duplicate field added to of our Django Wagtail models which has confused the migration system.</p> <p>The following was added to one of the models while back along with a migration that added a singular instance of the field:</p> <pre><code> stream = fields.StreamField( who_funds_you_blocks,...
<python><django><database><migration><wagtail>
2024-06-11 00:33:23
1
3,251
KindOfGuy
78,604,888
1,606,657
Auto detect tabs or spaces for Python projects
<p>I'm aware of the setting <code>set expandtab</code> and <code>set noexpandtab</code> which can trigger to use spaces or tabs accordingly.</p> <p>The problem I'm facing is that I'm working on different Python projects that are sometimes using spaces and sometimes tabs. I don't want to reformat all the code when I st...
<python><tabs><neovim>
2024-06-10 23:48:50
1
6,352
wasp256
78,604,863
6,227,035
Sorting dictionary values in Python
<p>I have a data structure as follow:</p> <pre><code>Clients= { &quot;data&quot;: [ { &quot;nClients&quot;: 3 }, { &quot;name&quot;: &quot;cTest1&quot;, &quot;roll_no&quot;: 1, &quot;branch&quot;: &quot;c&quot; }, { &quot;na...
<python><json><sorting><alphabetical>
2024-06-10 23:41:51
1
1,974
Sim81
78,604,689
19,048,408
With Python Polars, how to compare two frame (like with `==`), but while returning True/False on comparisons with null
<p>With python polars, how can I compare two dataframes (like with <code>==</code>), and get a comparison result per-cell, but while returning <code>True</code>/<code>False</code> on comparisons with null. By default, doing <code>df1 == df2</code> results in <code>null</code> being in any cells where either <code>df1</...
<python><dataframe><python-polars>
2024-06-10 22:13:24
3
468
HumpbackWhale194
78,604,335
4,936,825
Bland-Altman plots
<p>I need to make Bland-Altman plots, but I cannot find a good R or Python package for this.</p> <p>So far, I've found a single function in Statsmodels and another one in a package called Pingouin. But neither of these seem to cover the case with proportional bias or heteroskedastic differences.</p> <p>Is there an R or...
<python><r><statistics><statistical-test>
2024-06-10 20:05:20
1
723
Milad Shahidi
78,604,225
5,219,890
numpy : f-ordered arrays have slower assignment than their transpose
<p>If I have an array: <code>x = np.array(np.random.rand(2000, 400), order='F')</code>, and create a mask: <code>y = (x &gt; .5)</code> (which also happens to become F-contiguous), then the following code:</p> <p><code>x[y] = np.nan</code></p> <p>Is significantly slower than: (with twice the time taken)</p> <p><code>x....
<python><numpy>
2024-06-10 19:36:38
0
549
Vedaant Arya
78,604,108
864,598
Python in VSCode Editor does not recognize modules in same folder
<p>As you can see in image below, thread_processor and order_processor is in the same folder as main.py, yet it does not recognize as a module. Its is looking only at the root folder ..</p> <p>even adding below code in launch.json is not helping either ... THanks</p> <pre><code>{ &quot;configurations&quot;: [ ...
<python><visual-studio-code>
2024-06-10 19:01:44
2
1,014
M80
78,604,097
11,141,816
How to capture printed messages in parallel process?
<p>I have a function <code>parallel_run</code> which print out the diagnostic message during the run and then return a result. I want to capture the printed message and also the returned value. However, somehow I got many error messages.</p> <pre><code>import concurrent.futures import matplotlib.pyplot as plt import io...
<python><parallel-processing><io><concurrent.futures>
2024-06-10 18:57:48
0
593
ShoutOutAndCalculate
78,604,018
836,026
ImportError: cannot import name 'packaging' from 'pkg_resources' when trying to install causal_conv1d
<p>I was trying to install &quot;causal_conv1d&quot; using:</p> <pre><code>pip install --no-cache-dir -t /scratch/ahmed/lib causal_conv1d==1.0.0 </code></pre> <p>The error I got is:</p> <pre><code>Collecting causal_conv1d==1.0.0 Downloading causal_conv1d-1.0.0.tar.gz (6.4 kB) Preparing metadata (setup.py) ... err...
<python><pytorch><pip><anaconda><mamba-ssm>
2024-06-10 18:39:14
2
11,430
user836026
78,603,913
10,140,821
Find the 1st business day and last business day of the previous month based on a date
<p>I have a use case like this in Python: Find the 1st business day and last business day of the previous month based on a date. For example if date is <code>2024-06-10</code></p> <pre><code>first_business_day = '2024-05-01' last_business_day = '2024-05-31' </code></pre> <p>I have tried like below</p> <pre><code>run_da...
<python><date>
2024-06-10 18:08:17
2
763
nmr
78,603,841
2,153,235
More detailed info about data type that is common throughout a Series?
<p>I have a dataframe column consisting entirely of a common type <code>dict</code>. Is there any way to query the Series type to reveal the common data type? It currently only tells me that it is an object, which I understand is an array of references. But if the things being referenced are of the same type for an ...
<python><pandas><types><series><dtype>
2024-06-10 17:53:57
1
1,265
user2153235
78,603,728
4,577,467
How to embed Python 3.12 in a Windows C++ app?
<p>The operating system is Windows 10.</p> <p>I downloaded the installer for Python 3.12.3 from <a href="https://www.python.org/downloads/" rel="nofollow noreferrer">https://www.python.org/downloads/</a>. During custom installation, I chose a install location: <code>D:\Programs\Python\Python312</code></p> <p>After ins...
<python><c++><python-3.x><embed>
2024-06-10 17:24:56
2
927
Mike Finch
78,603,690
8,049,947
Information_schema INVALID IDENTIFIER from snowflake when trying to access query history through a python script
<p>I am currently working with Snowflake to view the query history. However, when I attempt to execute the same command in Python, following its syntax rules, I encounter an error stating <code>β€˜INVALID IDENTIFIER’ for β€˜information_schema’</code>.</p> <p><code>select * from table(information_schema.query_history()) </c...
<python><snowflake-cloud-data-platform>
2024-06-10 17:15:48
1
308
panther93
78,603,623
4,408,275
Redirect stdout/stderr in tkinter GUI app when launched with **pythonw**
<p>I want to launch a python GUI application on Windows.</p> <p>To <strong>not</strong> block the console if started I need to use <code>pythonw</code> to run this application.</p> <p>Additionally, I need to provide a batch script that does some setup and users need to run the application trough that script. When users...
<python><tkinter>
2024-06-10 16:56:48
0
1,419
user69453
78,603,611
3,663,742
django flatpages will show only one page
<p>I'm trying to use flatpages in my Django application. I installed it properly as far as I can see and created 2 pages. Using the shell, when I try:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; from django.contrib.flatpages.models import FlatPage &gt;&gt;&gt; FlatPage.objects.all() &lt;QuerySet [&...
<python><django><django-flatpages>
2024-06-10 16:54:04
1
436
Olivier
78,603,549
13,142,245
FastAPI run config commands before serving application?
<p>Does FastAPI automatically configure environment, imports, ML model instantiation, etc. when you run <code>uvicorn Package.API:app --reload --port 8001</code> ?</p> <p>The result I'm seeing is</p> <pre><code>INFO: Will watch for changes in these directories: ['/Users/me/Documents/application'] INFO: Uvicorn ...
<python><fastapi>
2024-06-10 16:39:01
1
1,238
jbuddy_13
78,603,383
13,187,876
Write data directly to blob storage from an Azure Machine Learning Studio notebook
<p>I'm working on some interactive development in an Azure Machine Learning notebook and I'd like to save some data directly from a <code>pandas DataFrame</code> to a <code>csv</code> file in my default connected blob storage account. I'm currently loading some data the following way:</p> <pre><code>import pandas as pd...
<python><pandas><azure><machine-learning><azure-machine-learning-service>
2024-06-10 16:05:39
1
773
Matt_Haythornthwaite
78,603,297
13,049,379
Split a PIL image into multiple regions with a patch included in one of the split region
<p>I need to write a python code that accepts a PIL image and split the image into M rows and N columns, such that one of the split region completely contains a patch of height H and width W starting at point (p,q).</p> <p>I am mostly able to write the code and my attempt is shown below, but not able to generalise for ...
<python><numpy><image><python-imaging-library>
2024-06-10 15:45:39
1
1,433
Mohit Lamba