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
79,210,075
13,238,846
How to get timestamps in Azure text to Speech Synthesized Audio
<p>I am trying get timestamps for the generated audio using Azure Text to Speech. I have configured the speech config correctly but I can't find any property related to timestamps in response object. Following code is my code.</p> <pre><code>speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service...
<python><azure><text-to-speech><azure-speech>
2024-11-21 07:21:22
1
427
Axen_Rangs
79,209,946
2,998,077
Python and Pandas to write large amount dataframe
<p>A script is generating 50000 dataframe of below structure, and save them 1-by-1 to local disk. To improve efficiency, I changed the write-to format from Excel to Parquet. However, it seems not running faster.</p> <p>The 50000 dataframe are then to be lopped to filter the rows when the Meet column is 4 or 5, to save ...
<python><dataframe>
2024-11-21 06:34:26
4
9,496
Mark K
79,209,922
294,103
Fetching multiple urls with aiohttp from a loop/generator
<p>All examples I saw for fetching multiple urls with <code>aiohttp</code> suggest to to the following:</p> <pre><code>async def fetch(session, url): async with session.get(url, ssl=ssl.SSLContext()) as response: return await response.json() async def fetch_all(urls, loop): async with aiohttp.ClientSe...
<python><python-asyncio><aiohttp>
2024-11-21 06:26:04
1
5,784
dragoon
79,209,872
178,732
Function with Python type hint which accepts a class A and outputs a class that inherits from A
<p>I am trying to implement a decorator looks like</p> <pre class="lang-py prettyprint-override"><code>def decorator(cls): class _Wrapper(cls): def func(self): super().func() print(&quot;patched!&quot;) return _Wrapper </code></pre> <p>and I am wondering how do I hint the <code>c...
<python><python-typing>
2024-11-21 06:03:39
2
24,932
xis
79,209,784
9,542,989
`ConversationSummaryBufferMemory` is not fully defined; you should define `BaseCache`, then call `ConversationSummaryBufferMemory.model_rebuild()`
<p>I am attempting to use LangChain's <code>ConversationSummaryBufferMemory</code> and running into this error:</p> <pre><code>pydantic.errors.PydanticUserError: `ConversationSummaryBufferMemory` is not fully defined; you should define `BaseCache`, then call `ConversationSummaryBufferMemory.model_rebuild()`. </code></p...
<python><langchain><py-langchain>
2024-11-21 05:29:44
1
2,115
Minura Punchihewa
79,209,754
98,494
Django: Objects that live throughout server lifetime
<p>I have some data in csv format that I need to load into the application once and then reuse it throughout the lifetime of the application, which is across multiple requests. How can I do that?</p> <p>An obvious method for me is to have a module that will load the data and then expose it. However, I don't like module...
<python><django>
2024-11-21 05:16:00
1
42,356
gruszczy
79,209,753
8,742,237
llama-index RAG: how to display retrieved context?
<p>I am using LlamaIndex to perform retrieval-augmented generation (RAG).</p> <p>Currently, I can retrieve and answer questions using the following minimal 5 line example, from <a href="https://docs.llamaindex.ai/en/stable/getting_started/starter_example/" rel="nofollow noreferrer">https://docs.llamaindex.ai/en/stable/...
<python><large-language-model><llama-index><rag>
2024-11-21 05:15:51
1
1,802
Jeremy K.
79,209,572
8,055,123
Log Pearson3 distribution fitting using scipy and lmoments3 in Python
<p>I am trying to find a way to fit Log Pearson3 distribution to my streamflow data but I can't find the way how to! Any tips will be much appreciated. Here is the problem:</p> <p>Both scipy and lmoment3 packages have Pearson3 but they don't have Log Pearson3 distributions to fit! scipy uses the Maximum Likelihood Esti...
<python><scipy>
2024-11-21 03:18:06
0
311
Navid Ghajarnia
79,209,481
2,137,570
python - macOS Sequoia: reading plist
<p>trying to read plist in macOS sequoia. I did find <a href="https://pypi.org/project/plists/#description" rel="nofollow noreferrer">https://pypi.org/project/plists/#description</a> but it doesn't install</p> <p><strong>How can I use python plists package?</strong></p> <blockquote> <p>pip3 install plists</p> </blockqu...
<python><plist><macos-sequoia>
2024-11-21 02:27:45
2
5,998
Lacer
79,209,425
5,256,563
Build a wheel and Install package version depending on OS
<p>I have several python packages that need to be installed on various os/environments. These packages have dependencies and some of them like Polars needs a different package depending on the OS, for example: polars-lts-cpu on MacOS (Darwin) and polars on all the other OS.</p> <p>I use <code>setuptools</code> to creat...
<python><setuptools><python-polars><python-packaging><python-wheel>
2024-11-21 01:46:23
1
5,967
FiReTiTi
79,209,419
14,590,651
Linux check bluetooth RSSI without pair and connect
<p><strong>Background:</strong> I'm building a distance sensor for my auto door lock which uses the bluetooth signal strength. The code runs on my raspiberry pi and detects my phone bluetooth address. It only needs to see if my phone is in a very close distance or a relatively far distance, so the RSSI should be stable...
<python><linux><raspberry-pi><bluetooth>
2024-11-21 01:41:01
1
536
Josh Liu
79,209,129
663,028
Any way to create a subset (or partially clone) from a conda environment?
<p>For example, I have a working environment with 300 packages. Is there a clean way to duplicate or clone from this environment with only 100 packages, without the need to resolve/download dependencies?</p> <p>I could manually copy the folder and delete a bunch of stuff that is not needed, but a &quot;subcloning&quot;...
<python><anaconda><conda>
2024-11-20 22:26:07
1
7,151
prusswan
79,209,096
3,458,191
How to move python function to the conftest as fixture?
<p>I have the following python code:</p> <p>main.py:</p> <pre><code>import pytest import re from playwright.sync_api import Page, expect from time import sleep TIMEOUT = 5000 # 5 seconds # Helper function to send a message and assert response def send_msg_and_assert(page: Page, message: str, regex: re.Pattern): ...
<python><python-3.x><pytest><playwright-python><playwright-test>
2024-11-20 22:04:30
0
1,187
FotisK
79,208,995
2,731,076
Type hinting in Python 3.12 for inherited classes that use the parent class method without typing module
<p>I have a parent class that I made along with a number of child classes that inherit from the parent class. These classes are essentially just python models to read certain documents in from a json or MongoDB and change them from a dictionary into a class. Because of that, I have a standard <code>from_file</code> cla...
<python><inheritance><python-typing>
2024-11-20 21:19:15
1
813
user2731076
79,208,862
8,576,801
In a Jupyter Notebook open in VS Code, how can I quickly navigate to the currently running cell?
<p>This feels like a useful feature but haven't been able to find a setting / extension that offers this capability.</p>
<python><visual-studio-code><jupyter-notebook><jupyter>
2024-11-20 20:27:36
1
428
piedpiper
79,208,817
13,259,162
Get a single series of classes instead of one series for each class with pandas in Python
<p>I have a DataFrame with 3 column of zeroes and ones corresponding to 3 different classes. I want to get a single series of zeroes, ones, and twos depending of the class of the entry (0 for the first class, 1 for the second one and 2 for the third one):</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt;...
<python><pandas><numpy>
2024-11-20 20:11:07
2
309
Noé Mastrorillo
79,208,808
10,193,760
String cleaning removing consecutive value and put comma in the end
<p>I have this string from an email I'm scraping:</p> <pre><code>TICKET\xa0\xa0 STATE\xa0\xa0\xa0\xa0 ACCOUNT IDENTIFIER\xa0\xa0\xa0 FILE DIRECTORY\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0 ...
<python><string><text><replace><split>
2024-11-20 20:07:23
1
1,610
Maku
79,208,772
823,633
pandas apply multiple columns
<p>Starting from this dataframe</p> <pre><code>df = pd.DataFrame( np.arange(3*4).reshape((4, 3)), index=['a', 'b', 'c', 'd'], columns=['A', 'B', 'C'] ) print(df) A B C a 0 1 2 b 3 4 5 c 6 7 8 d 9 10 11 </code></pre> <p>I want to apply two functions to each column to generate two col...
<python><pandas>
2024-11-20 19:56:32
2
1,410
goweon
79,208,694
15,835,974
How to join 2 DataFrames on really specific condition?
<p>I have those 2 DataFrames:</p> <pre><code>df1: +---+----------+----------+ |id |id_special|date_1 | +---+----------+----------+ |1 |101 |2024-11-01| |2 |102 |2024-11-03| |3 |103 |2024-11-04| |4 |null |2024-11-05| +---+----------+----------+ df2: +----------+----------+------+ |id_specia...
<python><pyspark>
2024-11-20 19:32:36
1
597
jeremie bergeron
79,208,656
194,305
migrating from distutils to setup tools
<p>I am migrating a large library of python cpp extensions form swig+distutils to swig+setuptols. I am using swig cpp example as the illustration. The original setup.py file:</p> <pre><code>from distutils.core import setup, Extension from distutils.command.build_ext import build_ext example_module = Extension( nam...
<python><python-3.x><setuptools><swig><distutils>
2024-11-20 19:20:07
0
891
uuu777
79,208,598
10,153,071
Unable to update a latent vector using custom loss function in pytorch
<p>I am trying to implement this function but have had no luck. There is a VAE model that I am using, and along with it, there are encoder and decoder. I'm freezing the weights of the VAE decoder, and trying to change a latent vector which is updated using the function <em><strong>optimize_latent_vector(model, inp__, n...
<python><deep-learning><pytorch><autograd>
2024-11-20 18:52:44
1
536
Jimut123
79,208,551
268,581
Two stacked area plots on the same chart
<h1>Plotting assets</h1> <p>I'm plotting $MSTR assets as follows</p> <pre><code>fig = px.area(df_all, x='end', y='val', color='fact', title=f'{symbol.upper()} : Balance sheet', width=1000, height=600) fig.add_trace(go.Scatter(x=df_assets['end'], y=df_assets['val'], mode='lines', name='Assets')) st.plotly_chart(fig) <...
<python><plotly><streamlit>
2024-11-20 18:33:43
1
9,709
dharmatech
79,208,459
6,829,370
Implementing Georeferencer transforms using QGIS Python API
<p>I can see in QGIS Georeferencer plugin(under Layer menu) various transform algorithms in Transformation settings (under transformation type) such as 'Linear','Polynomial 1','Polynomial 2','Helmert','Projective' etc. How can we directly use these transformations using Qgis Python API ? Please guide.</p>
<python><transform><geospatial><qgis><pyqgis>
2024-11-20 18:00:51
1
388
Shubham_geo
79,207,981
7,456,317
Python logger: a different log record attribute for each thread
<p>My use case is as follows: I have a server that handles requests, and for each request I'd like the log record to contain a <code>user_id</code>. I'd like to make it as seamless as possible for other developers in my team, such that they can simply import <code>logging</code> and use it, without passing user_id arou...
<python><multithreading><logging>
2024-11-20 15:50:05
1
913
Gino
79,207,951
773,102
Python wheel entry point not working as expected on Windows
<p>I'm tryring to setup a python wheel for my testrunner helper script to make it easyly acessible from everywhere on my Windows machine. Therefore I configure a console entry point in my setup.py. I can see the generated entry point in the entry_points.txt but if I'm trying to invoke my script I get the error message....
<python><python-wheel>
2024-11-20 15:40:27
1
1,483
Jonny Schubert
79,207,883
9,518,890
Workday returns 406 error (Server.governedError)
<p>I am having trouble getting some data from Workday, specifically from financial management &amp; <code>Get_Journals</code> operation using this <a href="https://community.workday.com/sites/default/files/file-hosting/productionapi/Financial_Management/v43.1/Get_Journals.html#Journal_Entry_Response_GroupType" rel="nof...
<python><soap><workday-api>
2024-11-20 15:27:07
0
14,592
Matus Dubrava
79,207,871
6,930,340
Replace last two row values in a grouped polars DataFrame
<p>I need to replace the last two values in the <code>value</code> column of a <code>pl.DataFrame</code> with zeros, whereby I need to <code>group_by</code> the <code>symbol</code> column.</p> <pre><code>import polars as pl df = pl.DataFrame( {&quot;symbol&quot;: [*[&quot;A&quot;] * 4, *[&quot;B&quot;] * 4], &quot...
<python><python-polars>
2024-11-20 15:24:34
2
5,167
Andi
79,207,658
12,820,223
Python package still unavailable after installing with venv
<p>I know this has been answered many times but I've been through the answers and it still won't work. I want to install package <code>&lt;some_package&gt;</code> so that I can use it through <code>import</code> in a script I run often.</p> <p>I tried using <code>pipx</code>, but that obviously installs the package in ...
<python><macos>
2024-11-20 14:33:48
2
411
Beth Long
79,207,577
945,034
Number out of representable range: type FIXED[SB4] with Snowflake Python Connector
<p>I have a typical ETL project where I am reading a csv file into a Pandas dataframe and need to write this DataFrame to a Snowflake table</p> <pre class="lang-py prettyprint-override"><code> with og_snowflake_resource.get_connection() as sf_conn: write_pandas(conn=sf_conn, overwrite=False, df=raw_df, tab...
<python><pandas><snowflake-cloud-data-platform>
2024-11-20 14:13:52
0
7,775
Kumar Sambhav
79,207,548
24,191,255
Determination of cutoff frequency for filtering
<p>I would like to determine the choice of cutoff frequency for e.g., a second-order low-pass Butterworth filter using frequency spectrum analysis. For this purpose, I would like to implement Fast Fourier Transformation on my data using <code>scipy.fftpack</code>.</p> <p>After transforming the signal, I smoothed the sp...
<python><filter><scipy><signal-processing><fft>
2024-11-20 14:04:48
0
606
Márton Horváth
79,207,543
19,500,571
Plotly: Increasing figure size to make room for long footnote
<p>Building on the example in this <a href="https://stackoverflow.com/questions/67055505/plotly-dash-how-to-add-footnotes-and-source-text-to-plots">thread</a>, I have the following code:</p> <pre><code>import plotly.express as px import plotly.graph_objects as go import pandas as pd df = pd.read_csv('https://raw.githu...
<python><plotly><visualization>
2024-11-20 14:02:15
1
469
TylerD
79,207,488
4,847,250
How do I represent sided boxplot in seaborn when boxplots are already grouped?
<p>I'm seeking for a way to represent two sided box plot in seaborn. I have 2 indexes (index1 and index2) that I want to represent according to two information info1 (a number) and info2 (a letter) My issue is the boxplot I have are already grouped together, and I don't understand how manage the last dimension?</p> <p>...
<python><seaborn><boxplot><group>
2024-11-20 13:48:11
1
5,207
ymmx
79,207,357
16,895,246
Tkinter keyboard based time input
<p>I'm looking for a way to input time to tkinter but all of the examples I can find are either unnecessarily fancy <a href="https://pypi.org/project/tkTimePicker/" rel="nofollow noreferrer">https://pypi.org/project/tkTimePicker/</a> or just slow to input <a href="https://pypi.org/project/tkTimePicker/" rel="nofollow n...
<python><tkinter><time>
2024-11-20 13:12:57
0
1,441
Pioneer_11
79,207,351
4,841,654
Error 422: Unprocessable Entity errors with Openstack python-swiftclient
<p>I am writing a Python script using <code>python-swiftclient</code> and <code>zipfile</code> to zip and upload files to the Swift API endpoint of an Openstack Object Store. I store the zipped data in memory as an <code>io.BytesIO</code> object.</p> <p>Code snippet:</p> <pre class="lang-py prettyprint-override"><code>...
<python><mime-types><python-zipfile><object-storage><openstack-swift>
2024-11-20 13:11:44
1
501
Dave
79,207,328
5,350,089
Changing Serial Port Parity at Run time Python Serial
<p>Hi i am working with python serial project i want to change the serial port parity value at runtime it is not working properly especially in odd parity mode it is not sending correct data</p> <pre><code>import serial import time ser = serial.Serial( port='COM3', baudrate=9600, parity=serial.PARITY_NONE,...
<python><serial-port><pyserial><parity>
2024-11-20 13:05:50
0
445
Sathish
79,207,322
2,447,427
SMAC3 conda dependency
<p>Are there any caveats to take into consideration before installing <a href="https://www.automl.org/hpo-overview/hpo-tools/smac/" rel="nofollow noreferrer">AutoML</a>'s <a href="https://github.com/automl/SMAC3" rel="nofollow noreferrer">SMAC3</a> using <code>pip</code> inside a regular <code>venv</code> rather than w...
<python><pip><anaconda><conda><pypi>
2024-11-20 13:03:48
1
343
bbudescu
79,207,126
7,179,546
How to launch 2 requests in python in parallel
<p>I want to execute 2 functions in Python that execute requests under the hood. I don't mind to wait until the two have finished, but they should be executed in parallel.</p> <p>I tried to use the <code>concurrent.futures</code> library, but that requires me to use an async and so on until the function on top of all, ...
<python><multithreading><parallel-processing>
2024-11-20 12:04:18
1
737
Carabes
79,206,947
8,792,159
How to apply a function to each 2D slice of a 4D Numpy array in parallel with Dask without running out of RAM?
<p>I want to apply a function to each 2D slice of a 4D Numpy array using Dask. The output should be a 2D matrix (the function applied to each 2D slice returns a single value). I would like to do this in parallel. Problem: I'm not sure I understand correctly how Dask implements the parallel calculation. Currently, I am ...
<python><arrays><numpy><parallel-processing><dask>
2024-11-20 11:14:24
0
1,317
Johannes Wiesner
79,206,753
4,042,267
How to type hint a factory fixture for a pydantic model for tests
<p>Let's assume I have a <code>pydantic</code> model, such as this <code>Widget</code>:</p> <p><code>models.py</code></p> <pre class="lang-py prettyprint-override"><code>from pydantic import BaseModel class Widget(BaseModel): name: str value: float </code></pre> <p>When writing tests (using <code>pytest</code...
<python><pytest><python-typing><pydantic>
2024-11-20 10:17:20
1
7,246
Graipher
79,206,734
9,547,278
Unable to pass self.instance_variable as default into a class method
<p>I have a class and method that I am trying to pass a <code>self.instance_variable</code> as default but am unable to. Let me illustrate:</p> <pre><code>from openai import OpenAI class Example_class: def __init__(self) -&gt; None: self.client = OpenAI(api_key='xyz') self.client2 = OpenAI(api_key=...
<python><class><methods><instance-variables>
2024-11-20 10:12:56
1
474
Legion
79,206,699
3,161,120
pylint --generated-members doesn't ignore class protobuf class
<p>Would anyone of you know how to configure <code>pylint</code> to error for the following module?</p> <p>Option doesn't work for <code>'vox_api.api_pb2.*'</code> and <code>'vox_api.*'</code>, but works for <code>'Response'</code>:</p> <p>Results:</p> <pre><code>$ pylint --generated-members='vox_api.api_pb2.*' src/pyj...
<python><protocol-buffers><pylint><pylintrc>
2024-11-20 10:02:52
0
1,830
gbajson
79,206,689
5,305,512
Azure AI Studio - Script runs indefinitely with no errors or outputs
<p>I am following <a href="https://learn.microsoft.com/en-us/azure/ai-studio/tutorials/copilot-sdk-build-rag" rel="nofollow noreferrer">this</a> tutorial to get started with Azure AI Studio. The <code>create_search_index.py</code> script ran successfully and created an index. But the <code>get_product_documents.py</cod...
<python><azure><azure-ai><rag>
2024-11-20 10:00:56
1
3,764
Kristada673
79,206,673
6,703,592
dataframe resample get the start time
<pre><code>freq = '1m' for date, df in df_trade.resample(freq): print(date) start = date - datetime.timedelta(freq) </code></pre> <p>we know that here <code>date</code> is the end time of resample under the given <code>freq</code> e.g. for the interval <code>('2021-03-01', '2021-03-31')</code>, <code>date</cod...
<python><dataframe><resample>
2024-11-20 09:57:15
0
1,136
user6703592
79,206,663
8,040,369
Adding values from 2 cells in the previous row in to current row in dataframe
<p>I have a dataframe like below</p> <pre><code> Name Value ==================== A 2400 B -400 C 400 D 600 </code></pre> <p>And i need the df to be in the below format</p> <pre><code> Name Lower_Value Upper_Value ====================================== A 0 ...
<python><python-3.x><pandas><dataframe>
2024-11-20 09:55:42
2
787
SM079
79,206,398
3,252,535
How to get the result of the objective function while using a slack variable?
<p>I have a simple Python code using Gurobi. I have added a slack variable to force model feasibility. I need to know how to get the real minimum value in my objective function.</p> <pre><code>import gurobipy as gp from gurobipy import GRB # Create the model model = gp.Model(&quot;quadratic_optimization_with_slack&quo...
<python><gurobi>
2024-11-20 08:40:45
2
899
ironzionlion
79,206,384
1,956,558
Beautiful soup duplicating link text
<p>I have a function that is meant to extract html to render it in pdf in another function</p> <pre><code>def setLinks(self, value): if isinstance(value, str) and ('&lt;' in value and '&gt;' in value): soup = BeautifulSoup(value, 'html.parser') paragraphs = [] links = [] # Process t...
<python><beautifulsoup>
2024-11-20 08:37:54
2
19,871
Juliatzin
79,206,293
6,930,340
Forcing numpy arrays generated by Python hypothesis to contain all allowed elements
<p>I generate test data using Python's <code>hypothesis</code> library.</p> <p>For example, I am generating a numpy array that may contain <code>0</code> and <code>1</code> like this:</p> <pre><code>arr = hypothesis.extra.numpy.arrays(dtype=np.int8, shape=10, elements=st.integers(0, 1)) </code></pre> <p>How can I make ...
<python><python-hypothesis>
2024-11-20 07:59:54
1
5,167
Andi
79,205,922
1,084,174
ModuleNotFoundError: No module named 'trl'
<p>I have installed trl using pip.</p> <pre><code>!pip show trl </code></pre> <p>and its showing packages info properly,</p> <pre><code>!pip show trl Name: trl Version: 0.7.10 Summary: Train transformer language models with reinforcement learning. Home-page: https://github.com/huggingface/trl Author: Leandro von Werra...
<python><jupyter-notebook><pip><package>
2024-11-20 05:34:24
1
40,671
Sazzad Hissain Khan
79,205,913
8,040,369
Spliting a JSON list obj into multiple based on values in python
<p>I have JSON object something like below,</p> <pre><code>Data = [ { 'Name': 'A1', 'Value': 10, 'Type': 'AAA' }, { 'Name': 'A1', 'Value': 20, 'Type': 'AAA' }, { 'Name': 'B1', 'Value': 10, 'Type': 'AAA' }, { 'N...
<python><json><python-3.x>
2024-11-20 05:28:57
3
787
SM079
79,205,712
9,632,470
Trouble Sending Text with smtplib
<p>I wrote the following code to send a text message from my python script. The first time I ran it I successfully received a text message to my phone, but it was blank (no message). I re-ran the code 3 times and now get no message, however I noticed the messages are in the outbox of the email (though the recipient pho...
<python><smtplib>
2024-11-20 03:35:54
0
441
Prince M
79,205,476
15,587,184
Python request taking too long to get PDF from website
<p>I'm trying to create a single, lightweight Python script to open a website hosting a guaranteed PDF file, download it, and extract its text.</p> <p>I’ve reviewed many posts here and across the internet and settled on a combination of the requests and PyPDF2 libraries. While PyPDF2 efficiently extracts text once the ...
<python><pdf><python-requests><request>
2024-11-20 00:35:34
2
809
R_Student
79,205,378
1,613,983
How do I plot a line over a bar chart with pandas/date index?
<p>I've got a dataframe I'd like to represent as a stacked bar chart, and a series that I'd like to represent as a line (but with a different scale). I'd like to draw these as a line chart (for the series) drawn on top of a bar chart (for the dataframe) with a shared x-axis (being the time indices).</p> <p>Here's a toy...
<python><pandas>
2024-11-19 23:40:04
1
23,470
quant
79,205,151
4,858,640
How to install python packages generate by CMake using setup tools?
<p>I am working with a C++ project in which the CMake build process generates a directory structure of Python packages (i.e. Python source files, not shared object) in the chosen build directory under <code>python_packages/my_package</code>. I cannot change this approach. I have written a <code>setup.py</code> script t...
<python><python-3.x><cmake><setuptools>
2024-11-19 21:47:27
0
3,242
Peter
79,205,112
141,650
Fixture `record_property` not found
<p>I'm trying to use the <code>record_property</code> fixture (<a href="https://docs.pytest.org/en/stable/reference/reference.html#record-property" rel="nofollow noreferrer">https://docs.pytest.org/en/stable/reference/reference.html#record-property</a>). My build file looks like this:</p> <pre><code>load(&quot;@pip//:r...
<python><pytest>
2024-11-19 21:28:16
1
5,734
Stephen Gross
79,204,975
4,858,640
Python version discrepancies when running setup.py in pyenv
<p>I'm trying to write a <code>setup.py</code> script for a Python project. I want to install this project into a pyenv virtualenv. So using pyenv 2.4.18 I have tried the following:</p> <pre><code>pyenv virtualenv 3.12.7 my_env pyenv local my_env pip install --upgrade pip pip install numpy python setup.py install </cod...
<python><python-3.x><setuptools><pyenv>
2024-11-19 20:32:20
0
3,242
Peter
79,204,897
9,006,687
Install gymnasium with atari games using conda
<p>Sorry if this is a silly question, but I can't figure this one out.</p> <p>I am trying to install gymnasium with Atari games using conda. Here is my setup.py:</p> <pre><code>from setuptools import find_packages from setuptools import setup setup( name=&quot;benchmarks&quot;, version=&quot;0.0.0&quot;, ....
<python><conda><openai-gym>
2024-11-19 20:03:27
0
461
Theophile Champion
79,204,757
498,584
Cuncurrency, mutex, semaphores on django and a cron job
<p>I want to create a critical section in django provide controlled section. One of this is in one of the django channels consumers handling the websocket connections and the other is in a cron process implemented with cron tab, not celery.</p> <p>I would like these both critical sections to have a lock. How would I im...
<python><django><mutex><semaphore><critical-section>
2024-11-19 19:09:26
0
1,723
Evren Bingøl
79,204,671
3,323,455
pymssql can connect to 'master' but can't connect to another database after
<p>I do</p> <p><code>pymssql.connect(server=self.host, user=self.username, password=self.password, port=self.port, database=database_name)</code></p> <p>then</p> <p><code>with conn.cursor() as cursor:</code></p> <p><code>cursor.execute(sql, args)</code></p> <pre><code>cursor.fetchall() </code></pre> <p>then</p> <pre><c...
<python><sql-server><pymssql>
2024-11-19 18:35:52
0
328
pulse
79,204,623
759,880
Correct way to parallelize request processing in Flask
<p>I have a Flask service that receives <code>GET</code> requests, and I want to scale the QPS on that endpoint (on a single machine/container). Should I use a python <code>ThreadPoolExecutor</code> or <code>ProcessPoolExecutor</code>, or something else? The <code>GET</code> request just retrieves small pieces of data ...
<python><multithreading><flask>
2024-11-19 18:19:35
1
4,483
ToBeOrNotToBe
79,204,622
19,760,971
How to create DataFrame that is the minimal values based on 2 other DataFrame's in pandas (python)?
<p>Let's say I have <code>DataFrame</code>s <code>df1</code> and <code>df2</code>:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; df1 = pd.DataFrame({'A': [0, 2, 4], 'B': [2, 17, 7], 'C': [4, 9, 11]}) &gt;&gt;&gt; df1 A B C 0 0 2 4 1 2 17 9 2 4 7 11 &gt;&gt;&gt; df2 = pd.DataFrame(...
<python><pandas><dataframe><min>
2024-11-19 18:19:19
1
867
k1r1t0
79,204,607
6,686,503
Coverage: How to gracefully stop a Django development server that runs on a Github Action Instance
<p>I am testing some API endpoints of my Django app by running Playwright separately on a Ubuntu machine on my Github Action instance. Since I also want to get the coverage of the tests, I am starting my server this way:</p> <pre class="lang-yaml prettyprint-override"><code> - name: run backend server run: poe...
<python><django><github-actions><code-coverage>
2024-11-19 18:13:24
0
692
Gers
79,204,599
599,402
Python typehinting packages without creating circular imports
<p>I've been scouring the internet trying to find a solution to this, and I have yet to find an answer despite this seeming like something that should be a very common use case:</p> <p><strong>How can I safely type check methods or arguments in Python across different files or packages without creating a circular depen...
<python><python-typing><pyright>
2024-11-19 18:11:25
3
8,441
Ephraim
79,204,500
4,852,094
mypy with pydantic field_validator
<p>With pydantic, is there a way for mypy to be hinted so it doesn't raise an error in this scenario, where there's a field_validator modifying the type?</p> <pre><code>class MyModel(BaseModel): x: int @field_validator(&quot;x&quot;, mode=&quot;before&quot;) @classmethod def to_int(cls, v: str) -&gt; i...
<python><pydantic>
2024-11-19 17:41:20
2
3,507
Rob
79,204,427
12,057,138
SDV generates incorrect values for hash-like fields when creating synthetic data from a CSV file"
<p>I am using SDV to generate mock data by extracting real data and metadata from an existing CSV file and then saving the mock data to a new CSV file.</p> <p>Here is my code:</p> <pre><code>import pandas as pd from sdv.metadata import Metadata from sdv.single_table import GaussianCopulaSynthesizer data = pd.read_csv(...
<python><data-generation><synthetic><sdv>
2024-11-19 17:12:26
0
688
PloniStacker
79,204,365
297,274
Polynomial roots - showing imaginary part
<p>Polynomial roots are determined using following code. Roots are displayed with imaginary numbers, but it is actually whole numbers. The 5's should be with out any imaginary value</p> <p>[5.+1.27882372e-07j 5.-1.27882372e-07j 2.+0.00000000e+00j]</p> <pre><code>import numpy as np poly=[1,-10,25] # (x-5)**2 p1 = np.po...
<python><numpy><polynomials>
2024-11-19 16:52:41
1
782
cobp
79,204,309
207,717
How to decompress raw PKZIP data without zip header in python?
<p>I want to to decompress raw data from a file in an exotic format, but I know that the compression method is the same that is used in a ZIP file (PKZIP).</p> <p>In the file the PK\03\04 signature is missing. After that the data more or less fits the PKZIP header specs:</p> <p><a href="https://docs.fileformat.com/comp...
<python><zip><compression><gzip><pkzip>
2024-11-19 16:37:09
1
6,717
PanJanek
79,204,288
1,100,652
Handle DNS timeout with call to blob_client.upload_blob
<p>While using the Azure storage SDK in Python, I have been unable to override what appears to be a default 90-second timeout to catch a DNS exception occurring within a call to <code>blob_client.upload_blob()</code>. I am looking for a way to override this with a shorter time interval (i.e. 5 seconds).</p> <p>The foll...
<python><azure><http><azure-blob-storage>
2024-11-19 16:31:16
1
415
George
79,204,203
821,995
How to detect MS Visual C++ runtime version mismatches from third-party libraries when importing Python modules?
<p>I've run into a weird case of incompatibility between:</p> <ul> <li>A Python module (<code>PySide6</code>) that bundles its own version of the Visual C++ runtime</li> <li>Our own compiled modules that are compiled against the latest Visual C++ runtime</li> </ul> <p>At some point we upgraded Visual C++, and the secon...
<python><c++><visual-c++><pyside6><visual-c++-runtime>
2024-11-19 16:06:43
1
7,455
F.X.
79,204,195
3,240,659
Tensorboard histogram display of layer weights was working in tensorflow 2.12 but is broken in 2.16. Is this due to the Keras version update (2 to 3)?
<p>The below code (a minimal 'toy' example using data generators for both training and validation data) works fine in 2.12 and produces the desired bias and kernel weight histograms in tensorboard for both hidden layers as well as the output layer. For 2.16 and later I just get the output layer bias and kernel displaye...
<python><tensorflow><keras>
2024-11-19 16:04:52
0
358
nickcrabtree
79,204,030
3,741,284
Determine most accurate best-fit algorithm for scattered points
<p>I'm currently working with the <code>skspatial</code> package in Python3. I currently have two functions:</p> <ol> <li><code>skspatial.objects.Cylinder.best_fit</code> to try to best fit the points into a cylinder</li> <li>A function that returns the bounding box of the scattered points. This function returns a cust...
<python><python-3.x><shapes><data-fitting><best-fit>
2024-11-19 15:25:37
1
947
CRoemheld
79,203,777
3,104,974
How to identify and manage a background daemon process beyond parent process runtime in python
<p>I want to run a python script <code>B</code> in the background every 8 hours on a Windows machine that usually runs 24/7. Also, I have another script <code>A</code> that is manually executed and uses data that is provided by the background script (which queries a large database and extracts relevant data so that it ...
<python><multiprocessing><python-multiprocessing><background-process>
2024-11-19 14:16:44
2
6,315
ascripter
79,203,234
6,189,352
Handling multiple IO blocking services using asyncio
<p>This doesn't necessarily have to be a question about Python, it could rather be about asynchronous programming in general. To keep it short, I have an undefined number of objects where each executes its operation by running a function that essentially acts as an infinite loop (often contains while True). These funct...
<python><concurrency><python-asyncio>
2024-11-19 11:25:06
2
579
Serjuice
79,203,163
4,999,991
Python Launcher (py.exe) points to non-existent Python installation in AppData - how to fix?
<p>When I run <code>py --version</code> on Windows, I get this error:</p> <pre class="lang-none prettyprint-override"><code>Unable to create process using '%LOCALAPPDATA%\Programs\Python\Python312\python.exe --version': The system cannot find the file specified. </code></pre> <p>However, I have Python properly installe...
<python><windows><registry>
2024-11-19 11:06:10
0
14,347
Foad S. Farimani
79,203,144
9,476,917
Python Seaborn - set_xlim - axis labels do not appear on axis
<p>I have following function to produce seaborn bar charts.</p> <pre><code>def create_bar_chart(data, numeric_col, category_col, group_col=None, x_min=0, x_max=100, fig_width_cm=12, ...
<python><matplotlib><seaborn><bar-chart>
2024-11-19 11:01:25
0
755
Maeaex1
79,203,119
7,760,998
(NoSuchVersion) when calling the GetObject operation: The specified version does not exist
<p>I am trying to download all the versions of a file in Amazon S3 using <code>boto3</code> (version 1.34.113) but it keeps giving the error <code>botocore.exceptions.ClientError: An error occurred (NoSuchVersion) when calling the GetObject operation: The specified version does not exist.</code></p> <p>My Python code i...
<python><amazon-web-services><amazon-s3><boto3>
2024-11-19 10:55:28
1
1,748
Samkit Jain
79,202,529
2,155,362
How to location image in web page?
<p>I want cut image from web page by python + Selenium, and remote debug by mstsc. Below is my code fragment:</p> <pre><code> image_data = self.driver.get_screenshot_as_png() screenshot = Image.open(BytesIO(image_data)) screenshot.save('screenshot.png') element = self.driver.find_element(By.CSS_SELECTOR,...
<python><selenium-webdriver>
2024-11-19 08:10:31
0
1,713
user2155362
79,202,327
7,282,437
Importing from another directory located in parent directory in Python
<p>Suppose we have a project structure like:</p> <pre><code>project/ public_app/ __init__.py dir/ __init__.py config.py subdir/ __init__.py functions.py utils.py my_app/ main.py </code></pre> <p>In <code>...
<python><directory><python-import>
2024-11-19 06:42:59
4
389
Adam
79,202,065
16,405,935
How to sum data by input date, month and previous month
<p>I'm trying to sum up data of selected date, month of selected date and previous month of selected date but don't know how to do. Below is my sample data and my expected Output:</p> <p>Sample data:</p> <pre><code>import pandas as pd import numpy as np df = pd.read_excel('https://github.com/hoatranobita/hoatranobita/r...
<python><pandas>
2024-11-19 04:13:19
1
1,793
hoa tran
79,201,971
2,307,441
swifter module not showing progress bar in python
<p>I have a pandas df with 1M records. I Need to apply a function to get the new column. To do so, I use <code>swift</code> to run the apply in parallel.</p> <p>swift module is working fine but as mentioned <a href="https://github.com/jmcarpenter2/swifter/issues/176" rel="nofollow noreferrer">here</a>, I don't see the ...
<python><pandas><apply><swifter>
2024-11-19 03:01:15
0
1,075
Roshan
79,201,839
403,875
Hello World for jaxtyping?
<p>I can't find any instructions or tutorials for getting started with jaxtyping. I tried the simplest possible program and it fails to parse. I'm on Python 3.11. I don't see anything on GitHub jaxtyping project about an upper bound (lower bound is Python 3.9) and it looks like it's actively maintained (last commit was...
<python><pytorch><python-typing><jax>
2024-11-19 01:14:35
2
5,604
dspyz
79,201,815
1,082,883
How to search string across multiple columns, and create a new column of flag if string found in any of columns using Polars?
<p>To search over multiple columns, and create a new column of flag if string found, the following code works, but is there any compact way inside <code>with_columns()</code> to achieve the same?</p> <pre class="lang-py prettyprint-override"><code>import polars as pl df = pl.DataFrame({ &quot;col1&quot;: [&quot;he...
<python><dataframe><python-polars>
2024-11-19 01:00:08
1
691
Fred
79,201,789
1,609,514
Why does Pandas rolling method return a series with a different dtype to the original?
<p>Just curious why the Pandas Series <a href="https://pandas.pydata.org/docs/reference/api/pandas.Series.rolling.html" rel="nofollow noreferrer">rolling window method</a> doesn't preserve the data-type of the original series:</p> <pre class="lang-py prettyprint-override"><code>import numpy as np import pandas as pd x...
<python><pandas><types><rolling-computation>
2024-11-19 00:40:14
1
11,755
Bill
79,201,663
13,642,249
Split columns containing lists from CSV into separate CSV files with pandas
<p>I have CSV files with multiple columns of data retrieved from APIs, where each cell may contain either a single value or a list/array. The size of these lists is consistent across each column (e.g., a column named <code>ALPHANUMS</code> having a row containing a list like <code>&quot;['A', 'B', '4']&quot;</code> has...
<python><pandas>
2024-11-18 23:07:59
5
1,422
kyrlon
79,201,516
393,194
How to mock a python-jenkins call in FastAPI
<p>I have a simple FastAPI application that uses <a href="https://python-jenkins.readthedocs.io/en/latest/" rel="nofollow noreferrer">python-jenkins</a> to make custom calls to our Jenkins instance.</p> <p>Here are a couple of examples:</p> <pre class="lang-py prettyprint-override"><code>@app.get(&quot;/jenkins_data&qu...
<python><pytest><fastapi>
2024-11-18 21:42:00
0
33,169
Mike Driscoll
79,201,278
10,853,071
Python Logging : name 'log' is not defined
<p>I am using python logging to write debug information to a file and print it to my screen :</p> <pre><code>logger=logging.getLogger() logger.setLevel(logging.INFO) file_handler = logging.FileHandler(&quot;std.log&quot;, mode='w') file_handler.setFormatter(logging.Formatter('%(asctime)s %(message)s')) logger.addHand...
<python><python-logging>
2024-11-18 20:00:56
2
457
FábioRB
79,201,114
46,058
flake8 warning for type hints using collections.namedtuple for pandas `itertuples()`
<p>I want to provide type hints for the IDE tab completion (and IDE type linter) for the loop variable over Pandas' DataFrame itertuples(). I could do this with <code>typing.NamedTuple</code>, but I though that <code>collections.namedtuple</code> would be enough:</p> <pre class="lang-py prettyprint-override"><code>row...
<python><pandas><python-typing><flake8>
2024-11-18 18:58:55
1
327,106
Jakub Narębski
79,201,012
7,271,231
IF element IN list in robot framework
<p>I am trying to see if the element is present in the list using Robot Framework. This is my test:</p> <pre><code>IF Calgary IN ${list} do something END </code></pre> <p>But I am getting this error <code>No keyword with name 'IN' found</code></p>
<python><robotframework><robotframework-browser>
2024-11-18 18:21:29
2
648
Urvish rana
79,200,982
3,840,530
How to make the ttk treeview not show extra empty columns?
<p>I am building an app with tkinter and running into some annoying issues.</p> <p>When I load my data into the ttk treeview, I see that there are always some additional columns on the right side of my treeview which are empty. I realized for a bigger data set there are many more columns which are empty (actual data is...
<python><pandas><tkinter><treeview><ttk>
2024-11-18 18:13:09
2
302
user3840530
79,200,874
13,968,392
Column assignment with .alias() or =
<p>What is the preferred way to assign/add a new column to a polars dataframe in <code>.select()</code> or <code>.with_columns()</code>?<br /> Are there any differences between the below column assignments using <code>.alias()</code> or the <code>=</code> sign?</p> <pre><code>import polars as pl df = pl.DataFrame({&qu...
<python><dataframe><python-polars>
2024-11-18 17:34:50
2
2,117
mouwsy
79,200,849
10,165,118
SQLAlchemy - Tables are not created by Database class
<p>I am struggling to automatically create tables using SQLAlchemy for Postgresql database.</p> <p>In my module I defined a <code>base.py</code>:</p> <pre class="lang-py prettyprint-override"><code>from sqlalchemy import MetaData from sqlalchemy.orm import DeclarativeBase, Session class Base(DeclarativeBase): # E...
<python><postgresql><sqlalchemy><orm>
2024-11-18 17:24:39
1
472
P. Leibner
79,200,847
337,149
Proper way to extract XML elements from a namespace
<p>In a Python script I make a call to a SOAP service which returns an XML reply where the elements have a namespace prefix, let's say</p> <pre><code>&lt;ns0:foo xmlns:ns0=&quot;SOME-URI&quot;&gt; &lt;ns0:bar&gt;abc&lt;/ns0:bar&gt; &lt;/ns0:foo&gt; </code></pre> <p>I can extract the content of <em>ns0:bar</em> with t...
<python><xml><xml-parsing>
2024-11-18 17:23:55
2
11,423
August Karlstrom
79,200,661
11,457,006
Reducing cold start in a python AWS Lambda Function
<p>I have an AWS lambda function written in python that needs a way of manipulating data stored in tables. My solution is to use pandas to read the tables in as parquet files. While this works, the cold start of this lambda function goes from ~400ms to 2000ms as soon as I add a pandas layer (even without any computat...
<python><pandas><amazon-web-services><aws-lambda>
2024-11-18 16:15:30
1
3,875
Jesse McMullen-Crummey
79,200,411
4,124,981
legacy elastic beanstalk application failing to run ebextension with CERTIFICATE_VERIFY_FAILED
<p>We have an old legacy app that runs on elastic beanstalk. This week the app started failing to deploy, with the following error:</p> <p><code>Failed to retrieve https://github.com/papertrail/remote_syslog2/releases/download/v0.18/remote_syslog_linux_amd64.tar.gz: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify f...
<python><amazon-web-services><amazon-elastic-beanstalk><papertrail-app>
2024-11-18 14:55:21
0
3,024
Matt Bryson
79,200,387
6,498,245
How to enable parallel execution of ABAP in PyRFC?
<p>I am migrating a project to PyRFC, using a server configuration.</p> <p>My program is registering a function that has to be called. The incoming data is splitted across 3 DTP, hence my function will be called 3 times.</p> <p>When we set the parallel execution in SAP to 1, everything is working fine and I am receivin...
<python><abap><rfc><pyrfc>
2024-11-18 14:48:58
1
356
Double Sept
79,200,104
1,882,828
Node.js socket io server disconnects python socket.io client after 30 seconds
<p>Node.js socket io server disconnects python socket.io client after 30 seconds.. server sends this:</p> <blockquote> <p>0{&quot;sid&quot;:&quot;6afJCYzsh1Yz3bh3AAAA&quot;,&quot;upgrades&quot;:[],&quot;pingInterval&quot;:25000,&quot;pingTimeout&quot;:5000}</p> </blockquote> <p>am not able to find any other references ...
<python><node.js><socket.io><timeout>
2024-11-18 13:26:04
0
331
Sathish Kumar
79,200,058
1,129,666
How to make urllib use my own network code for the actual http GET/PUT/... operations?
<p>I need to configure urllib in Anaconda Python 3.6 to use my own python code to do the actual GET, PUT, ... operations. The solution will be native python code and wrap the curl cli to do the acutal operation.</p> <p>I'm working in a highly restrictive environment where I cannot install any software on my workstation...
<python><urllib>
2024-11-18 13:14:22
0
324
briconaut
79,199,863
25,413,271
Reorder Numpy array by given index list
<p>I have an array of indexes:</p> <pre class="lang-py prettyprint-override"><code>test_idxs = np.array([4, 2, 7, 5]) </code></pre> <p>I also have an array of values (which is longer):</p> <pre class="lang-py prettyprint-override"><code>test_vals = np.array([13, 19, 31, 6, 21, 45, 98, 131, 11]) </code></pre> <p>So I wa...
<python><numpy>
2024-11-18 12:11:21
1
439
IzaeDA
79,199,776
6,542,623
LLDB Python scripting - how to add module or load symbol file at particular address?
<p>In LLDB you can do the following during a debugging session to add missing symbols at particular addresses:</p> <pre><code>target modules load --file &lt;symbol file&gt; .text 0x&lt;address&gt; </code></pre> <p>How can you do that in with the LLDB Python scripting module? I searched through the API but I couldn't fi...
<python><lldb>
2024-11-18 11:35:01
2
354
Kotosif
79,199,599
13,118,291
Tensorflow GPU crashing after first epoch
<p>I am training a neural network model and when running the code :</p> <pre><code>history = model.fit( X_train, y_train_encoded, epochs=20, batch_size=32, validation_data=(X_val, y_val_encoded), ) </code></pre> <p>The first epoch finishes successfully (in around 11 minutes), and then I get this error :...
<python><tensorflow><deep-learning><jupyter-notebook>
2024-11-18 10:40:03
0
465
Elyes Lounissi
79,199,376
4,444,546
Hypothesis cannot build from type when type is int subclass
<p>So my problem is the following</p> <pre class="lang-py prettyprint-override"><code>from typing import ClassVar, TypeVar from hypothesis import strategies as st T = TypeVar(&quot;T&quot;, bound=&quot;FixedUint&quot;) class FixedUint(int): MAX_VALUE: ClassVar[&quot;FixedUint&quot;] def __init__(self: T, v...
<python><python-hypothesis>
2024-11-18 09:34:50
1
5,394
ClementWalter