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,567,558
234,146
Create a numpy table in C++
<p>I have a C++ DLL that utilizes numpy tables created in Python. I can add and retrieve data in C++ and Python from the table easily.</p> <p>The table currently is created in Python using:</p> <pre><code>class MyTable(object): _table_type = np.dtype({'names': ['field1', 'field2'], 'formats':[np.flo...
<python><c++><numpy><pybind11>
2024-06-02 19:54:56
0
1,358
Max Yaffe
78,567,412
7,090,501
Can't close out of pop up box with selenium
<p>I'm trying to download a pdf at the following link:</p> <p><a href="https://www.cms.gov/medicare-coverage-database/view/lcd.aspx?lcdid=39763&amp;ver=8" rel="nofollow noreferrer">https://www.cms.gov/medicare-coverage-database/view/lcd.aspx?lcdid=39763&amp;ver=8</a></p> <p>Most documents at this website have the a pop...
<python><selenium-webdriver>
2024-06-02 18:46:17
3
333
Marshall K
78,567,404
520,556
Particular reshape of pandas dataframe
<p>How can I create a new dataframe if the input looks like this:</p> <pre><code>inputTable = pd.DataFrame({ 'A' : [1, 2, 3, 4, 5], 'B' : [2, 3, 4, 5, 6], 'C' : [3, 4, 5, 6, 7] }) </code></pre> <p>and the resulting table should look like this:</p> <pre><code>resultingTable = pd.DataFrame({ 'Category' : ...
<python><pandas>
2024-06-02 18:43:40
2
1,598
striatum
78,567,022
7,758,213
Running Powershell commands using Paramiko in python in a remote Windows 7
<p>I'm using paramiko in Python to send commands (and retrieve data) from another server. When I send a <strong>Powershell</strong> command to Windows 10 server it all works OK.</p> <p>But when sending this to Windows 7 it stuck indefinitely.</p> <p>sending cmd command works OK in both OS types</p> <p>my example:</p> <...
<python><powershell><powershell-2.0><paramiko>
2024-06-02 16:15:22
0
968
Izik
78,566,922
252,228
imported module not found in class in Pyodide
<p>I am trying to use pyodide with lxml and urllib3, for some reasons I don't understand, when I try to use <code>urllib3</code> in a class supposed to be a Resolver for lxml etree I get an error <code>NameError: name 'urllib3' is not defined</code>.</p> <p>Example code is online at <a href="https://martin-honnen.githu...
<python><lxml><urllib3><pyodide>
2024-06-02 15:41:10
1
168,793
Martin Honnen
78,566,724
10,855,529
Selecting a particular set of strings from a list in polars
<pre><code>df = pl.DataFrame({'list_column': [['a.xml', 'b.xml', 'c', 'd'], ['e.xml', 'f.xml', 'g', 'h']]}) def func(x): return [y for y in x if '.xml' in y] df.with_columns(pl.col('list_column').map_elements(func, return_dtype=pl.List(pl.String))) </code></pre> <p>Is there a way to achieve the same without using...
<python><python-polars>
2024-06-02 14:28:39
1
3,833
apostofes
78,566,503
2,749,397
Offsetting the x tick labels to aim at the corresponding x tick
<p><a href="https://i.sstatic.net/peo4Cdfg.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/peo4Cdfg.png" alt="enter image description here" /></a></p> <p>As you can see, the arrows are not <em>exactly</em> aimed at the corresponding <em>x</em>-tick, is it possible to offset the labels so that, for any re...
<python><matplotlib>
2024-06-02 13:05:18
0
25,436
gboffi
78,566,374
2,662,728
'HtmlToDocx' object has no attribute 'run'
<p>The parser is giving &quot;HtmlToDocx object has no attribute run&quot;. When I do a search, I look at the stackoverflow results first because the answers are rated. I did not find an answer for this question on stackoverflow.</p>
<python><html><html-to-docx>
2024-06-02 12:18:47
2
535
Anthony Petrillo
78,566,281
774,575
Select with DateTime index, ignoring day attribute
<p>Trying to select rows for which the index label is a date in January 2016:</p> <pre><code>import numpy as np import pandas as pd index = pd.date_range('2016-01-28', freq='d', periods=6) columns=list('A') values = np.random.randint(1,10, size=(len(index), len(columns))) df = pd.DataFrame(values, index=index, columns...
<python><pandas><datetime>
2024-06-02 11:39:53
1
7,768
mins
78,566,093
5,798,365
Assignment works with no __setitem__ defined
<p>I'm writing my own matrix class that works with Python <code>Fraction</code> instead of numbers.</p> <p>I now need to overload <code>[]</code>, so I could read and assign values to specific cells in the matrix without directly addressing the base list from the outer scope.</p> <p>So here's the code:</p> <pre><code>f...
<python><class><methods><operator-overloading>
2024-06-02 10:26:06
1
861
alekscooper
78,565,961
4,002,204
Error in sklearn’s cross_val_score with ‘f1’ scoring for categorical target in LightGBM
<p>My code receives a dataset and runs a classification on it with <code>lightgbm</code>. The problem is when I try to do fine-tuning with <code>sklearn</code>'s <code>cross_val_score</code>, the target column contains categorical values, not numerical ones. It works when I set the <code>cross_val_score</code> to work ...
<python><scikit-learn><cross-validation><multiclass-classification><lightgbm>
2024-06-02 09:16:47
0
1,106
Zag Gol
78,565,860
694,716
How to run two chain that first output is second input using langchain python?
<p>I have two chains</p> <pre><code>llm = OpenAI() code_prompt = PromptTemplate( input_variables=[&quot;task&quot;, &quot;language&quot;], template=&quot;Write a very short {language} function that will {task}.&quot; ) test_prompt = PromptTemplate( input_variables=[&quot;language&quot;, &quot;code&quot;], ...
<python><langchain>
2024-06-02 08:30:29
1
6,935
barteloma
78,565,773
7,261,317
Django 4.2: Apply sorting Child Table key based on foreignkey
<p>please see below model definition</p> <pre><code>class Product(models.Model): name = models.CharField(max_length=200, blank=True, null=True) prduct_type = models.CharField(max_length=30, blank=True, null=True) class ProductRateInfo(models.Model): product= models.ForeignKey(Product, on_delete=mod...
<python><django><django-models>
2024-06-02 07:52:06
1
3,483
Robert
78,565,772
163,768
2d numpy indexing by another array
<p>So, I have a 2d array</p> <pre><code>a.shape (1050, 21) </code></pre> <p>And a 1d array</p> <pre><code>b.shape (1050,) </code></pre> <p>I'm looking for a way (other than iterating) to produce 1d array (let's call it &quot;c&quot;) from &quot;a&quot; so that c[x] = a[x, b[x]]</p>
<python><numpy><numpy-ndarray>
2024-06-02 07:51:48
1
1,669
Demiurg
78,565,768
16,869,946
Pandas groupby transform minimum greater than 0
<p>I have a Pandas dataframe that looks like</p> <pre><code>Race_ID Date Student_ID Rank 1 1/1/2023 1 3 1 1/1/2023 2 8 1 1/1/2023 3 0 1 1/1/2023 4 4 2 11/9/2022 ...
<python><pandas><dataframe><group-by>
2024-06-02 07:51:06
1
592
Ishigami
78,565,758
2,756,466
Connect Chainlit to existing ChromaDb
<p>I am trying to create a RAG application using chainlit.</p> <p>This is the code, I got from an existing tutorial, which is working fine. Only problem that the user has to choose a pdf file every time. I want that chainlit is connected with a persistent chroma vectordb, which should be created only once for all users...
<python><langchain><py-langchain><chromadb><retrieval-augmented-generation>
2024-06-02 07:43:00
1
7,004
raju
78,565,716
4,030,761
Mismatch between periodogram calculated by SciPy periodogram and AstroPy Lomb Scargle periodogram at low frequencies
<p>I am trying to compute the periodogram of my data using both SciPy's periodogram and AstroPy <a href="https://docs.astropy.org/en/stable/timeseries/lombscargle.html" rel="nofollow noreferrer">Lomb-Scargle periodogram</a>—the periodogram matches everywhere except at frequencies near the minimum frequency as shown in ...
<python><signal-processing><fft><spectrum>
2024-06-02 07:18:59
1
355
Prav001
78,565,706
77,222
jinja2 evaluate variables in variable
<p>Using Jinja2 v 3.0. Say I have this context:</p> <pre class="lang-py prettyprint-override"><code>h = template.render(content=c, md=metadata) </code></pre> <p>Suppose my c, which is a string, also has variable in it, like <code>{{ md.title }}</code>, that I do want to be evaluated.</p> <p>How can I do that? is ther...
<python><jinja2>
2024-06-02 07:15:11
1
11,645
Ayman
78,565,533
11,941,142
How to rename a file with Python without overwriting an existing file?
<p>I'd like to rename a file using Python on Linux, but only if it won't overwrite an existing file.</p> <p>I'm looking for the same behaviour as:</p> <pre><code>$ mv --no-clobber old_filename new_filename </code></pre> <p>As best as I can tell, I can't get this behaviour from the obvious candidates:</p> <ul> <li><a hr...
<python>
2024-06-02 05:29:21
1
572
countermeasure
78,565,463
513,554
Is ELISA analysis in Elixir Nx/Schorar possible?
<p>I have read the article <a href="https://medium.com/@tentotheminus9/elisa-analysis-in-python-deb8c6ed91db" rel="nofollow noreferrer">ELISA Analysis in Python</a> on Medium.</p> <p>The above article uses SciPy's <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html" rel="nofollow...
<python><machine-learning><scipy><elixir><elixir-nx>
2024-06-02 04:29:18
2
5,188
Tsutomu
78,565,383
9,468,665
An alternative way to set the value of a variable in pocketpy wihout converting to a string
<p>I am using pocketpy as an embedded interpreter for a C++ program. One thing I need to do is convert a <code>std::vector&lt;float&gt;</code> to a named pocketpy variable. I can do this by evaluating a string version and passing the string to the <code>vm-&gt;exec</code> method but that seems like an inefficient appro...
<python><c++><interop>
2024-06-02 03:15:30
0
474
Bill Sellers
78,565,377
5,043,301
How to customize Form Validation error message for Password Confirmation Field
<p>I am trying to customize Form Validation error message for Password Confirmation Field at User Creation Form.</p> <p>My <strong>forms.py</strong> is like below.</p> <pre><code>from django.contrib.auth.forms import UserCreationForm from django.core.exceptions import ValidationError from .models import User class Cus...
<python><django>
2024-06-02 03:12:30
2
7,102
abu abu
78,565,243
11,618,586
How to return NaN if all values are NaN using the agg() function specifying aggregation output columns
<p>I have a dataframe like so:</p> <pre><code>data = {'Integers': [1, 2, np.nan, 4, 5], 'AllNaN': [np.nan, np.nan, np.nan, np.nan, np.nan]} df = pd.DataFrame(data) </code></pre> <p>I want to return <code>NaN</code> when performing the sum aggregations on the datagrame. There are solutions on here that advises t...
<python><python-3.x><pandas><aggregate-functions>
2024-06-02 01:04:49
1
1,264
thentangler
78,565,203
5,951,505
List of lists (double [[) in Python
<p>This is a really basic thing but after reading the documentation I am still not able to do. I just want to create a list of 9 sublists as follows</p> <pre><code>[[0, 0.05, 0.1, ..., 25],[0, 0.05, 0.1, ..., 25],[0, 0.05, 0.1, ..., 25],[0, 0.05, 0.1, ..., 25],[0, 0.05, 0.1, ..., 25],[0, 0.05, 0.1, ..., 25],[0, 0.05, 0...
<python><list>
2024-06-02 00:24:47
2
381
Hans
78,565,188
11,833,899
Getting data into a manager.dict and sharing it between processes
<p>I'm currently trying to teach myself how to handle live data by streaming Forza telemetry data from my xbox to my PC. I'm having issues storing that data in a manager.dict and sharing it to other processes. I've created a manager.dict called packets, here is the app.py:</p> <pre><code>from connectors.forza_connect i...
<python><multiprocessing><python-multiprocessing>
2024-06-02 00:18:52
1
598
scottapotamus
78,565,064
11,998,382
Avoid doubling every rule for NEWLINE vs DOUBLE_NEWLINE
<p>I want blank new lines to be syntactically significant (optimization for leaf leaning trees <code>[[[a, b], c, d], e, [g], f] == [a b | c d | e [g] f]</code> but with <code>\n\n</code> instead of <code>|</code>). But the only way I can disambiguate is by doubling every definition depending on whether it ended with a...
<python><lark-parser>
2024-06-01 22:35:26
0
3,685
Tom Huntington
78,565,013
907,047
Using llama3 model to parse markdown data
<p>I am trying to use llama3 model to parse markdown data input and to create a markdown table for me. Here is my Python script. The only external library is ollama Python library. I would be greatfull to any suggestions how to do this in the proper and best practices way or at least to point me what exactly documentat...
<python><python-3.x><artificial-intelligence><llama><ollama>
2024-06-01 22:12:01
0
4,231
Georgi Naumov
78,564,958
7,053,357
How to find deprecated APIs
<p>My organization is a startup that has a microservice architecture (Python). There are several services that expose some endpoints. The problem is that, as the startup grew, many things were dynamic, code changed and people came and went... and we are certain for a fact that there's more than a few endpoints that are...
<python><deprecated>
2024-06-01 21:27:42
1
364
felisimo
78,564,920
1,686,628
Function not being mocked unless full path is called
<p>main.py</p> <pre><code>from path.to.mod import run def foo(args: str): run(args) </code></pre> <p>test.py</p> <pre><code>@patch(&quot;path.to.mod.run&quot;) def verify_args(mock): foo(&quot;bar&quot;) mock.assert_called_once_with(&quot;bar&quot;) </code></pre> <p>the above code does not mock <code>run</...
<python><python-3.x><pytest><python-unittest><python-unittest.mock>
2024-06-01 21:08:08
1
12,532
ealeon
78,564,771
13,968,392
Alternative to df.rename(columns=str.replace(" ", "_"))
<p>I noticed that it's possible to use <code>df.rename(columns=str.lower)</code>, but not <code>df.rename(columns=str.replace(&quot; &quot;, &quot;_&quot;))</code>.</p> <ol> <li><p>Is this because it is allowed to use the variable which stores the method (<code>str.lower</code>), but it's not allowed to actually call t...
<python><pandas><replace><rename><method-chaining>
2024-06-01 19:46:55
1
2,117
mouwsy
78,564,655
4,146,344
Show an image at some location on a point cloud using Open3D
<p>So I have a point cloud which I can show on the screen using Open3D's examples. However, now I have an image and I need to show that image on a specific coordinate on the point cloud. I can't find any example about how to do this. Does anyone know how it can be done ? Thank you very much.</p>
<python><point-clouds><open3d>
2024-06-01 18:44:45
1
710
Dang Manh Truong
78,564,587
4,956,494
manim - Can't animate a 3D Coin Flip
<p>I am trying to animate a coin flip using Manim. For that I create a VGroup with a central Cylinder and two Dots for the two sides.</p> <p>Still, when I rotate the object the bottom part doesn't come to the front, it' like the front side always stays there. Can someone help me?</p> <pre class="lang-py prettyprint-ove...
<python><manim>
2024-06-01 18:15:30
1
446
rusiano
78,564,523
7,760,910
Unable to mock awsglue module via tox
<p>I have one method in one of the modules like below:</p> <pre><code>from awsglue.utils import getResolvedOptions from functools import * class FetchArguments: def __init__(self) -&gt; None: pass def fetch_arguments(self, args): </code></pre> <p>and now for this class, I have written a unit test wh...
<python><amazon-web-services><unit-testing><aws-glue><python-unittest>
2024-06-01 17:48:16
0
2,177
whatsinthename
78,564,333
1,802,225
How to init Pool() inside child daemonic, but only once?
<p>On python <code>3.11</code> and <code>Ubuntu</code> I have a task to init asynchronous calls every time interval (not <code>asyncio</code>) and inside child do multiprocessing task. I have 36 cores / 72 processors. The problem is when I init new <code>Pool(72)</code> it takes 0.3 seconds that is too much for my task...
<python><python-3.x><multithreading><multiprocessing><python-multiprocessing>
2024-06-01 16:27:41
1
1,770
sirjay
78,564,217
1,540,785
starting container process caused: exec: "fastapi": executable file not found in $PATH: unknown
<p>I am trying to Dockerize my fastapi application, but it fails with the following error</p> <blockquote> <p>Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: &quot;fastapi&quot;: executab...
<python><docker><fastapi><python-poetry><builder-pattern>
2024-06-01 15:38:00
2
371
kanadianDri3
78,563,834
11,834,577
Tesseract not recognising digits correctly
<p>I have some images, I am preprocessing them before extracting digits from them. The problem is &quot;Tesseract&quot; is not able to extract accurate digits from them. The images only contain digits.</p> <p>Following is my code:</p> <pre><code>from PIL import Image, ImageEnhance, ImageFilter import pytesseract CAPT...
<python><tesseract><python-tesseract>
2024-06-01 12:53:17
0
388
Vishwa Mittar
78,563,796
1,045,364
How to add a scrollbar to python plotly long title
<p>I am using python plotly to create scatterplot using following function-</p> <pre><code>def show_products(products: list[ProductInfo], title: str) -&gt; None: layout = go.Layout( autosize=False, width=1500, height=1500, ...
<python><python-3.x><plotly><formatting>
2024-06-01 12:35:01
0
5,300
Learner
78,563,786
3,010,930
python compile with multiple functions
<p>(edit: simpler example with functions) I'm having trouble compiling a python AST with functions that call each other. A minimal example:</p> <pre><code>def main(): str = &quot;&quot;&quot; def fn_2(): print(&quot;got so far&quot;) def fn(input): fn_2() fn(&quot;abc&quot;) &quot;&quot;&quot; ...
<python><compilation><metaprogramming>
2024-06-01 12:31:41
1
1,434
William
78,563,412
3,160,186
Specify custom errorbar values in Seaborn
<p>I have the following dataframe:</p> <pre class="lang-py prettyprint-override"><code>data = pd.DataFrame([ [&quot;A&quot;, &quot;gelu&quot;, 0.896048951, 0.897377622, 0.893671329], [&quot;A&quot;, &quot;hard_tanh&quot;, 0.889965035, 0.891643357, 0.888566434], [&quot;A&quot;, &quot;leaky_relu&quot;, 0.8952...
<python><seaborn><bar-chart><errorbar>
2024-06-01 10:00:23
0
309
Liuka
78,562,982
6,638,232
How count adjacent points with the same values and label them according to the count in Python
<p>I have the following script and sample data:</p> <pre><code>import numpy as np import pandas as pd # Generating dummy data for testing ROWS=10 COLS=20 X = np.random.randint(2, size=(ROWS, COLS)) # Visualizing df = pd.DataFrame(data=X) bg='background-color: ' df.style.apply(lambda x: [bg+'red' if v&gt;=1 else bg+'y...
<python><numpy>
2024-06-01 06:25:45
0
423
Lyndz
78,562,910
2,396,539
Getting access to a protected member warning shown by pycharm in descriptor get method
<p>I was trying to play around with Python descriptors and Pycharm IDE seems to be complaining</p> <p><a href="https://i.sstatic.net/v8XHPYGo.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/v8XHPYGo.png" alt="enter image description here" /></a></p> <p>Am I using descriptors incorrectly? Or is this expec...
<python><python-descriptors>
2024-06-01 05:42:17
1
69,441
Aniket Thakur
78,562,653
10,001,413
Internal Server Error when hosting flask web app
<p>I am trying to host a flask web app on a hosting platform. So far I have tried to host on vercel and pythonanywhere, and I seem to run into the same issue with both. The code runs fine locally but on the cloud it gives me an <code>Internal Server Error (500)</code></p> <p>The code is long but ill try to shorten it u...
<javascript><python><flask><cloud><hosting>
2024-06-01 02:32:59
1
350
Shell1500
78,562,537
1,762,950
How to save numpy.ndarray in static or thread local variable in python extension written in Rust with PyO3?
<p>I am building a simple python extension to process numpy.ndarray objects using rust-numpy crate. I want to save numpy.ndarray objects in static or thread local variables for later process:</p> <pre class="lang-rust prettyprint-override"><code>use std::cell::RefCell; use numpy::PyReadwriteArray1; use pyo3::{Bound, py...
<python><rust><pyo3>
2024-06-01 00:50:44
1
415
kyleqian
78,562,481
1,802,225
How to close multiprocessing pool inside process?
<p>I am wondering how to make multiprocessing in python (<code>3.11</code>) with asynchronous calls (not <code>asyncio</code> lib) and automatically close processes when they are finished?</p> <p>Below I wrote a simple code and the problem that it does not close pool processes (<code># this prints is never executed</co...
<python><python-3.x><multiprocessing><python-multiprocessing><concurrent.futures>
2024-06-01 00:04:16
1
1,770
sirjay
78,562,406
253,039
Multiplying chains of matrices in JAX
<p>Suppose I have a vector of parameters <code>p</code> which parameterizes a set of matrices <code>A_1(p), A_2(p),...,A_N(p)</code>. I have a computation in which for some list of indices <code>q</code> of length <code>M</code>, I have to compute <code>A_{q_M} * ... * A_{q_2} * A_{q_1} * v</code> for several different...
<python><jax>
2024-05-31 23:13:06
1
402
Evan
78,562,400
14,523,964
Trying to get JSON data from an API but getting an error when I try to concat in a while loop
<p>I am trying to get data from a specific table (<a href="https://data.cms.gov/provider-data/dataset/yizn-abxn" rel="nofollow noreferrer">https://data.cms.gov/provider-data/dataset/yizn-abxn</a>) on the the Centers for Medicare &amp; Medicaid Services website using their API.</p> <p>Because the API only provides 500 r...
<python><json>
2024-05-31 23:10:22
1
655
tonybot
78,562,227
3,954,026
python + SQLAlchemy: deleting taking 250,000x longer than querying the same data
<p>I am accessing a PostGres database using python and SQL ALchemy. I can't figure out how to delete in a timely manner. <strong>The query is fast, the delete takes 250,000x longer</strong></p> <p>I have a table, 'RP', that has 92M rows. I am trying to delete some of them.</p> <p>I have some code that finds the objects...
<python><postgresql><sqlalchemy>
2024-05-31 21:48:59
1
552
Jeff Ellen
78,562,109
2,252,356
Keras model building get error Cannot convert '51' to a shape
<p>I am making a keras model to classify Human pose. I have taken the code from the <a href="https://www.tensorflow.org/lite/tutorials/pose_classification" rel="nofollow noreferrer">link</a></p> <p>In Colab it is working fine. I get below error in my local</p> <p><code>Cannot convert '51' to a shape.</code></p> <pre cl...
<python><tensorflow><machine-learning><keras><deep-learning>
2024-05-31 20:59:15
0
2,008
B L Praveen
78,561,921
6,539,635
How would I implement the Hausdorff distance using Gekko?
<p>If the following function took in arrays A and B that contain arrays of Gekko variables instead of floats, how would I find the Hausdorff distance, aka, how would I define np.inf and modify the rest of the code?</p> <pre><code>def hausdorff_distance(A, B): &quot;&quot;&quot; Compute the Hausdorff distance betwee...
<python><geometry><distance><gekko>
2024-05-31 20:00:18
1
349
Aaron John Sabu
78,561,796
4,159,193
Can't find command fastapi for Python on MSYS2
<p>I want to make the Python fastapi work with MSYS2.</p> <p>I work from the MSYS2 MinGW x64 shell. I have the following installed using the commands:</p> <pre><code>pacman -S mingw-w64-x86_64-python pacman -S mingw-w64-x86_64-python-pip pacman -S mingw-w64-x86_64-python-fastapi </code></pre> <p>and I also ran</p> <pre...
<python><pip><fastapi><msys2>
2024-05-31 19:17:44
2
546
flori10
78,561,713
10,319,707
How can I overcome AWS Glue's extreme memory limitations?
<p><a href="https://docs.aws.amazon.com/glue/latest/dg/add-job-python.html" rel="nofollow noreferrer">A Python Shell job cannot use more than one DPU</a>. This means that it has a limit of 16 GB of memory.</p> <p>Earlier today, I wired what I considered to be a modest ETL task to AWS Glue with 1 DPU. It was written in ...
<python><amazon-web-services><memory><etl><aws-glue>
2024-05-31 18:52:57
1
1,746
J. Mini
78,561,409
8,543,025
Plotly Heatmap Colorbar Displays Ticks in Incorrect Location
<p>I'm creating a 1-line heatmap using plotly, based on <a href="https://chart-studio.plotly.com/%7Eempet/15229/heatmap-with-a-discrete-colorscale/?_gl=1*wtj9of*_ga*MTcyMDM3MTgxLjE3MDkyODYzODQ.*_ga_6G7EE0JNSC*MTcxNzE3MDUwOC40MS4xLjE3MTcxNzA2MjQuNjAuMC4w#/" rel="nofollow noreferrer">this guide</a>. In the original code,...
<python><heatmap><plotly>
2024-05-31 17:22:18
0
593
Jon Nir
78,561,392
13,721,819
How to substitute each regex pattern with a corresponding item from a list
<p>I have a string that I want to do regex substitutions on:</p> <pre><code>string = 'ptn, ptn; ptn + ptn' </code></pre> <p>And a list of strings:</p> <pre><code>array = ['ptn_sub1', 'ptn_sub2', '2', '2'] </code></pre> <p>I want to replace each appearance of the regex pattern <code>'ptn'</code> with a corresponding ite...
<python><python-re>
2024-05-31 17:18:15
3
612
Wilson
78,561,327
260,313
Make version.py visible from setup.py when using pyproject.toml
<p>I have a project with this file structure:</p> <pre><code>project/ |- ... |- include/ \- version.hpp |- conanfile.py |- pyproject.toml |- setup.py \- version.py </code></pre> <ul> <li><code>version.hpp</code> is the only point where I keep the current version.</li> <li><code>version.py</code> programmatically par...
<python><setup.py><pyproject.toml>
2024-05-31 17:01:55
1
8,209
rturrado
78,561,121
2,383,070
How to extend Polars API to work on both DataFrame and LazyFrame
<p>I would like to extend the Polars API as described <a href="https://docs.pola.rs/py-polars/html/reference/api.html" rel="nofollow noreferrer">in the docs</a>, with a single namespace which should work on both DataFrames and LazyFrames.</p> <p>Pretend I have a simple DataFrame, which could just as easily be a LazyFra...
<python><dataframe><python-polars>
2024-05-31 16:12:46
3
3,511
blaylockbk
78,561,116
2,382,272
Importing pandas before tensorflow makes the script freeze
<p>So I have changed from my Windows machine to a MacBook Pro with Apple M3 Pro (36 GB) running with macOS Sonoma (version 14.5) due to a work requirement. I realized something very strange. In a small sample script I managed to extract the root cause of this issue.</p> <p>When I import pandas before tensorflow / keras...
<python><pandas><tensorflow>
2024-05-31 16:12:11
2
1,331
Ilhan
78,561,073
1,126,944
Is Root Logger At Logging Module?
<p>Although my this question seems trivial, but it really makes me doubt is this due to Python documentation mistake or my understanding has some issues ?</p> <p>When I reading Python's logging documentation, I met this <a href="https://docs.python.org/3/howto/logging.html#logging-basic-tutorial" rel="nofollow noreferr...
<python><logging>
2024-05-31 16:01:18
1
1,330
IcyBrk
78,560,979
8,262,535
MLFlow - Is there a way to log all input parameters to a function?
<p>I have a function which is meant to be extendable, and would like to ensure that all input parameters keep being logged without the need to manually check/add them. Is there a way to do this automatically?</p> <pre><code>def __init__(self, model_name: str, num_classes: int, device: str = 'cuda:0', learning_rate: flo...
<python><logging><pytorch><mlflow><pytorch-lightning>
2024-05-31 15:36:45
1
385
illan
78,560,927
2,326,627
Import files from external submodule
<p>Is it possible to execute an external submodule of a project without changing the file content of the submodule itself? Suppose I have this hierarchy.</p> <pre><code>mydir | +-- mya.py | +-- submodule | +-- subpackage | +-- __init__.py | +-- suba.py ...
<python><python-3.x><python-import>
2024-05-31 15:26:53
2
1,188
tigerjack
78,560,578
10,145,953
AWS Textract asynchronous operations within multiprocessing
<p>I am working in a Lambda function within AWS. I have two functions which asynchronously call on Textract to return the extracted text from an image. By switching to this asynchronous operation from a singular call one at a time (which must wait for the result to complete before submitting a new request), given the v...
<python><aws-lambda><multiprocessing><amazon-textract>
2024-05-31 14:16:50
1
883
carousallie
78,560,565
2,867,168
Unable to select tags in BeautifulSoup via CSS Selector
<p>folks! I am currently working with BeautifulSoup to try to scrape some data from a website, and I'm having some issues trying to select elements using <code>soup.select()</code>.</p> <p>Here's a screenshot from my browser of the section of code I'm working with.</p> <p><a href="https://i.sstatic.net/kEsvlndb.png" r...
<python><beautifulsoup>
2024-05-31 14:14:31
1
1,253
MisutoWolf
78,560,561
18,949,720
Streamlit-folium no data return on click
<p>Using streamlit_folium and geopandas explore() to display a choropleth map drawn with this code:</p> <pre><code>m = my_shapefile.explore( column = 'risk', popup = ['ID_PARCEL', 'Risk of infection:'], tooltip = 'Risk of infection:', ) st_data = st_folium(m, width = 800, height = 500) st.write(st...
<python><gis><streamlit><folium><choropleth>
2024-05-31 14:13:24
0
358
Droidux
78,560,536
14,073,111
Create a WEF simulator in python using kerberos authentication
<p>I have a real WEF/WEC setup where i have three machines: Windows Server, Windows 10 (WEF) and Windows 10 (WEC). It works just fine like this... But i want to have a WEF simulator using python with kerbeos authentication.</p> <p>I installed Wireshark on my WEF, just to see what it is actually sending to WEC and seems...
<python><http><python-requests><http-post><multipartform-data>
2024-05-31 14:08:30
1
631
user14073111
78,560,448
3,583,669
Chainlit Stream responses from Groq & Langchain
<p>my Chainlit AI chat application uses Groq, OpenAI embeddings, LangChain and Chromadb, and it allows the user to upload a PDF and interact with it. It works fine, but it spits out the whole response.</p> <p>I'd like it to stream the responses instead. How can I achieve this?</p> <p>Here's the full code below:</p> <pr...
<python><chatbot><langchain><large-language-model><chromadb>
2024-05-31 13:50:03
1
313
Obi
78,560,356
5,547,553
How to update fields with previous fields value in polars?
<p>I have this dataframe:</p> <pre><code>import polars as pl df = pl.DataFrame({ 'file':['a','a','a','a','b','b'], 'ru':['fe','fe','ev','ev','ba','br'], 'rt':[0,0,1,1,1,0], }) </code></pre> <pre><code>shape: (6, 3) ┌──────┬─────┬─────┐ │ file ┆ ru ┆ rt │ │ --- ┆ --- ┆ --- │ │ str ┆ str ┆ i64 │ ╞══════╪...
<python><dataframe><python-polars>
2024-05-31 13:33:41
1
1,174
lmocsi
78,559,814
5,043,301
Form Validation message for Password Confirmation Field
<p>I have below code in <strong>forms.py</strong> file.</p> <pre><code>from django.contrib.auth.forms import UserCreationForm from .models import User class CustomUserCreationForm(UserCreationForm): class Meta: model = User fields = ('first_name','last_name','email','date_of_birth', 'gender...
<python><django>
2024-05-31 11:33:56
1
7,102
abu abu
78,559,671
3,104,974
No fields matching the criteria 'None' were found in the dataset
<p>I'm trying to load a spark dataframe via <a href="https://petastorm.readthedocs.io/en/latest/api.html" rel="nofollow noreferrer">petastorm 0.12</a> following the tutorial given in the <a href="https://learn.microsoft.com/en-us/azure/databricks/_extras/notebooks/source/deep-learning/petastorm-spark-converter-tensorfl...
<python><pyspark><petastorm>
2024-05-31 10:56:59
1
6,315
ascripter
78,559,624
5,678,057
Classification for multi row observation: Long format to Wide format always efficient?
<p>I have a table of observations, or rather 'grouped' observations, where each group represents a deal, and each row representing a product. But the prediction is to be done at a Deal level. Below is the sample dataset.</p> <p><strong>Sample Dataset :</strong></p> <pre><code>df = pd.DataFrame({'deal': ['deal1', 'deal1...
<python><classification><feature-selection><data-preprocessing>
2024-05-31 10:43:21
3
389
Salih
78,559,390
2,636,044
Pydantic v2 fail early
<p>With the following example, I'd expect <code>Root</code> to fail early (after trying to validate <code>sub_model_a</code>, instead, it fails in <code>sub_model_b</code>, I've tried looking at the documentation but can't seem to find a flag for it, I think in pydantic v1 this would fail early?</p> <pre class="lang-py...
<python><python-3.x><pydantic><pydantic-v2>
2024-05-31 09:53:25
1
1,339
Onilol
78,559,388
949,251
Warning: Gradients do not exist for variables
<p>I recently came across a warning in Tensorflow that caused some head-scratching and took a while to fix. Since I didn't find a solution online, I wanted to share.</p> <p>I am building a transformer (encoder-decoder) architecture. But my training results are really bad. The transformer always gives the same answer no...
<python><tensorflow><keras><transformer-model>
2024-05-31 09:53:15
1
831
Cerno
78,559,167
2,276,054
OR-Tools crashing Python 3.12 in Windows work environments only; perhaps MSVCP140.dll-related?
<p>I've created the following simple piece of Python code using OR-Tools:</p> <pre><code>from ortools.sat.python import cp_model print(&quot;1/4&quot;) model = cp_model.CpModel() print(&quot;2/4&quot;) solver = cp_model.CpSolver() print(&quot;3/4&quot;) solver.solve(model) # &lt;------------ crashes here! print(&quo...
<python><or-tools><msvcrt><cp-sat>
2024-05-31 09:17:21
1
681
Leszek Pachura
78,559,149
6,401,403
Exclude rows from MySQL table where timestamp is less than in other row
<p>I have a MySQL table having &quot;datetime&quot; columns <code>begintime</code> and <code>endtime</code>:</p> <pre><code>+---------------------+---------------------+ | begintime | endtime | +---------------------+---------------------+ | 2024-05-22 10:13:23 | 2024-05-31 13:37:34 | | 2024-05-30...
<python><mysql><pandas>
2024-05-31 09:13:18
2
5,345
Michael
78,559,061
14,978,092
How to implement class weight sampling in multi label classification?
<p>I am working on a multi label classification problem and need some guidance on computing class weights using Scikit-Learn.</p> <p><strong>Problem Context:</strong></p> <p>I have a dataset with 9973 training samples.The labels are one-hot encoded, representing 13 different classes.The shape of my training labels is (...
<python><machine-learning><scikit-learn>
2024-05-31 08:57:17
1
590
Hamza
78,558,300
4,732,111
How to access Polars Dataframe containing Struct Type column fields using SQLContext?
<p>I'm trying to execute SQL query on Polars dataframes using SQLContext and below is my code:</p> <pre><code> ctx = pl.SQLContext().register_many( {&quot;tbl1&quot;: df_source, &quot;tbl2&quot;: df_reference}) src_df = ctx.execute(pl_sql_query, eager=True) </code></pre> <p>Here the schema of <strong>df_source...
<python><dataframe><python-polars>
2024-05-31 05:49:58
2
363
Balaji Venkatachalam
78,558,275
7,360,872
How to add SQLTableSchema into chromadb llama-index?
<p>In the code below I need to add one more data into <code>chromadb</code>. How could I do that?</p> <pre><code>from llama_index.core import SQLDatabase from llama_index.core.objects import ( SQLTableNodeMapping, ObjectIndex, SQLTableSchema, ) # chroma db import chromadb fro...
<python><llama-index><chromadb>
2024-05-31 05:42:03
0
928
Abhijith M
78,557,911
3,453,776
Trying to use watchdog/watchmedo on a Python/gRPC service: changes detected, code doesn't refresh
<p>I'm building a gRPC Python app and tried to use <code>watchdog</code> with the <code>watchmedo</code> extension to listen for code changes and reload, like it is described <a href="https://stackoverflow.com/questions/64504406/how-to-hot-reload-grpc-server-in-python">in this question</a>.</p> <p>When the server is lo...
<python><grpc><python-watchdog><grpcio>
2024-05-31 02:54:11
1
571
nnov
78,557,892
2,793,602
Windows task scheduler to execute python script - 0x1 error
<p>I have a python script on a server. It places data from MS SQL Server into a df, then creates a CSV file to a location on the server, and then uploads the CSV file to an FTP site. It checks if there is already a file in that location before creating the CSV, and deletes it if there is.</p> <p>I want Windows Task Sch...
<python><sql-server><scheduled-tasks>
2024-05-31 02:41:55
0
457
opperman.eric
78,557,711
17,246,545
Why getting gym errors in stable-baseline version 2.1.0?
<p>I am uploading an ecr image to an aws lambda and invoking it.</p> <p>In the core code of this ecr image, I am importing stable-baseline3 (2.3.0), and I am using PPO within this library to use PPO.load().</p> <p>It used to work fine, but recently I've been getting the error <code>no module named “gym”</code>.</p> <p>...
<python><python-3.x><docker><aws-lambda><compilation>
2024-05-31 00:57:41
1
389
SecY
78,557,590
7,470,057
What are my options for configuration files that contain a function in python?
<p>I'm creating a chat bot manager in python, where myself (or other developers) can provide a configuration file to the manager and it will generate a bot depending on what it found in the config.</p> <p>The chat bot manager is generally for monitoring different services, and then performing some sort of action depend...
<python><functional-programming><configuration-files>
2024-05-30 23:41:40
1
465
backward forward
78,557,567
12,240,037
Downloading REST data which contains date_time attributes
<p>I am attempting to download data from ArcGIS REST services in ArcGIS Pro using custom geometry. After some <a href="https://stackoverflow.com/questions/78405479/arcgis-rest-map-services-data-query-using-geometry-in-python?noredirect=1#comment138254993_78405479">help</a>, I've managed to get this to work and save the...
<python><rest><datetime><arcgis>
2024-05-30 23:28:25
1
327
seak23
78,557,260
13,794,499
If Python builtins derive from ABCs, then why is their metaclass type instead of ABCMeta?
<p>I was reading PEP-3119, and I discovered that builtins derive from ABCs.</p> <p>From PEP-3119:</p> <blockquote> <p>The built-in type set derives from MutableSet. The built-in type frozenset derives from Set and Hashable.</p> </blockquote> <p>In Python:</p> <pre><code>from collections.abc import Mapping &gt;&gt;&gt; ...
<python><class><inheritance><metaclass><abc>
2024-05-30 21:08:32
1
306
Jordan
78,557,248
2,893,712
Pandas Map Multiple Columns Based on Specific Conditions
<p>My organization uses special codes for various employee attributes. We are migrating to a new system and I have to map these codes to a new code based on certain logic.</p> <p>Here is my mappings df <code>Mappings</code>:</p> <pre><code>State Old_Mgmt New_Mgmt Old_ID New_ID New_Site 01 A001 ...
<python><pandas><mapping>
2024-05-30 21:05:50
3
8,806
Bijan
78,557,050
9,158,985
polars: Enabling global string cache creates smaller parquet files
<h2>Summary of the problem</h2> <h3>Changes made to code</h3> <p>I have a daily job (written in python using polars) that pulls some data from an API, transforms it, and saves it to a parquet file. A number of the columns are stored as <a href="https://docs.pola.rs/py-polars/html/reference/api/polars.datatypes.Categori...
<python><python-polars>
2024-05-30 20:00:19
0
880
natemcintosh
78,556,853
9,127,614
Artifact when creating and filling in a 2d list in Python
<p>Predefining a &quot;matrix&quot;:</p> <pre><code>m = [[0] * 2] * 3 </code></pre> <p>Changing one element at position 0,1:</p> <pre><code>m[0][1] = 1 </code></pre> <p>Checking:</p> <pre><code>print(m) [[0, 1], [0, 1], [0, 1]] </code></pre> <p>All the elements m[0], m[1] and m[2] have now 1 at position 1. Why? Th...
<python><list><matrix>
2024-05-30 19:12:13
0
1,179
Mikhail Zakharov
78,556,399
2,153,235
Hide pandas column headings in a terminal window to save space and reduce cognitive noise
<p>I am looping through the groups of a pandas <code>groupby</code> object to print the (sub)dataframe for each group. The headings are printed for each group. Here are some of the (sub)dataframes, with column headings &quot;MMSI&quot; and &quot;ShipName&quot;:</p> <pre class="lang-none prettyprint-override"><code> ...
<python><pandas><dataframe>
2024-05-30 17:09:42
2
1,265
user2153235
78,556,386
4,814,342
How to create a custom role with specific permissions in Airflow using AirflowSecurityManager or other?
<p>I'm currently working on a project where I need to create custom roles with specific permissions in Apache Airflow. I have a dictionary that contains the role names and their corresponding permissions. Here is an example of the dictionary:</p> <pre><code>roles_permissions = { &quot;Role1&quot;: [&quot;can_dag_re...
<python><security><airflow><roles>
2024-05-30 17:06:30
1
947
Náthali
78,556,221
504,717
Get bytes data instead of writing using wfdb.wsramp
<p>We are using <a href="https://wfdb.readthedocs.io/en/latest/wfdb.html#wfdb.wrsamp" rel="nofollow noreferrer">wfdb</a> to write medical info for clients. However, this code has hardcoded requirements to &quot;write-to-a-directory&quot;. Is there a way if I can get byte content so that i can upload it to S3?</p> <p>Th...
<python><wfdb>
2024-05-30 16:26:56
1
8,834
Em Ae
78,556,172
2,977,256
Historical forecast in time series libraries
<p>I have been using Darts, where there is a very nice historical forecast functionality, and also nixtla's neuralforecast library. The latter does have cross-validation, which can mimick a historical forecast, but is bog-slow (unlike the other parts of nixtla's library, which are very speedy, and allow for a lot more ...
<python><time-series>
2024-05-30 16:16:16
1
4,872
Igor Rivin
78,556,068
5,547,553
Why does the results of str.extract and str.extract_all differ in polars?
<br> <p>Why does the result for str.extract and str.extract_all differ?<br> Should str.extract_all not return only the capture group, like str.extract does?</p> <pre><code>import polars as pl #polars==0.20.30 dff = pl.DataFrame({'a': 'Label: name, Value: John, Label: car, Value: Ford'}) (dff.with_columns(pl.col('a').s...
<python><regex><python-polars>
2024-05-30 15:54:37
0
1,174
lmocsi
78,555,894
10,425,150
Find all columns with "dateformat" in dataframe
<p>For the following <code>df</code> I would like to extract columns with &quot;dates&quot;:</p> <pre><code>import pandas as pd df = pd.DataFrame([[&quot;USD&quot;, 12.3, 1, 23.33, 33.1],[&quot;USD&quot;, 32.1, 2, 34.44, 23.1]],columns= ['currency', '1999-07-31', 'amount', '1999-10-31', '2000-01-31']) </code></pre> <di...
<python><pandas><dataframe>
2024-05-30 15:21:31
1
1,051
Gооd_Mаn
78,555,801
4,245,882
Get Position of clicked pixel on an image in justpy
<p>In justpy, I would like to load an image and record which pixel a clicked on. So I need the position of the pixel of an image with an offset, not position of the mouse on screen.</p> <p>JustPy click and click_out event do not give any coordinates at all, even in debug mode.</p> <pre><code>{'event_type': 'click__out'...
<python><justpy>
2024-05-30 15:01:11
1
698
stupidstudent
78,555,437
23,260,297
Exporting dataframe to excel with indexes
<p>I am exporting a dataframe to excel. I am using this piece of code:</p> <pre><code>with pd.ExcelWriter(path, engine='openpyxl', mode='w') as writer: df.to_excel(writer, sheet_name=name, index=False) </code></pre> <p>I know using <code>index=False</code> removes the indexes in excel. However, I have a ...
<python><pandas><excel><openpyxl>
2024-05-30 13:54:18
1
2,185
iBeMeltin
78,555,411
8,510,149
Fillna with values from other rows with matching keys
<p>In the dataframe I define below I want to use the features ID and ID2 to fill the cells of features val1 and val2 with values. I want all ID and ID2 cominations to have the same values for the features val1 and val2.</p> <pre><code> df = pd.DataFrame({'ID':[0,0,0,1,1,1], 'DATE':['2021', '2022', '2023'...
<python><pandas>
2024-05-30 13:49:43
2
1,255
Henri
78,555,334
72,791
Filter a pandas DataFrame based on multiple columns with a corresponding list of values
<p>I have a DataFrame that looks a bit like this:</p> <pre><code> A B C D ... G H I J 0 First First First First ... 0.412470 0.758011 0.066926 0.877992 1 First First First Third ... 0.007162 0.957042 0.601337 0.636086 2 First First Third Fi...
<python><pandas><dataframe>
2024-05-30 13:36:40
2
73,231
DrAl
78,555,002
561,243
Problem plotting pandas dataframe containing arrays
<p>I have a tricky question for you concerning data structure in pandas for plotting with seaborn.</p> <p>Let's imagine, I have several experiments, each of them performed in different conditions. The result of each experiment is an array with a few thousand floats.</p> <p>I was considering to have all the experiment r...
<python><pandas><dataframe><seaborn>
2024-05-30 12:35:58
1
367
toto
78,554,968
982,402
Automate print pdf using robot framework
<p>I am using windows. My application has a print icon. On click of that print icon opens the send to print window. How to automate this print window.</p> <p>I already tried below steps but nothing worked so far. The focus never goes to this print window. Please guide.</p> <pre><code>Click Element my-print-icon-id ...
<python><automation><pytest><robotframework>
2024-05-30 12:30:52
1
1,719
Anna
78,554,699
1,390,887
XSL for each text starts-with select in variable
<p>i have this XML in input:</p> <pre><code> &lt;root&gt; RH03051CDSIA280524CM1490301951171 610000001 93001 G0305101700000000004575EUR270524C000000000000,00IT44 62000000100127052427...
<python><xml><xslt><transform>
2024-05-30 11:33:42
2
1,380
Catanzaro
78,554,551
2,846,140
Adapt context to log level in structlog
<p>A common need when logging events is to provide more or less information depending on the log level. Consider the example below where some noisy payload should be included in the logs only if the log level is <code>DEBUG</code> or below. I found 3 possible approach so far:</p> <pre class="lang-py prettyprint-overrid...
<python><structlog>
2024-05-30 11:01:37
1
13,475
Vincent
78,554,273
10,516,773
Gmail API history().list() returns only history id?
<p>I'm using Subscription listen script like this, but even though i sent new email for inbox every time it sends only, <code>{'historyId': 123456 }</code>,</p> <p>i tried every possible changes i can think of regenerate access tokens, Purge Pub Sub messages still no luck, what i am missing here.</p> <pre><code>from go...
<python><google-cloud-platform><gmail-api><google-cloud-pubsub>
2024-05-30 10:03:23
0
1,120
pl-jay
78,553,974
12,430,846
qcut is not finding quantiles (many 0s and 1s duplicated in my df)
<p>I have a column of my df with <code>MAX_PERC</code> column ranging from 0 to 1.</p> <ul> <li>The count of 0s are 103168.</li> <li>The count of 1s are 32364.</li> <li>The count of obs less than 1 and more than 0.8 is 2594.</li> <li>The count of obs more than 0 and less than 0.8 is 129.</li> </ul> <p>I'm trying to us ...
<python><pandas><dataframe><numpy><quantile>
2024-05-30 09:06:43
1
543
coelidonum