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,734,373
9,116,959
Erratic Behavior in xTerm Terminal While Running Long Python Script with SSH Connections
<p>Using <code>xTerm</code> terminal to run a long Python script. Randomly, while the script is running, the terminal behavior becomes erratic. New lines and indents get messed up. For example, I see</p> <pre><code> **************************************************************************************************** ...
<python><terminal><indentation><xterm>
2024-07-11 08:19:06
0
632
Kfir Ettinger
78,734,366
11,148,741
Send email via EmailMultiAlternatives sudenly stopped working
<p>I encounter a strange error. The email sending stopped working since yesterday before all was fine. I did not change a thing at all.</p> <p>Error message is:</p> <pre><code> 2024-07-11 09:35:01,147 share.email.service ERROR Traceback (most recent call last): File &quot;/srv/deduu/./share/email/service.py&quot;...
<python><django><smtplib>
2024-07-11 08:17:41
0
489
Matt
78,734,268
2,466,784
I have designed a separate database file for handling database queries for sqlite database in python but facing issue in execute function
<p>I am working on a sqlite database python based project , to keep the code neat and clean I am passing the values of my form fields along with database name and table name to another python file , whose work is to handle only database queries , I have framed the query everthing is working fine but I am getting error ...
<python><sqlite>
2024-07-11 08:01:14
0
805
Arun Agarwal
78,733,931
1,716,733
pip wheel installation overrides version
<p>I am trying to install a Python package from a wheel:</p> <pre><code>pip install PyMuPDF==1.24.7 --no-index --find-links file:///Users/myusername/Downloads/PyMuPDF-1.24.7-cp310-none-macosx_11_0_arm64.whl </code></pre> <p>But getting this error:</p> <pre><code>ERROR: Could not find a version that satisfies the requi...
<python><pip><python-wheel>
2024-07-11 06:44:47
1
13,164
Dima Lituiev
78,733,661
395,857
How can I extract which Python lines are used when running a Python script, including the Python lines of the libs it's using?
<p>Example: I have this Python script <code>SE_Q_coverage.py</code>:</p> <pre><code># pip install transformers from transformers import AutoModelForTokenClassification, AutoTokenizer tokenizer = AutoTokenizer.from_pretrained('huawei-noah/TinyBERT_General_4L_312D') if False: print('this line is not hit') tokenized_i...
<python>
2024-07-11 05:10:39
1
84,585
Franck Dernoncourt
78,733,473
319,058
How to pass all Python's traffics through a socks proxy?
<p>There is <a href="https://stackoverflow.com/a/31641300/319058">How to pass all Python's traffics through a http proxy?</a> However that one does not deal with sock proxy. I want to use sock proxy which we can get easily with ssh tunneling.</p> <pre><code>ssh -D 5005 user@server </code></pre>
<python><proxy><tinyproxy>
2024-07-11 03:51:49
1
5,477
Win Myo Htet
78,733,472
4,732,111
How to initialise a list defined at the class level from a common method outside of the class in python?
<p>I have a list defined at the class level in Python and below is my code:</p> <pre><code>class TestStudentReg(unittest.TestCase): student_id_list = [] </code></pre> <p>I'm trying to initialise the list by reading values from a csv file and below is the method that i use within the same class i.e., <em>TestStude...
<python><python-3.x>
2024-07-11 03:51:21
1
363
Balaji Venkatachalam
78,733,467
898,249
python script crashes on Windows; fixed by running a separate memory update py script
<p>I have a Python Flask API server that crashes after a few seconds when running on my new Windows machine (a Dell work station). There is usually no error message, but sometimes there are errors related to Python libraries (not my code). <a href="https://i.sstatic.net/eAlNlnIv.png" rel="nofollow noreferrer"><img src=...
<python><windows><flask><memory><hardware>
2024-07-11 03:48:03
2
689
Randy Lam
78,733,361
24,758,287
How to take the average of all previous entries in a group?
<p>I'd like to do the following in python using the polars library:</p> <p>Input:</p> <pre class="lang-py prettyprint-override"><code>df = pl.from_repr(&quot;&quot;&quot; β”Œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Name ┆ Number β”‚ β”‚ --- ┆ --- β”‚ β”‚ str ┆ i64 β”‚ β•žβ•β•β•β•β•β•β•ͺ════════║ β”‚ Mr.A ┆ 1 β”‚ β”‚ Mr.A ┆ 4 β”‚ β”‚ Mr.A ┆ 5 β”‚ β”‚ Mr....
<python><grouping><python-polars>
2024-07-11 02:54:25
1
301
user24758287
78,733,192
11,628,437
How to seed `gymnasium` environment resets when using `stable_baselines3`?
<p>I would like to seed my gymnasium environment. From the <a href="https://gymnasium.farama.org/" rel="nofollow noreferrer">official documentation</a>, the way I'd do it is -</p> <pre class="lang-py prettyprint-override"><code>import gymnasium as gym env = gym.make(&quot;LunarLander-v2&quot;, render_mode=&quot;human&q...
<python><reinforcement-learning><stable-baselines><gymnasium>
2024-07-11 01:17:10
1
1,851
desert_ranger
78,733,174
5,754,215
How can I use styles from an existing docx file in my new document?
<p>I have a beautiful .docx file generated by a teammate and I would like to use the styles in it as defaults for the new documents I am generating programmatically via python-docx.</p> <p>I am able to load the existing docx file but it isn't clear how to use the styles from the document in my newly created documents.<...
<python><python-docx>
2024-07-11 01:00:02
1
551
Not a machine
78,733,059
11,748,924
Broadcasting multiple versions of X_data that pair with the same y_data
<p>My deep learning architecture accepts an input vector with size <strong>512</strong> and an output vector with size <strong>512</strong> too.</p> <p>The problem is I have <code>X_data</code> version that pairs with the same <code>y_data</code>.</p> <p>I have these tensors:</p> <pre><code>(4, 8, 512) -&gt; (batch_siz...
<python><numpy><tensorflow><keras><deep-learning>
2024-07-10 23:38:28
1
1,252
Muhammad Ikhwan Perwira
78,732,981
3,884,734
Snowflake Native app with container service, grant imported privilege on Snowflake DB
<p>How can a snowflake native application built with container services request or grant imported privilege on Snowflake DB?</p> <p>According to <a href="https://other-docs.snowflake.com/en/native-apps/consumer-granting-privs#grant-the-imported-privileges-privilege-on-the-snowflake-database" rel="nofollow noreferrer">S...
<python><sql><docker><snowflake-cloud-data-platform>
2024-07-10 22:58:06
1
4,411
Sajal
78,732,956
12,224,591
Save 16-bit PGM Image with Python PIL?
<p>I am attempting to convert an image in PNG format to a 16-bit PGM format and save it using Python's <a href="https://python-pillow.org/" rel="nofollow noreferrer"><code>PIL</code></a> library. I'm using Python 3.12.4 in all examples shown.</p> <hr /> <p>Using the following <code>test.png</code> image:</p> <p><a href...
<python><python-imaging-library><pgm>
2024-07-10 22:42:54
2
705
Runsva
78,732,871
2,153,235
Global namespace changes depending on scope?
<p>I have the following function defined in my Spyder startup file:</p> <pre><code># startup.py #----------- def del_globals(*names): for name1 in names: try: del globals()[name1] except KeyError: pass # Ignore if name1 doesn't exist </code></pre> <p>At the Spyder console, I run the following script with...
<python><global-namespace>
2024-07-10 22:05:57
1
1,265
user2153235
78,732,772
601,684
How to get bot's conversation history with user in aiogram?
<p>I'm making a telegram bot using the aiogram (v3.9.0) library for python (v3.11) and I need to access some previous messages in a conversation with a user. Please note that we are not talking about a group or channel, but about a private chat, where the user starts the bot with the <code>/start</code> command.</p> <p...
<python><telegram-bot><aiogram>
2024-07-10 21:30:36
0
836
alexeyprog
78,732,770
20,394
Type for heterogeneous *args
<p>In typed Python, how do you type a <code>*args</code> list that you're expecting to pass to another argument that is a higher kinded function?</p> <p>For example, this function takes a function and its first argument and internally just routes <code>*args</code> through, but its type signature depends on the type of...
<python><variadic-functions><python-typing><higher-order-functions>
2024-07-10 21:29:54
1
120,803
Mike Samuel
78,732,560
18,150,609
Applying styles to Pandas multiindex, using all index levels for context
<p>I am attempting to style a dataframe with cell colors based on categories provided via the index. Index levels 0 and 1 provide the fruit and part. I want every cell to be colored based on distinct categories of fruit parts. This works fine when trying to format the cells values throughout the dataframe, but produces...
<python><python-3.x><excel><pandas><dataframe>
2024-07-10 20:07:53
1
364
MrChadMWood
78,732,502
12,021,983
Embedded python script in golang with go routines
<p>I'm working on a Go application that interfaces with Python via CGO to process store data. I'm using goroutines because I have more than 4M store.</p> <p>Issue: The execution gets blocked after some iterations.</p> <p>Here's a simplified overview of the relevant code snippets:</p> <p>Go Code (main package):</p> <pr...
<python><c><go><cgo>
2024-07-10 19:55:37
0
531
sokida
78,732,473
2,153,235
"del" a list of variables, some which don't exist, without invoking globals()
<p>In <a href="https://stackoverflow.com/questions/78727436">this Q&amp;A</a>, I describe why I wish to issue (say) <code>del a,b,c</code> where some of the variables do not exist. All solutions work, but they make use of <code>globals()</code> because that is the prevailing namespace. That is, I run a script and the...
<python>
2024-07-10 19:46:26
1
1,265
user2153235
78,732,261
14,230,633
How to turn off linting in ipynb notebooks?
<p>Is it possible to turn off the squiggly underline linting in notebooks but not other (Python) scripts?</p>
<python><visual-studio-code><jupyter-notebook>
2024-07-10 18:39:25
1
567
dfried
78,732,237
8,545,026
FastAPI uvicorn starrlette gradio package errors
<p>I am trying to upgrade a gradio app to the latest version. I have been able to get the app running again but it's throwing server errors when i go to the browser. I am getting the following errors listed:</p> <pre><code>ValueError: too many values to unpack (expected 2) ERROR: Exception in ASGI application Traceb...
<python><fastapi><uvicorn><gradio>
2024-07-10 18:30:42
1
550
Husk Rekoms
78,732,010
899,862
Use of defalut dict such that the default is a dict with an empty list
<p>The main object is a dictionary whose keys are strings, values a 2nd dictionary.<br /> The 2nd dictionary has string keys, and list values.</p> <p>I want to append a new value to the empty list created using defalutdict()</p> <p>Here is what I am trying to do:</p> <pre class="lang-py prettyprint-override"><code>impo...
<python><dictionary><defaultdict>
2024-07-10 17:31:09
1
2,620
Mikef
78,731,945
251,589
Get the name of the current python distribution (name field in pyproject.toml)
<p>I am getting the version of my package using this code:</p> <pre class="lang-py prettyprint-override"><code>import importlib.metadata importlib.metadata.version(&quot;mypackage&quot;) </code></pre> <p><a href="https://stackoverflow.com/a/73904403/251589">As documented in this question</a></p> <p>I would like to avoi...
<python><package>
2024-07-10 17:14:32
0
27,385
sixtyfootersdude
78,731,803
9,884,998
Create Matrix by Multiplying ith and jth Vector-Element in Numpy
<p>I need to calculate a the error function V</p> <pre><code>V = Ξ£i Ξ£j X[i] X[j] Οƒ[i][j] </code></pre> <p>Where <code>Οƒ[i][j]</code> is a given matrix and I need a relatively fast solution. To do this I want to create another matrix Y where</p> <pre><code>Y[i][j] = X[i]*X[j] </code></pre> <p>So I that I can simply sum ...
<python><numpy>
2024-07-10 16:40:50
2
529
David K.
78,731,732
9,854,132
Cannot find an element with Selenium in Python
<p>From this url: <a href="https://ec.europa.eu/economy_finance/recovery-and-resilience-scoreboard/milestones_and_targets.html?lang=en" rel="nofollow noreferrer">https://ec.europa.eu/economy_finance/recovery-and-resilience-scoreboard/milestones_and_targets.html?lang=en</a></p> <p>I want to click to the following button...
<python><selenium-webdriver>
2024-07-10 16:25:28
2
316
Theodosis Siomos
78,731,615
5,547,553
How to rewrite Oracle sql's hierarchical query to polars?
<p>In Oracle I have the following hierarchical sql:</p> <pre class="lang-sql prettyprint-override"><code>with prod as (select 10 id,'1008' code from dual union all select 11 id,'1582' code from dual union all select 12 id,'1583' code from dual union all select 13 id,'2023' code...
<python><sql><python-polars><recursive-query>
2024-07-10 15:56:30
1
1,174
lmocsi
78,731,458
941,397
How to start gunicorn when using a custom Post Deployment Action on Azure App Service
<p>I am trying to use a Post Deployment Action on Azure App Service with a Flask app. I followed <a href="https://stackoverflow.com/questions/64895608/run-post-deployment-action-on-azure-app-service">this</a> Stack overflow post to accomplish the Post Deployment Action, but this results in the container not starting wi...
<python><azure><flask><deployment><azure-web-app-service>
2024-07-10 15:25:25
1
8,133
Superdooperhero
78,731,437
353,337
Linear interpolation function `interp1d`, replacement after deprecation
<p>In SciPy, there are numerous interpolation function that return a function, e.g., <code>Akima1DInterpolator</code>. I'd like to have the same for a simple linear interpolator. <code>interp1d</code> does the trick, but is deprecated. What can I replace it with?</p> <pre class="lang-py prettyprint-override"><code>impo...
<python><scipy>
2024-07-10 15:20:27
2
59,565
Nico SchlΓΆmer
78,731,396
13,100,938
Fixed windowing not producing synchronous output
<p>I am using the Apache Beam Python SDK to create a Dataflow pipeline.</p> <p>Steps:</p> <ol> <li>ingest synchronous pubsub messages</li> <li>window into 1 second windows with 600ms allowed latency and a 2 second processing trigger</li> <li>transform data</li> <li>write to Firestore synchronously (1Hz)</li> </ol> <p>C...
<python><google-cloud-firestore><apache-beam>
2024-07-10 15:12:12
1
2,023
Joe Moore
78,731,355
251,589
Why is `__name__` of `__init__` different when importing directly?
<p>I have a directory structure like this:</p> <pre><code>. β”œβ”€β”€ main.py └── silly_test β”œβ”€β”€ __init__.py └── foo.py </code></pre> <pre><code># main.py import silly_test.foo import silly_test.__init__ # This line is unusual - I wouldn't typically do this. </code></pre> <pre><code># silly_test/__init__.py print(f...
<python><import>
2024-07-10 15:04:07
1
27,385
sixtyfootersdude
78,731,243
20,176,161
Convert a dataset into a dataframe with two columns
<p>I have a dataset <code>X</code> which I have tried to convert into a dataframe.</p> <p>The dataset <code>X</code> is as follows:</p> <pre><code> X= woe_transform.fit_transform(df) libelle_situation_professionnelle:AUTRES libelle_situation_professionnelle:RETRAITE ... montant_echeance_d:(1347.0, 1561.0] mont...
<python><pandas><dataframe>
2024-07-10 14:42:39
1
419
bravopapa
78,731,018
2,618,377
Non-supported wavelets in PyWavelets cwt()
<p>I'm am refreshing my knowledge of wavelets by working through some of the examples in Fugal's book, &quot;Conceptual Wavelets in Digital Signal Processing&quot; (2006) using PyWavelets rather than Matlab. I have run into a problem in the very first introductory chapter. Mr. Fugal presents two examples of using the...
<python><matlab><pywavelets>
2024-07-10 13:56:14
1
421
Pat B.
78,730,970
2,521,423
Checking subclass against metaclass type
<p>I have a set of plugins that inherit from a metaclass. the metaclasss is defined like so:</p> <pre><code>from abc import ABC, abstractmethod class MetaReader(ABC): def __init__(self, arg1, arg2, **kwargs): ... </code></pre> <p>and the subclass like so:</p> <pre><code>from utils.MetaReader impor...
<python><metaclass><abc>
2024-07-10 13:47:07
1
1,488
KBriggs
78,730,773
5,224,881
How to make clickable link compatible with IDEs and mkdocs?
<p>My docstrings contain links. I want to make these links clickable in IDE, but I want to use the <a href="https://github.com/mkdocstrings/python" rel="nofollow noreferrer">https://github.com/mkdocstrings/python</a> to generate mkdocs api reference. I want to use this package, because the rest of my documentation is i...
<python><docstring><mkdocs><mkdocstrings>
2024-07-10 13:08:33
1
1,814
MatΔ›j RačinskΓ½
78,730,743
7,746,472
Transpose XLSX and send to database, using Pandas
<p>I have a xlsx file that is structured in an unorthodox way. Simplified, it looks like this:</p> <div class="s-table-container"><table class="s-table"> <thead> <tr> <th></th> <th>A</th> <th>B</th> <th>C</th> <th>D</th> <th>E</th> <th>F</th> </tr> </thead> <tbody> <tr> <td>1</td> <td></td> <td></td> <td></td> <td></td...
<python><python-3.x><pandas><dataframe>
2024-07-10 13:01:56
3
1,191
Sebastian
78,730,642
8,037,521
Non-blocking Tkinter window
<p>I have read multiple similar questions &amp; answers, but somehow still have not understood how to apply them to my particular use case. The best I found was using Tkinter with <code>Thread</code>:</p> <pre><code>from Tkinter import * import threading class App(threading.Thread): def __init__(self, tk_root): ...
<python><multithreading><tkinter>
2024-07-10 12:40:22
0
1,277
Valeria
78,730,606
21,152,416
How to update nested attribute name for specific DynamoDB items
<p>I use <code>boto3</code> client for managing DynamoDB items. Let's assume that the item structure is the following:</p> <pre class="lang-json prettyprint-override"><code>{ &quot;id&quot;: &quot;item_id&quot;, &quot;name&quot;: &quot;item_name&quot;, &quot;age&quot;: 23, &quot;body&quot;: { {&quot;nested&...
<python><amazon-web-services><amazon-dynamodb><boto3>
2024-07-10 12:34:31
1
1,197
Victor Egiazarian
78,730,254
351,410
Matplotlib: adjust z-order of bar chart after adding all bars
<p>When adding a series of bars to a stacked bar chart in <code>matplotlib.pyplot</code>, there is only one <code>zorder</code> argument for the entire series, and it only accepts a single integer (not an array-like, which would be preferable). My chart has several series, and the intended z-order changes at each bar p...
<python><matplotlib>
2024-07-10 11:22:41
0
2,715
Byron Hawkins
78,730,136
6,583,936
Scatter 3d animation frames dont display all traces
<p>I have searched for proper animation script and come up with following function on how to add traces:</p> <pre><code>from plotly import graph_objects as go def add_anim_frames(figure: go.Figure, traces): sliders_dict = { &quot;active&quot;: 0, # &quot;yanchor&quot;: &quot;top&quot;, # &...
<python><animation><plotly><scatter3d>
2024-07-10 10:59:57
1
320
mcstarioni
78,729,859
11,748,924
Numpythonic way to fill value based on range indices reference (label encoding from given range indices)
<p>I have this tensor dimension:</p> <pre><code>(batch_size, class_id, range_indices) -&gt; (4, 3, 2) int64 [[[1250 1302] [1324 1374] [1458 1572]] [[1911 1955] [1979 2028] [2120 2224]] [[2546 2599] [2624 2668] [2765 2871]] [[3223 3270] [3286 3347] [3434 3539]]] </code></pre> <p>How do I construct ...
<python><numpy>
2024-07-10 09:59:35
2
1,252
Muhammad Ikhwan Perwira
78,729,186
7,448,592
dynamic subplot dimensions
<p>I want to plot several subplots. Depending on the data it might by a N x M array of plots, but also only a single plot or a 1 x M or N x 1 array.</p> <p>The code I'm using is as follows which works for M x N arrays. However if M or N or both are 1 I get the Error: <em>matplotlib IndexError: too many indices for arra...
<python><matplotlib>
2024-07-10 07:38:39
1
485
goaran
78,728,925
7,735,258
How to generate canonicalized element using c14n11
<p>I am signing my XML document using Python's signxml library. Here's my code:</p> <pre><code>signer = XMLSigner( method=methods.enveloped, signature_algorithm=&quot;rsa-sha256&quot;, c14n_algorithm=&quot;http://www.w3.org/2006/12/xml-c14n11&quot;, digest_algorithm=&quot;sha256&quot;, ...
<python><xml><hash><digital-signature><c14n>
2024-07-10 06:28:23
0
321
Package.JSON
78,728,639
10,855,529
Separate a column with hybrid data types in polars
<p>I have column with containing data of multiple data types as string. Now, I am wondering how I can split the data into separate columns (one for each data type).</p> <p><strong>Input.</strong></p> <pre class="lang-py prettyprint-override"><code>df = pl.DataFrame({ &quot;hybrid_column&quot;: [&quot;1&quot;, &quot...
<python><python-polars>
2024-07-10 04:48:48
1
3,833
apostofes
78,728,631
3,377,314
How to render a static SVG in Shiny for Python?
<p>Is there a way to render a SVG in a shiny-python app directly rather than convert it to a png and then render it from an <code>ImgData</code>, by calling <code>ui.output_plot</code>?</p>
<python><py-shiny>
2024-07-10 04:46:07
1
969
Devil
78,728,112
11,439,134
How to create python wheel for each platform and only include binaries for that specific platform
<p>My project has the structure:</p> <pre><code>project - binaries - win32 - win64 - linux32 - linux64 - linuxarm - darwin64 - darwinarm </code></pre> <p>Each of the folders contains binaries that the project uses that are specific to the platform.</p> <p>I'm trying to create a wheel for the projec...
<python><setuptools><python-wheel>
2024-07-09 23:49:27
0
1,058
Andereoo
78,728,033
11,748,924
Numpythonic ways of converting sparse to dense based on referenced index
<p>I have this sparse vector <code>val</code> with this Pythonic way:</p> <pre><code>idx = [2, 5, 6] val = [69, 12, 15] _ = np.zeros(idx[-1]+1) for i in idx: _[i] = val[idx.index(i)] print(_) dbg(_) </code></pre> <p>Here is the output:</p> <pre><code>[ 0. 0. 69. 0. 0. 12. .15] (6,) float64 </code></pre> <p>How do...
<python><numpy>
2024-07-09 23:05:06
2
1,252
Muhammad Ikhwan Perwira
78,727,846
14,301,545
TypeError: cannot pickle 'builtins.DT' object - multiprocessing, pickle, pathos
<p>I'm using &quot;startinpy&quot; library (<a href="https://startinpy.readthedocs.io/en/0.10.2/" rel="nofollow noreferrer">https://startinpy.readthedocs.io/en/0.10.2/</a>) in my project. It generally works great, but when I want to use it in second process, the pickle error shows up:</p> <p><code>TypeError: cannot pic...
<python><multiprocessing><pathos>
2024-07-09 21:44:50
1
369
dany
78,727,843
4,894,593
cimport cython module that wraps C libraries
<p>I have this kind of C/cython project:</p> <pre><code>project/ β”œβ”€β”€ src/ β”‚ └── modules/ β”‚ β”œβ”€β”€ cython1.pyx β”‚ β”œβ”€β”€ cython1.pxd β”‚ β”œβ”€β”€ cython2.pyx β”‚ β”œβ”€β”€ cython2.pxd β”‚ β”œβ”€β”€ includes/ β”‚ β”‚ β”œβ”€β”€ c1.h β”‚ β”‚ β”œβ”€β”€ c1.c β”‚ β”‚ β”œβ”€β”€ c2.h β”‚ β”‚ β”œβ”€β”€ c2.c β”‚ └── ... └── setup.p...
<python><c><cython>
2024-07-09 21:42:54
0
1,080
Ipse Lium
78,727,839
23,260,297
Create config file for python script with variables
<p>I have a config file for a python script that stores multiple different values</p> <p>my config.ini looks like this:</p> <pre><code>[DHR] key1 = &quot;\\path1\...&quot; key2 = &quot;\\path2\...&quot; key3 = &quot;\\path3\file-{today}.xlsx&quot; </code></pre> <p>my <code>.py</code> has a date variable that gets toda...
<python>
2024-07-09 21:42:38
2
2,185
iBeMeltin
78,727,781
2,397,318
Showing one x tick per month on a pandas plot
<p>I have a time series with daily data, that I want to plot, and only plot a x-tick every month. I have tried multiple approaches (including the ones described <a href="https://stackoverflow.com/questions/69101233/using-dateformatter-resets-starting-date-to-1970">here</a>, but it seems that pandas considers my data fr...
<python><pandas><matplotlib><bar-chart>
2024-07-09 21:24:12
1
3,769
meto
78,727,605
6,573,259
How to safely run a python script indefinitly?
<p>Im planning on making a script on python that monitors some external parameters and act based on the retrieved data. The check basically is do an http call on a server on the network, and if the response it not as expected do another http call on another server on the network.</p> <p>The script will have a 60 second...
<python><python-3.x>
2024-07-09 20:19:36
1
752
Jake quin
78,727,436
2,153,235
One-liner to specify many variables for "del" and ignore those that don't exist
<p>I am using Spyder for exploratory data analysis -- not for production code. I like to think of my script as a sequence of major sections. At the end of each section, I want to delete the temporary objects so that the Variable Explorer in Spyder isn't too crowded. However, the objects that exist depend on the cont...
<python>
2024-07-09 19:27:25
5
1,265
user2153235
78,727,326
6,622,697
How to run a function at startup before requests are handled in Django?
<p>I want to run some code when my Django server starts-up in order to clean up from the previous end of the server. How can I run some code once and only once at startup before the server processes any requests. I need to access the database during this time.</p> <p>I've read a couple of things online that seem a bit ...
<python><django>
2024-07-09 18:57:44
1
1,348
Peter Kronenberg
78,727,261
9,951,273
How to dynamically define class variables?
<p>Let's say I want to create a class:</p> <pre><code>class Foo: hello = &quot;world&quot; goodbye = &quot;moon&quot; </code></pre> <p>But both of those class variables are dynamically provided.</p> <pre><code>attrs = [(&quot;hello&quot;, &quot;world&quot;), (&quot;goodbye&quot;, &quot;moon&quot;)] def create...
<python><class>
2024-07-09 18:39:25
1
1,777
Matt
78,727,228
56,207
Replace removed function PyArray_GetCastFunc in numpy 2
<p>I'm migrating some python C extension to numpy 2. The extension basically gets a list of 2D numpy arrays and generates a new 2D array by combining them (average, median, etc,). The difficulty is that the input and output arrays are byteswapped. I cannot byteswap the input arrays to machine order (they are too many t...
<python><numpy>
2024-07-09 18:26:15
1
727
Sergio
78,727,183
3,821,009
Distinct elements across subgroups for each group in polars
<p>Consider this data frame:</p> <pre><code>df = (polars .DataFrame( dict( j=[1,1,1,1,2,2,3,3,3,3,3,3,3], k=[1,1,2,2,3,3,4,4,5,5,6,6,6], l=[1,2,1,2,2,2,3,4,3,3,3,4,3], u=[1,1,1,1,2,2,3,3,3,3,3,3,3], ) ) ) j k l u i64 i64 i64 i64 1 1 1 1 1 1 2 ...
<python><python-polars>
2024-07-09 18:15:48
1
4,641
levant pied
78,727,159
1,600,870
How do I add a location filter when using the LinkedIn Voyager API?
<p>I'm trying to scrape LinkedIn job postings using the Voyager API, adapting code from <a href="https://github.com/ArshKA/LinkedIn-Job-Scraper" rel="nofollow noreferrer">here</a>. Here's the relevant portion of the code:</p> <pre><code>class JobSearchRetriever: def __init__(self): self.job_search_link = 'h...
<python><web-scraping><linkedin-api>
2024-07-09 18:08:53
1
2,095
perigon
78,727,123
3,107,798
Size of pyarrow Table in bytes
<p>I have a basic <a href="https://arrow.apache.org/docs/python/generated/pyarrow.Table.html#" rel="nofollow noreferrer">pyarrow.Table</a>. What's the best way to get it's size in bytes?</p> <p>Here is an example table:</p> <pre><code>import pyarrow as pa n_legs = pa.array([2, 4, 5, 100]) animals = pa.array([&quot;Fla...
<python><pyarrow><apache-arrow>
2024-07-09 18:01:07
1
11,245
jjbskir
78,726,982
2,152,371
Coinbase Advance Trading API returns "Error: account not available" when placing orders
<p>For the past while I have been trying to get this crypto trading bot to work. The problem is that while I can get/list accounts when I place an order I get a 400 error.</p> <p>The code:</p> <pre><code>def place_order(symbol, side, amount, price=None): url = 'https://api.coinbase.com/api/v3/brokerage/orders' ...
<python><rest><cryptocurrency><http-status-code-400><coinbase-api>
2024-07-09 17:24:42
1
470
Miko
78,726,975
11,628,437
How do I log observations after reset in Stable_Baselines3?
<p>I want to log each <code>observation</code> obtained after <code>reset</code> during training, while using SB3.</p> <p>Based on <a href="https://github.com/DLR-RM/stable-baselines3/issues/137#issuecomment-669862467" rel="nofollow noreferrer">this</a> issue message, I decided to use the <code>Monitor</code> wrapper i...
<python><reinforcement-learning><openai-gym><stable-baselines>
2024-07-09 17:22:57
1
1,851
desert_ranger
78,726,881
11,318,930
holoviews how to set margin around a layout
<p>Using <code>holoviews</code> with the <code>plotly</code> extension, I am rendering a layout with several <code>overlay</code> plots. Each plot has a 4 line title. Unfortunately, the result clips the title from 4 lines to two. It feels like I need to set margins but doing so does not seem to help. How can I make ...
<python><plotly><holoviews>
2024-07-09 16:59:31
0
1,287
MikeB2019x
78,726,750
10,721,627
How can I install packages using `uv pip install` without creating a virtual environment in CI/CD pipeline?
<p>I would like to install Python packages in the CI/CD pipeline using the <a href="https://github.com/astral-sh/uv" rel="nofollow noreferrer">uv</a> package manager. I did not create a virtual environment because I would like to use the virtual machine's global Python interpreter. When I run the <code>uv pip install &...
<python><pip><continuous-integration><uv>
2024-07-09 16:28:42
1
2,482
PΓ©ter SzilvΓ‘si
78,726,599
8,554,833
SQL FetchMany in the middle
<p>So I'm fetching data from large tables. I'm using fetchmany to get 100,000 rows at a time. However, during my export, I will occasionally get a network disconnect, or need to stop the process for one reason or another.</p> <p>I was wondering if there is a way to perform a fetchmany after a certain point. For instanc...
<python><sql>
2024-07-09 15:52:30
0
728
David 54321
78,726,520
11,402,025
Swagger API : should not accept Null
<p>I have added the following to the swagger definition for the api.</p> <pre><code>value : BooleanEnum = Query ( False, alias=&quot;value&quot;) class BooleanEnum(str, Enum): true = &quot;true&quot; false = &quot;false&quot; @classmethod def _missing_(cls, value): return cls.__members__.get(va...
<python><swagger><fastapi><swagger-ui><pydantic>
2024-07-09 15:33:27
1
1,712
Tanu
78,726,485
8,964,393
How to convert a python character to a python object
<p>I have the following python lists</p> <pre><code>import pandas as pd import numpy as np listOfChars = ['feature1','feature2'] listOfBins = [[0,1,2],[15,20,30]] </code></pre> <p>I need to define each of the elements in <code>listOfChars</code> and assign them the correspondent <code>listOfBins</code> element.</p> <p...
<python><list><function><assign>
2024-07-09 15:25:46
2
1,762
Giampaolo Levorato
78,726,475
674,039
How can I ignore a specific breakpoint interactively?
<p>Consider this script:</p> <pre><code>print(&quot;before loop&quot;) for i in range(100): breakpoint() print(&quot;after loop&quot;) breakpoint() print(&quot;exit&quot;) </code></pre> <p>Short of pressing &quot;c&quot; one hundred times, how can you get past the breakpoint within the loop at L3 and proceed to L5?...
<python><pdb>
2024-07-09 15:24:12
3
367,866
wim
78,726,212
6,104,011
Can you order the execution of all expanded jobs in single rule?
<p>I have a snakemake pipeline that runs a genetic analysis. The genome has been split into many 'regions'. These regions can run in parallel, and therefore I've used <code>expand()</code>, and they all run as expected.</p> <pre><code>regions = ['r1', 'r2', 'r3', 'r4'] some_pattern = {region}/file.tsv rule all: i...
<python><snakemake>
2024-07-09 14:30:20
2
1,064
iquestionshard
78,726,188
8,037,521
Simultaneous matplotlib and open3d visualization
<p>I am looking for a way to simultaneously visualize two simple interfaces that I have for 3d (point cloud) and 2d (photo) data visualization. One is with tkinter and matplotlib, and another with open3d. Separately or sequentially they work without any issues. However, I want user to be able to have them side-by-side ...
<python><multithreading><matplotlib><open3d>
2024-07-09 14:24:35
0
1,277
Valeria
78,726,092
1,883,154
ValueError: Appended dtypes differ when appending two simple tables with dask
<p>I am using Dask to write multiple very large dataframes to a single parquet dataset in python.</p> <p>The dataframes are simple and all the column types are either floats or strings.</p> <p>I iterate over the dask dataframes, and call <code>to_parquet</code> on each one, overwritting if this is the first dataframe, ...
<python><dask><parquet>
2024-07-09 14:06:40
0
1,738
Ian Sudbery
78,726,032
3,368,980
Detecting DRM encrypted files
<p>My company uses DRM software (NASCA) for file encryption/protection that is hooked deep into the OS. I'd like to detect whether a file has been encrypted or not, in Python.</p> <p>An easy way would be checking for whether the file begins with <code>&lt;## NASCA DRM FILE - VER1.00 ##&gt;</code> as all of our encrypte...
<python><encryption>
2024-07-09 13:56:16
0
441
Abstracted
78,725,967
7,775,166
Translate Pandas groupby plus resample to Polars in Python
<p>I have this code that generates a toy DataFrame (production df is much complex):</p> <pre><code>import polars as pl import numpy as np import pandas as pd def create_timeseries_df(num_rows): date_rng = pd.date_range(start='1/1/2020', end='1/01/2021', freq='T') data = { 'date': np.random.choice(date_...
<python><dataframe><group-by><python-polars>
2024-07-09 13:42:48
1
732
girdeux
78,725,930
6,622,697
How to validate an enum in Django using serializers
<p>I'm using serializers to validate my Post data. How can I validate an Enum?</p> <p>I have a class like this:</p> <pre><code>class DataTypeEnum(StrEnum): FLOAT = 'float' INTEGER = 'integer' BOOLEAN = 'boolean' </code></pre> <p>And my Post input contains</p> <pre><code>{ ... &quot;value&quot; : &lt;data...
<python><django><validation><django-rest-framework>
2024-07-09 13:36:20
1
1,348
Peter Kronenberg
78,725,809
19,067,218
How to hide the __init__.py in every directory
<p>I have a repo filled with lots of nested directories; in almost everyone, I have a <code>__init__.py</code> file. The problem is it makes it harder to visually search directories for the files, and it was noticeable when the directory only contained 1 Python code file alongside <code>__init__.py</code></p> <p>So my...
<python><configuration><pycharm><ide><init>
2024-07-09 13:10:03
1
344
llRub3Nll
78,725,722
2,767,937
Passing Additional Information in LangChain abatch Calls
<p>Given an <code>abatch</code> call for a LangChain chain, I need to pass additional information, beyond just the content, to the function so that this information is available in the callback, specifically in the <code>on_chat_model_start</code> method.</p> <p>Here is the code:</p> <pre class="lang-py prettyprint-ove...
<python><langchain><large-language-model>
2024-07-09 12:53:53
0
629
TantrixRobotBoy
78,725,603
20,920,790
How to get requirements from my Airflow python environment
<p>How to perform pip freeze &gt; requirements.txt for Airflow environment? Or get list of packages by another way.</p> <p>Airflow v. 2.8.2 installed with Docker.</p>
<python><airflow>
2024-07-09 12:29:41
1
402
John Doe
78,725,262
4,277,485
Convert TSV file data to a dataframe, which can be pushed to database
<p>We have TSV files which holds IOT data, want to convert to table like structure using pandas. I have worked on TSV data, similar to given below, were the logics goes like</p> <ol> <li>read the file</li> <li>Add new column names</li> <li>do transpose</li> <li>reindex</li> </ol> <p>This is bit challenging as explained...
<python><pandas><csv><file>
2024-07-09 11:16:24
1
438
Kavya shree
78,725,115
1,824,064
Is there a way to toggle develop mode for path dependencies during install?
<p>I have a project that depends upon local libraries, which are installed as path dependencies in edit mode:</p> <pre><code>mylib = {path=&quot;../../libs/mylib&quot;, develop=true} </code></pre> <p>This is what I want during development so that library changes are immediately reflected in the project. What is the pro...
<python><python-poetry>
2024-07-09 10:39:37
1
1,998
amnesia
78,724,819
1,838,076
How can I redirect stdout and stderr of subprocess in python to same file without losing the order
<p>I have a simple script to mimic a program writing to stdout and stderr streams interleaved.</p> <pre><code>import sys import time for i in range(5): print(int(time.time()), &quot;This is Stdout&quot;) print(int(time.time()), &quot;Stderr&quot;, file=sys.stderr) time.sleep(1) </code></pre> <p>When I run ...
<python><subprocess>
2024-07-09 09:35:42
1
1,622
Krishna
78,724,742
956,539
Speed-up literal_eval in a DataFrame apply
<p>I have a <code>pandas</code> DataFrame with the following columns:</p> <pre><code>id | value | somedate ------------------------------ 1 | [10, 13, 14] | 2024-06-01 2 | [5, 6, 7] | 2024-07-01 3 | [1, 2, 3] | 2024-06-01 </code></pre> <p>I'm doing the following transformation to parse the <code>value</...
<python><pandas><dataframe>
2024-07-09 09:20:35
2
2,891
abudis
78,724,741
447,426
How format doc within :param <name>: in reStructuredText markup?
<p>I am trying to document certain <code>:param</code> and want to give examples like</p> <pre><code> :param mapper_matrix: lookup table with columns ref_col, ref_col_2 and value.\n |**Example:** | [(&quot;s1&quot;, &quot;p1&quot;, &quot;state1&quot;), | (&quot;s1&quot;,...
<python><restructuredtext><pydoc>
2024-07-09 09:20:32
1
13,125
dermoritz
78,724,606
1,982,032
How can calculate the American put option's vega,rho?
<p>The QuantLib's version in my os:</p> <pre><code>import QuantLib as ql ql.__version__ '1.34' </code></pre> <p>All the arguments related to the put option:</p> <pre><code>settlementDate = ql.Date(11, ql.July, 2019) maturity = ql.Date(19, ql.July, 2019) stock = 0.28 strike = 0.5 riskFreeRate = 0.05 volatility = 1.7 </c...
<python><quantlib>
2024-07-09 08:55:07
1
355
showkey
78,724,558
5,269,892
Pandas alignment error during elementwise comparison
<p>When checking element-wise equality of multiple columns of a dataframe against a single column, pandas raises a <code>ValueError: Operands are not aligned. Do 'left, right = left.align(right, axis=1, copy=False)' before operating.</code>.</p> <pre><code>import pandas as pd df1 = pd.DataFrame({ 'A': [1, 2, 3, 4,...
<python><pandas><comparison>
2024-07-09 08:42:38
2
1,314
silence_of_the_lambdas
78,724,345
6,930,340
Extending the Polars API for both DataFrame and LazyFrame
<p>I am extending the <code>polars</code> DataFrame and LazyFrame as described in the <a href="https://docs.pola.rs/api/python/stable/reference/api.html" rel="nofollow noreferrer">docs</a>.</p> <p>Let's go with their <code>split</code> example for <code>pl.DataFrame</code>. Let's say I also wanted to extend the <code>p...
<python><python-polars>
2024-07-09 07:52:16
1
5,167
Andi
78,724,330
893,254
VS Code + pytest - How to move the whole project to a subdirectory?
<p>I have an existing Python project which looks like this:</p> <pre><code>.venv/ ... example_package/ __init__.py tests/ test_example_package.py </code></pre> <p>Imagine that I worked on this project for a while and then decided to add a frontend to some kind of web service using React.</p> <p>I created a ...
<python><visual-studio-code><pytest>
2024-07-09 07:49:47
1
18,579
user2138149
78,724,252
1,838,076
Why concatenation can't handle Nones in categorical columns when the DF can hold it in the first place
<p>I have 2 DFs with <code>object</code> type columns, which work fine with concatenation.</p> <h3>Code</h3> <pre class="lang-py prettyprint-override"><code>df1 = pd.DataFrame({'A': ['A0', 'A1'], 'B': ['B0', None]}) df2 = pd.DataFrame({'A': ['A4', 'A5'], 'B': [None, None]}) print(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;...
<python><pandas><dataframe><categorical-data>
2024-07-09 07:32:42
1
1,622
Krishna
78,724,178
3,581,875
URL Fragment Encoding - Dollar? [AWS]
<p>What is the standard way to encode the fragment portion of a URL? (after the <code>#</code> symbol)</p> <p>I noticed that on AWS CloudWatch for example, percent characters (<code>%</code>) in the fragment portion are encoded as '$25', so you'd see something like this:</p> <pre><code>.../home?region=us-west-1#logsV2:...
<python><amazon-web-services><url><encoding>
2024-07-09 07:16:07
0
1,152
giladrv
78,723,898
10,426,490
How to determine the text responsible for Google Gemini `block_reason: OTHER`?
<p>I've spent a long time setting up Google Gemini. Now that I've:</p> <ul> <li>Setup a Google Workspace</li> <li>Connected a GCP Billing Account (If you don't do this, you'll receive <code>Status 429 exceeds quota</code>(?))</li> <li>Ect.</li> </ul> <p>Anyway, I can now send API requests. These requests contain very l...
<python><google-gemini><google-generativeai>
2024-07-09 06:07:35
1
2,046
ericOnline
78,723,649
20,087,266
How to set the default colour of a PyQtGraph ImageView's Histogram LUT?
<p>PyQtGraph's <a href="https://pyqtgraph.readthedocs.io/en/latest/api_reference/widgets/imageview.html" rel="nofollow noreferrer">ImageView</a> widget includes a histogram with:</p> <ol> <li>a moveable region that defines dark and light levels. as well as</li> <li>the ability to edit a colour gradient.</li> </ol> <p>T...
<python><image><user-interface><pyqt><pyqtgraph>
2024-07-09 04:11:32
1
4,086
Kyle F. Hartzenberg
78,723,533
1,942,868
push reload or invoke javascript function from server
<p>I have Django + React + uwsgi application.</p> <p>Uwsgi access to the database.</p> <p>Now I want to reload Django(React) web applicataion triggered by Database is changed.</p> <p>For example</p> <ol> <li>User open the web application</li> <li>Administrator use mysql command on server <code>Insert into mytable(name)...
<javascript><python><django>
2024-07-09 03:05:50
0
12,599
whitebear
78,723,313
1,636,016
Variables set inside the rcfile are NOT accessible through Python
<p>I've a shell script and a python script organized as follows (<strong>CAN NOT</strong> change the directory structure):</p> <pre class="lang-none prettyprint-override"><code>~ β”œβ”€β”€ a.py β”œβ”€β”€ b └── c.sh </code></pre> <p>The MWEs are as follows:</p> <p><code>c.sh</code></p> <pre class="lang-bash prettyprint-override...
<python><subprocess><sh><subshell>
2024-07-09 01:09:52
2
563
dibyendu
78,723,116
3,486,684
Python + Polars: efficiently looking up a value in another DataFrame: replace or join?
<p><strong>Note to potential editors:</strong> please leave both &quot;Python&quot; and &quot;Polars&quot; in the question title, because:</p> <ul> <li>there are many questions about looking up values in another dataframe in the <code>pandas</code> context;</li> <li>not everyone (e.g. search engines, or beginners) know...
<python><python-polars>
2024-07-08 22:51:42
0
4,654
bzm3r
78,722,956
169,252
Python: await to read from socket OR shut down on event
<p>Given this function:</p> <pre><code>async def read_data(self, stream: UStreams) -&gt; None: while True: read_bytes = await stream.read(MAX) #handle the bytes </code></pre> <p>This however will keep the function running forever, of course.</p> <p>I'd like to have this function do this, but also ...
<python><asynchronous><async-await><python-trio>
2024-07-08 21:45:21
1
6,390
unsafe_where_true
78,722,955
2,478,983
child item is not using parent coordinates
<p>I have a problem with PySide coordinate system. I create a custom item (NodeItem) that inherits from QGraphicsRectItem and is positioned in the scene. This custom item has a child (LabelItem) that inherits from QGraphicsTextItem. When I add the parent item (NodeItem) to the scene is positioned in 150,150 in scene co...
<python><pyside6>
2024-07-08 21:44:57
1
370
Carlitos_30
78,722,940
17,556,733
How do I create and freely delete parts of a black layer with python and tkinter
<p>Using python and the tkinter library, I want to create a program that will open an image, then draw a completely black layer on top of it, and using mouse click + movement, delete parts of that black layer (think of it as a fog-of-war in a table top game) or restore parts of the black layer.</p> <p>When I want to de...
<python><tkinter><optimization><canvas><layer>
2024-07-08 21:40:13
1
495
TheMemeMachine
78,722,914
14,336,726
An ordinary numpy array produces a type error?
<p>Could someone explain why I get this warning</p> <pre><code>&lt;&gt;:18: SyntaxWarning: list indices must be integers or slices, not tuple; perhaps you missed a comma? </code></pre> <p>and this error message</p> <pre><code>TypeError Traceback (most recent call last) Cell In[62], line ...
<python><arrays><numpy>
2024-07-08 21:30:32
1
480
Espejito
78,722,890
14,301,911
Where can I find an exhaustive list of actions for spark?
<p>I want to know exactly what I can do in spark without triggering the computation of the spark RDD/DataFrame.</p> <p>It's my understanding that only actions trigger the execution of the transformations in order to produce a DataFrame. The problem is that I'm unable to find a comprehensive list of spark actions.</p> <...
<python><dataframe><apache-spark><pyspark>
2024-07-08 21:20:53
2
504
HappilyCoding
78,722,888
9,097,114
Python sendgrid - Concat/Add a string to HTML_CONTENT
<p>i Am trying to add a string to thml content and out that i am getting is not as required<br /> 'str1' should be added in place of str1 to 'Attached is the report of your data - +str1'</p> <pre><code>str1= 'StringToBeAdded' html_content1 = ''' Hi All, &lt;br&gt; &lt;br&gt; Greetings from xyz! ...
<python><sendgrid>
2024-07-08 21:19:59
1
523
san1
78,722,881
9,363,181
Collect values as dictionary in parent column using Pyspark
<p>I have code and data like below:</p> <pre><code>df_renamed = df.withColumnRenamed(&quot;id&quot;,&quot;steps.id&quot;).withColumnRenamed(&quot;status_1&quot;,&quot;steps.status&quot;).withColumnRenamed(&quot;severity&quot;,&quot;steps.error.severity&quot;) df_renamed.show(truncate=False) +----------+-------+------...
<python><python-3.x><dictionary><apache-spark><pyspark>
2024-07-08 21:16:46
2
645
RushHour
78,722,524
2,700,344
pyvis - How to make nodes IDs selectable (to copy into buffer) in browser
<p>This code generates HTML files with sub-graphs. The problem is that it is not possible to copy some node ID from HTML page to be able to paste it into some other tool.</p> <pre><code>G = nx.from_pandas_edgelist(df, source='fromKey', target='toKey', create_usin...
<python><networkx><pyvis>
2024-07-08 19:03:40
1
38,483
leftjoin