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,052,782
21,935,028
Antlr4 python runtime error after generating from grammar
<p>I using the following Antlr4 PLSQL grammar files:</p> <p><a href="https://github.com/antlr/grammars-v4/tree/master/sql/plsql" rel="nofollow noreferrer">https://github.com/antlr/grammars-v4/tree/master/sql/plsql</a>.</p> <p>From here I downloaded as follows:</p> <pre><code>wget https://github.com/antlr/grammars-v4/bl...
<python><antlr4>
2024-02-24 14:24:23
1
419
Pro West
78,052,710
6,239,096
How to pass a variable value in SSIS to Python Script : Execute Process task
<p>I've a execute process task which executes python Script<a href="https://i.sstatic.net/n0qzu.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/n0qzu.png" alt="enter image description here" /></a></p> <p><a href="https://i.sstatic.net/YDWK0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Y...
<python><ssis><sql-server-data-tools><ssis-2012><msbi>
2024-02-24 14:01:12
1
844
sai bharath
78,052,703
11,049,863
How to automatically scroll (autoscroll) a list of images contained in a list with tkinter
<p>My job is to automatically display, one by one, the pages of a pdf file with tkinter. To do this, I create an image for each page and store all the images in a list. I can display all the pages from my list with manual scrolling. But I want it to be automatic (autoscroll). How can I proceed?<br/> Here is my code:</p...
<python><tkinter><autoscroll>
2024-02-24 13:59:00
1
385
leauradmin
78,052,641
11,861,874
Tkinter Output of Function as Table and Graph
<p>I have two functions that produce two types of output one is a data frame table and the other is a plot of that dataframe. All functions take one file as input. which we load from the previous tkinter function. I would like to dynamically select a function from the radio box, next, once we select a particular functi...
<python><tkinter>
2024-02-24 13:40:31
1
645
Add
78,052,611
10,470,463
How to get the text of the email body?
<p>I have this code but I don't actually get the email text.</p> <p>Have I got to decode the email text?</p> <pre><code>import sys import imaplib import getpass import email import email.header from email.header import decode_header import base64 def read(username, password, sender_of_interest): # Login to INBOX ...
<python><email><mime>
2024-02-24 13:31:00
2
511
Pedroski
78,052,486
3,995,261
How do I make the type of a dictionary inferred from its value in Python?
<p>Consider this simple config:</p> <pre><code>config = { 'sentry': { 'endpoint': '...', 'server_name': '...', }, } </code></pre> <p>let's imagine that it's in fact big (tens of keys on different levels). I'm looking for a way to &quot;infer&quot; the type of config to achieve 3 goals:</p> <ol> ...
<python><python-typing>
2024-02-24 12:55:14
0
8,448
YakovL
78,052,480
8,484,261
Filling up a pandas pivot table with missing columns for months and adding month column headers
<p>I am pivoting a dataframe to get it into long form. The data is by month and year. But not all months are present.</p> <ol> <li>How do I add the columns for the missing months and fill those with ZERO?</li> <li>How do I merge the top two column identifiers (Year and Month) into one Date identifier for the month?</li...
<python><pandas><dataframe><pivot-table><multi-index>
2024-02-24 12:53:47
1
3,700
Alhpa Delta
78,052,441
5,615,873
What is the difference between cv2.waitKey() and cv2.waitKey(0)?
<p>I have found a lot of questions around about what is <code>cv2.waitKey()</code> used for, about the difference between <code>cv2.waitKey(0)</code> and <code>cv2.waitKey(1)</code>, etc., the answers to which can be found in many OpenCV documentations. Yet, I have not found any documentation or people asking about the...
<python><opencv>
2024-02-24 12:42:37
1
3,537
Apostolos
78,052,412
21,935,028
Antlr4 PLSQL Errors
<p>I'm trying to test the Antlr4 (Oracle) PLSQL grammar, but really struggling. I might have confused things by having followed 2 or 3 different guides.</p> <p>I performed the following steps, starting with installation, on Ubuntu 22.04.</p> <p>Install packages, but not sure I ended up using these:</p> <pre><code>sudo ...
<python><parsing><plsql><antlr4>
2024-02-24 12:34:31
1
419
Pro West
78,052,404
13,517,174
unreachable network error when establishing a bluetooth connection between raspberrypi and laptop
<p>I have a c++ script, which I am running on my raspberry pi to automatically connect to a device that attempts connection and receives arrays of the fixed size 8:</p> <pre><code>#include &lt;iostream&gt; #include &lt;unistd.h&gt; #include &lt;sys/socket.h&gt; #include &lt;bluetooth/bluetooth.h&gt; #include &lt;blueto...
<python><c++><raspberry-pi><bluetooth><network-programming>
2024-02-24 12:32:21
1
453
Yes
78,052,180
893,254
What are the differences between AbstractEventLoop.create_server and asyncio.start_server?
<p>I am trying to understand the differences between</p> <ul> <li><code>AbstractEventLoop.create_server()</code></li> <li><code>asyncio.start_server()</code></li> </ul> <p>and why one might choose one of these options over the other.</p> <p>The relevant documentation pages can be found</p> <ul> <li>for <code>AbstractEv...
<python><python-asyncio>
2024-02-24 11:14:17
1
18,579
user2138149
78,052,149
1,608,765
Identify lines in spectrogram using python
<p>I have a long strip of data with some lines in it that are visually very clear (both blue and red), however, I can't seem to be able to identify them versus the background.</p> <p>I've tried to average the array in in the time direction, run that through a low pass filter and then identify the peaks. But it does not...
<python><signal-processing><spectrum>
2024-02-24 11:06:05
0
2,723
Coolcrab
78,052,124
3,018,893
Running the next step of a generator in a separate process
<p>How would it be possible to resume a generator in another process.</p> <p>Assume the following:</p> <ol> <li>The processes have access to the same code</li> <li>The scope should propogate between iterations</li> <li>If necessary modify the python interpreter itself</li> </ol> <p>An example of the kind of generator</...
<python>
2024-02-24 10:57:06
0
520
Jack burridge
78,051,902
12,129,443
Why I am unable to import trl package in Jupyter?
<p>I am trying to import <code>SFTTrainer</code> from <code>trl</code> package. I am getting the error message - <code>ImportError: cannot import name 'override' from 'typing_extensions' (D:\...\..\)</code>. <strong>I am able to do it perfectly well in Google Colab, no issues</strong>. Why is this? How can I import on ...
<python><machine-learning><jupyter-notebook><huggingface-trainer><nltk-trainer>
2024-02-24 09:46:41
1
668
Srinivas
78,051,606
3,067,485
Cannot reproduce a bifurcation diagram from article
<p>I have been reading this article <a href="https://www.researchgate.net/publication/348791076_A_Simple_Guide_for_Plotting_a_Proper_Bifurcation_Diagram" rel="nofollow noreferrer">A Simple Guide for Plotting a Proper Bifurcation Diagram</a> and I want to reproduce the following figure (Fig. 10, p. 2150011-7):</p> <p><a...
<python><ode>
2024-02-24 07:51:44
1
11,564
jlandercy
78,051,555
14,298,525
Python + Falcon + OpenTelemetry: Not sending traces to OTEL Collector
<p>I am trying to instrument my Falcon app to send traces to OTEL Collector. I am doing auto-instrument via launch command and then trying to send traces like the following:</p> <blockquote> <p>OTEL_RESOURCE_ATTRIBUTES=service.name=terminus OTEL_EXPORTER_OTLP_TRACES_ENDPOINT='http://otel-collector:4317' OTEL_EXPORTER_O...
<python><open-telemetry><falcon>
2024-02-24 07:32:09
0
341
mifol68042
78,051,321
9,211,026
Python NSSM commands packaged in .exe
<p>I have an app that I built with customtkinter. It needs to configure a file and install a python script as a service. That service reads from the config file. It works when I run it from pycharm but when I use auto_py_to_exe the service fails to start with error code 3.</p> <p>my code runs the following command to i...
<python><auto-py-to-exe><nssm>
2024-02-24 05:40:15
1
2,152
cmrussell
78,051,188
5,695,336
Will slice then append back to the same shape increase memory usage?
<pre><code>x = np.random.rand(3, 4) x = x[1:] x = np.append(x, np.random.rand(1, 4), axis=0) </code></pre> <p>The second line creates a new view of the original data, so no memory change. My question is that will the third line increase memory usage?</p> <p>If <code>append</code> copies the original data, regardless of...
<python><numpy>
2024-02-24 04:11:57
1
2,017
Jeffrey Chen
78,051,181
308,827
Cannot get a constant when using statsmodels add_constant
<p>I have the following python code using statsmodels:</p> <pre><code>import numpy as np import statsmodels.api as sm # Assuming future_time_points is an array like this future_time_points = np.array([2010]) # Stacking future_time_points and its square stacked_array = np.column_stack((future_time_points, future_time_...
<python><statsmodels>
2024-02-24 04:06:07
1
22,341
user308827
78,050,943
13,174,189
How to return Document that was used to answer a question using i am using RetrievalQA?
<p>I am using python and langchain RetrievalQA for RAG. Here is sample of code that i have written:</p> <pre><code>loader = UnstructuredPDFLoader(filename, mode=&quot;elements&quot;) data = loader.load() text_splitter = RecursiveCharacterTextSplitter(chunk_size = 300, chunk_overlap = 0) splits = text_splitter.split_doc...
<python><python-3.x><nlp><artificial-intelligence><langchain>
2024-02-24 01:22:37
1
1,199
french_fries
78,050,933
7,658,985
Solving Hcaptcha using 2captcha to automate website search (Python)
<p>I'm trying to automate a web search via Python.</p> <p>The website is behind <code>hCaptcha</code> but I'm using a <code>2captcha</code> solver.</p> <p>Although, I've replicated web browser's behavior, I'm still being asked to solve the <code>hCaptcha</code> again.</p> <p>Here's what I've tried:</p> <pre class="lang...
<python><beautifulsoup><python-requests><httpx><2captcha>
2024-02-24 01:17:41
1
11,557
αԋɱҽԃ αмєяιcαη
78,050,884
4,744,396
how to iterate through each element of a unknown length of list while passed as argument to a function in python?
<p>how can i modify the tab function to print the element 'c'?</p> <pre><code> def tab(data): for i, v in enumerate(data): print(i, v[0], v[1]) tab([['a', 'b']]) tab([['a', 'b', 'c']]) </code></pre> <p>Result:</p> <pre><code>$ python3 tabulate2.py 0 a b 0 a b </code></pre>
<python><list>
2024-02-24 00:52:16
2
437
chetan honnavile
78,050,843
8,484,261
Using Pivot Table to reshape data in pandas so that multiple value appear below with their own lines
<p>I have a dataframe that I am trying to pivot to get into long form. The executable code is below. But the output is not coming out the way I want it. I want the Amount and Quantity to be coming one below the other</p> <pre><code>import pandas as pd import numpy as np df = pd.DataFrame({ 'Year':[2022,2022,20...
<python><pandas><pivot><pivot-table>
2024-02-24 00:34:32
1
3,700
Alhpa Delta
78,050,753
7,751,438
ModuleNotFoundError: No module named 'pybind11_tests'
<p>When running the <code>pytest</code> command at the root path of my project, I encounter this error. Since there are no SO question on how to solve this issue, I will provide an answer to my own question for others to benefit. Please see answer below.</p>
<python><pybind11>
2024-02-23 23:55:37
1
806
jsibs
78,050,752
1,609,514
How to write a function that works on both Numpy arrays and Pandas series, returning the same type
<p>A feature of some numpy functions is that they work on both arrays and Pandas series:</p> <pre class="lang-python prettyprint-override"><code>my_series = pd.Series([10, 20, 30], index=([2000, 2001, 2002]), name='My series') my_array = np.array([10, 20, 30]) print(np.cumsum(my_series)) print(np.cumsum(my_array)) </c...
<python><pandas><numpy><duck-typing>
2024-02-23 23:55:26
1
11,755
Bill
78,050,698
4,119,262
Python "While" calculation returns absurd / random amounts for each new inputs
<p>I am trying to learn Python. I am hence working on an exercise, where a user inputs a number, and until the sum of numbers inputted is not reaching a given total, the user is told the missing amount (or the amount given / paid &quot;in excess).</p> <p>I have the following code:</p> <pre><code>amount_given = int(inpu...
<python><while-loop><sum>
2024-02-23 23:32:14
1
447
Elvino Michel
78,050,640
1,802,225
Web3py: can not find ABI function after decoded
<p>Here is transaction <a href="https://etherscan.io/tx/0x6465187a7bb43a6db42ee63e5f5cc30fb094393957a7f1ce6c08b5afddf3e0bc" rel="nofollow noreferrer">https://etherscan.io/tx/0x6465187a7bb43a6db42ee63e5f5cc30fb094393957a7f1ce6c08b5afddf3e0bc</a></p> <p>I don't know why my script can not find ABI Transfer() function afte...
<python><ethereum><solidity><smartcontracts><web3py>
2024-02-23 23:13:07
1
1,770
sirjay
78,050,623
5,978,130
create virtual conda env from yaml file on macOs
<p>I have a macOS Ventura 13.6.4 MacBook Pro. I have installed python 3.11.5 using the anaconda installer for macOs. I am trying to create a conda virtual python environment from a yaml file. The script I'm running in the terminal is below, along with the yaml file and the error message I'm getting. Can you please ...
<python><anaconda>
2024-02-23 23:08:04
1
573
modLmakur
78,050,591
1,654,472
Inconsistent processing of the form-data POST with multiple files
<p>I have a script in python to test posting multiple files to a certain end point. Here is the script:</p> <pre><code>import requests url = &quot;https://endpoint.com/api/upload&quot; payload = {} files=[ ('images',('image01.png',open('H:/image01.png','rb'),'image/png')), ('images',('image02.png',open('H:/image02....
<python><rest><python-requests>
2024-02-23 22:58:46
0
731
GeekSince1982
78,050,439
12,415,855
Selenium undetected chromedriver with different chrome-versions?
<p>I have the following code which works fine on a computer where chrome 122 is installed currently -</p> <pre><code>import undetected_chromedriver as uc driver = uc.Chrome() driver.get('https://ballzy.eu/en/men/sport/shoes') </code></pre> <p>But when I run this code on a computer where a different chrome-version is i...
<python><python-3.x><selenium-webdriver><selenium-chromedriver><undetected-chromedriver>
2024-02-23 22:16:19
3
1,515
Rapid1898
78,050,189
13,086,128
`df.query()` in polars?
<p>What is the equivalent of <strong><a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html#pandas-dataframe-query" rel="noreferrer">pandas.DataFrame.query</a></strong> in polars?</p> <pre><code>import pandas as pd data= { 'A':[&quot;Polars&quot;,&quot;Python&quot;,&quot;Pandas&quot;], ...
<python><python-3.x><dataframe><python-polars>
2024-02-23 21:04:07
1
30,560
Talha Tayyab
78,050,174
2,030,762
Bin packing in OR-Tools with only one bin
<p>I've been trying to adapt the bin-packing problem often seen in OR-Tools to optimize space used instead of optimizing number of bins, but I don't seem to be able to sort out how to do it.</p> <p>So what I want to do is something like:</p> <p>Given a set of 2D boxes of various sizes, and an arbitrarily long 2D contai...
<python><or-tools><constraint-programming><cp-sat>
2024-02-23 21:01:46
1
776
emote_control
78,050,169
2,035,671
Supabase with JWT auth from Python client doesn't work with RLS
<p>I have a problem with Supabase that is related to RLS.</p> <p>In my Python backend, I set up the supabase client and get the user based on the JWT <code>jwt</code> passed by the frontend:</p> <pre class="lang-py prettyprint-override"><code>user = supabase.auth.get_user(jwt) user_id = user.dict().get(&quot;user&quot;...
<python><next.js><jwt><supabase><supabase-py>
2024-02-23 20:59:57
2
490
shredEngineer
78,050,162
5,923,866
Pyspark Group By Date Range
<p>I have a sample pyspark dataframe that can be created like this</p> <pre><code>sample_df = spark.createDataFrame([ ('2020-01-01', '2021-01-01', 1), ('2020-02-01', '2021-02-01', 1), ('2021-01-15', '2022-01-15', 2), ('2022-01-15', '2023-01-15', 2), ('2022-02-01', '2023-02-01', 3), ('2022-03-01'...
<python><pyspark><group-by>
2024-02-23 20:58:58
1
395
spatel4140
78,050,000
13,132,728
How to assign each item in a list an equal amount of items from another list in python
<p>Let's say I have a list of people</p> <pre><code>['foo','bar','baz'] </code></pre> <p>and a list of items</p> <pre><code>['hat','bag','ball','bat','shoe','stick','pie','phone'] </code></pre> <p>and I want to <em>randomly</em> assign each person an equal amount of items, like so</p> <pre><code>{ 'foo':['hat','bat','s...
<python><python-itertools>
2024-02-23 20:16:08
5
1,645
bismo
78,049,835
2,274,981
SQLite3 - Location of db
<p>I have implemented SQLite3 into my discord bot, everything seems to work and I can commit rows to my db, do a select and retrieve them, however in my local directory for the project I can't see the DB itself.</p> <p>I've tried looking for commands to log the location to my log file but nothing seems to work either.<...
<python><sqlite><sqlite3-python>
2024-02-23 19:39:15
1
1,149
Lynchie
78,049,782
7,938,796
How to make a lighter SciPy package for AWS Lambda
<p>AWS Lambda restricts packages to be less than 50MB zipped. I need to use <code>scipy</code> for my workflow which is a large package, so I'm trying to trim it down so I can use it within lambda without having to use container images or anything like that since I'm not as familiar with it. And lambda is the ideal sol...
<python><amazon-web-services><aws-lambda>
2024-02-23 19:26:40
1
767
CoolGuyHasChillDay
78,049,684
9,915,864
Python import problem: Why is my python code unexpectedly trying to import a module function?
<p>When I run my top-level file <code>downloader.py</code>, I'm getting an unexpected import error, unexpected since I thought the function is finished by the time <code>downloader.py</code> calls it. I'm not sure which file this is supposed to be resolved in. I'm running in VS Code and using the VS Code generated venv...
<python><python-import>
2024-02-23 19:07:48
1
341
Meghan M.
78,049,538
2,824,791
Failure to debug Python Functions using VSCode + WSL2 + Ubuntu 22.04
<p>Tools</p> <ul> <li>VSCode</li> <li>WSL2</li> <li>Ubuntu 22.04</li> <li>Python 3.10.12</li> </ul> <p>I am using the Code created when using Workspace/New Project... Project consistently fails with: <strong>ConnectionRefusedError: [Errno 111]</strong></p> <h3>Investigative information</h3> <p>I have tried everything I...
<python><azure-functions><windows-subsystem-for-linux><ubuntu-22.04><azure-functions-core-tools>
2024-02-23 18:37:10
1
5,096
jlo-gmail
78,049,416
3,778,976
How to test warnings with Pytest but exclude from summary report
<p>Pytest supports testing for warning messages with warns(). For example,</p> <p>auth.py:</p> <pre><code>import warnings def warn_for_plain_text_security(): warnings.warn(&quot;Notice: Credentials in the .rc file is deprecated&quot;) warn_for_plain_text_security() </code></pre> <p>test_auth.py:</p> <pre><code>...
<python><pytest>
2024-02-23 18:12:41
1
1,391
Brad Schoening
78,049,406
13,296,497
Pysark dataframe not filtering out rows when comparing two columns
<p>Example of my data</p> <pre><code> event_id | previous_plan | new_plan 1 | Null | 1mo 2 | Null | 1mo 3 | 1mo | 1mo 4 | 6mo | 6mo 5 | Null | 6mo 6 | 1mo | 6mo 7 | 6mo ...
<python><dataframe><pyspark>
2024-02-23 18:11:17
1
1,092
DSolei
78,049,161
4,704,065
Duplicate and incorrect legends
<p>I am creating a plot and have few issues:</p> <ol> <li>Legends are duplicated</li> <li>Legends are shown incorrectly on the left, instead of the right</li> <li>Same value of legend is shown incorrect for different values and colors</li> <li>Plots are overlapped</li> </ol> <ul> <li>I am plotting svIonoStdev vs ITow w...
<python><pandas><matplotlib>
2024-02-23 17:25:37
1
321
Kapil
78,049,053
6,447,399
QuantLib Call Options Pricing over rows in a data frame
<p>I have some data which looks like:</p> <pre><code>date call_open call_high call_low call_close put_open put_high put_low put_close stock_open stock_high stock_low stock_close stock_volume 0 2024-01-31 15:30:00 1.03 1.82 0.88 0.95 11.72 12.78 11.34 12.55 488.62 489.09 48...
<python><quantlib>
2024-02-23 17:05:23
0
7,189
user113156
78,048,953
22,212,435
Why don't ButtonPress and Button-1 execute together?
<p>So I wrote a very simple logic:</p> <pre><code>import tkinter as tk root = tk.Tk() root.bind('&lt;Button-1&gt;', lambda e: print('b-1'), add='+') root.bind('&lt;ButtonPress&gt;', lambda e: print('some button'), add='+') root.mainloop() </code></pre> <p>I expect that when I click &quot;<code>Button-1</code>&quot;, it...
<python><tkinter>
2024-02-23 16:52:43
1
610
Danya K
78,048,862
765,800
Dynamically add mixin to a class depends on attribute value in python
<p>I want to dynamically add a mixin class in an object without effecting any other objects of that class. I have an external service that determine which mixin should be used for a particular object.</p> <p>I am currently using a metaclass to dynamically add a base class to an object. But the issue is, if I change bas...
<python><inheritance><mixins>
2024-02-23 16:37:53
2
353
Ali Hasan Imam
78,048,750
1,711,271
In polars select all column ending with pattern and add new columns without pattern
<p>I have the following dataframe:</p> <pre class="lang-py prettyprint-override"><code>import polars as pl import numpy as np df = pl.DataFrame({ &quot;nrs&quot;: [1, 2, 3, None, 5], &quot;names_A0&quot;: [&quot;foo&quot;, &quot;ham&quot;, &quot;spam&quot;, &quot;egg&quot;, None], &quot;random_A0&quot;: np...
<python><dataframe><python-polars><calculated-columns>
2024-02-23 16:19:24
3
5,726
DeltaIV
78,048,718
8,831,116
Derive type hint for my_dict.items() for return type of function (Python)
<p>I have a definition of a frequently used type, <code>MyModel</code>. For various reasons, in some models I do not work on <code>MyModel</code> directly but on a stream of tuples of <code>key</code> and <code>value</code>. Currently I have to duplicate the type hints for these iterables.</p> <p>To give a brief exampl...
<python><mypy>
2024-02-23 16:14:05
0
858
Max Görner
78,048,681
1,711,271
Add a new column into an existing Polars dataframe
<p>I want to add a column <code>new_column</code> to an existing dataframe <code>df</code>. I <em>know</em> this looks like a duplicate of</p> <p><a href="https://stackoverflow.com/q/75720011/1711271">Add new column to polars DataFrame</a></p> <p>but the answer to that questions, as well as the answers to many similar...
<python><dataframe><python-polars>
2024-02-23 16:08:20
2
5,726
DeltaIV
78,048,653
11,609,834
How to hint Python function with an inplace argument?
<p>I have a function that takes and <code>inplace</code> argument. Following good practice, the function returns <code>None</code> if it modifies the input (<code>inplace=True</code>) and returns a copy of the input, modified, otherwise (<code>inplace=False</code>). (My preference now would be to just not have the <cod...
<python><python-typing>
2024-02-23 16:04:01
1
1,013
philosofool
78,048,639
12,423,732
VertexAI: RunName of Experiment
<p>Is it possible to get a list of runs for a given experiment using google.cloud.aiplatform?</p> <p>I've looked through the docs and can't see an obvious way to retrieve this.</p>
<python><google-cloud-vertex-ai>
2024-02-23 16:01:18
1
319
Iain MacCormick
78,048,603
4,269,851
Python calling function defined in __init__.py not working
<p>I created sub folder <code>module1</code> with just _<code>_init__.py</code></p> <pre><code>def print_hello(): print('Hello') __all__ = [&quot;print_hello&quot;] print('Init loaded') </code></pre> <p>inside <code>main.py</code> i have</p> <pre><code>import module1 print_hello() </code></pre> <p>Output as foll...
<python><module><init>
2024-02-23 15:55:33
1
829
Roman Toasov
78,048,552
14,751,182
How to retrieve the selected ALPN protocol from an asyncio stream?
<p>I am writing a HTTP client in Python. In order to select the correct HTTP version, I use ALPN.<br> While there is an easy and documented way to get the selected protocol from a ssl-wrapped socket (<code>SSLSocket.selected_alpn_protocol()</code>), I have found no official way to do this for <code>asyncio</code> strea...
<python><ssl><python-asyncio><alpn>
2024-02-23 15:47:46
1
604
Adam Jenča
78,048,327
3,751,711
AES simple encryption in Node and decryption in Python and vice versa
<p>I generate secretKey in nodejs as below,</p> <pre><code>const generateAesKey = () =&gt; { const { randomBytes } = require('node:crypto'); randomBytes(32, (err, buf) =&gt; { if (err) throw err; return buf.toString('hex'); }); } const secretKey = generateAesKey(); </code></pre> <p>Secret...
<javascript><python><node.js><encryption><aes>
2024-02-23 15:07:04
0
55,623
micronyks
78,048,307
3,433,875
Gradient color on broken barh plot in matplotlib
<p>I am trying to reproduce this: <a href="https://i.sstatic.net/pV6fi.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pV6fi.png" alt="enter image description here" /></a></p> <p>using this code:</p> <pre><code>import matplotlib.pyplot as plt import numpy as np import pandas as pd from matplotlib.lines i...
<python><matplotlib>
2024-02-23 15:04:14
2
363
ruthpozuelo
78,048,241
3,240,484
typing Protocol valid for Enumerator member
<p>What is the right typing to accept an Enumerator Type which should match a Protocol ? I mean the Enumerator should have members defined inside a Protocol</p> <p>Here is a simplified code exemple.</p> <pre class="lang-py prettyprint-override"><code>from typing import Protocol from enum import Enum class MyProto(P...
<python><enums><python-typing>
2024-02-23 14:57:17
1
314
user3240484
78,048,223
7,981,566
Adding folder with data with `pyproject.toml`
<p>I would like to package some legacy code to a <code>hello</code> <em>Python</em> package containing only one module (<code>hello.py</code>) file in the top-level directory alongside with some data in a folder called <code>my_data</code> without changing the folder structure:</p> <pre><code>hello/ |-hello.py |-pyproj...
<python><setuptools><python-packaging><pyproject.toml>
2024-02-23 14:54:09
3
1,059
NicolasBourbaki
78,048,149
3,768,497
No module named 'regression_testing.common' Python Sphinx
<p>Repo is like this, with 2 folders for &quot;individual modules&quot; <code>regression_testing_package</code> and <code>regressin_testing_common</code> but both share the same namespace <code>regression_testing</code> both are managed with their own poetry configuration and both have their own sphinx documentation co...
<python><python-sphinx>
2024-02-23 14:41:46
1
619
Karl
78,048,052
1,350,082
Setting grouped barplot colour based on the category and not the grouping used with hue in Seaborn
<p>I am trying to change how the colours are displayed when plotting a grouped barplot with seaborn.</p> <p>In the following minimal example,you get the output you would expect, the colour being set on the group. However, I want the colour to be set based on the category.</p> <pre><code>import pandas as pd import seabo...
<python><matplotlib><seaborn>
2024-02-23 14:25:07
1
317
speeder1987
78,048,004
7,959,614
Rewrite for-loop vectorized using Numpy
<p>I have the following code:</p> <pre><code>def obj(f, pis, rs): out = np.zeros(f.size) for pi, r in zip(pis, rs): out += r * pi / (1 + np.dot(r, f)) return out p = np.array([0.42, 0.08, 0.42, 0.08]) r = np.array([[-1.0, 7.0, -1.0, 0.4], [-1.0, 7.0, 0.5, -1.0], [0.2, ...
<python><numpy>
2024-02-23 14:16:45
2
406
HJA24
78,047,985
9,976,891
Tkinter scrollable frame cut off when adding horizontal scrollbar
<p>I'm modifying <a href="https://stackoverflow.com/a/47985165/9976891">this</a> example to add a horizontal scrollbar. I've looked at similar answers on SO but they don't help, which I'll explain further at the bottom of the question.</p> <p>Before adding the horizontal scrollbar, I added some code that instead of a s...
<python><user-interface><tkinter>
2024-02-23 14:14:07
2
425
GMSL
78,047,651
14,649,310
Celery task chain seems to only run first task. How does the Celery chain works?
<p>I have an issue which I believe relates to how this method works. I am creating a chain of lets say 300 pretty big tasks with a lot of items to be processed by each task. I create and async run a Celery task of this events like so:</p> <pre><code>result = chain(*my_tasks).apply_async(ignore_result=True) </code></pre...
<python><rabbitmq><celery>
2024-02-23 13:12:06
1
4,999
KZiovas
78,047,611
1,095,202
Debugging tips for CMake's failure to find Python (which is on $PATH)
<p>I have a Python virtual environment (<code>venv</code> in the project dir) activated, so that <code>which python</code> points to the Python interpreter in this environment. The environment also has NumPy installed.</p> <p>I also have a CMake build that should link a C library to this Python and the python is search...
<python><cmake>
2024-02-23 13:04:58
0
927
Dmitry Kabanov
78,047,287
4,865,723
PyLint --init-hook via subprocess.run() not working (maybe escape problems)
<p>I do run <code>pylint</code> in unittests using <code>subprocess.run()</code>. I need to use <code>--init-hook=</code> feature of <code>pylint</code> to encourage it to find my modules.</p> <p>I do run this on shell (bash) and it works as expected:</p> <pre><code>pylint qttools.py --disable=all --enable=E0401 --init...
<python><pylint>
2024-02-23 12:11:41
1
12,450
buhtz
78,047,278
4,269,851
Python transpose dictionary
<p>I have</p> <pre><code>data_dict = {1: {'One': 110, 'Two': 210, 'three': 310}, 2: {'One': 120, 'Two': 220, 'three': 320}, 3: {'One': 130, 'Two': 230, 'three': 330}} </code></pre> <p>need to print as CSV in this order</p> <pre><code>'',1,2,3 One,110,120,130 Two,210,220,230 Three,310,320,330 <...
<python><csv><dictionary><transpose>
2024-02-23 12:10:30
2
829
Roman Toasov
78,047,244
651,779
How to run piped command with Python subprocess without deadlocking?
<p>I have a python script that runs</p> <pre><code>for cmd in chr_commands: info(&quot;Run: &quot;+cmd) subprocess.run(cmd) </code></pre> <p>Where each cmd is equivalent to</p> <pre><code>samtools view -F 0x0004 input.bam chr3:0-500000 2&gt;&gt; log.txt |awk 'BEGIN {OFS=&quot;\t&quot;} {bpstart=$4; bpend=bpsta...
<python><subprocess><snakemake><singularity-container>
2024-02-23 12:04:24
0
8,854
Niek de Klein
78,047,164
11,749,309
Optimize assigning an index to groups of split data in Polars
<h1>SOLVED:</h1> <h3>Fastest Function: 995x faster than original function</h3> <pre class="lang-py prettyprint-override"><code>def add_range_index_stack2(data, range_str): range_str = _range_format(range_str) df_range_index = ( data.group_by_dynamic(index_column=&quot;date&quot;, every=range_str, by=&qu...
<python><dataframe><optimization><indexing><python-polars>
2024-02-23 11:48:46
2
373
JJ Fantini
78,047,106
3,362,720
In tox What is the difference between setenv, and passenv
<p>I setting up tox to be used in my <code>.gitlab-ci.yml</code> in combination with pytest. I want pytest to run with specific environment that are set in the .gitlab-ci.yml file</p> <p>In the documentation I found the <code>tox.ini</code> configurations <code>setenv</code> and <code>passenv</code> but I couldn't unde...
<python><pytest><gitlab-ci><tox>
2024-02-23 11:35:55
3
4,046
Ouss
78,047,017
13,461,081
Python package Expiring Dict is not working (automatic expiring)
<p>Using the following <a href="https://pypi.org/project/expiringdict/" rel="nofollow noreferrer">package</a> for expiring dictionaries doesn't work. Is there any known deprecation on the package? The GitHub repository seems inactive but the latest release was 1 and half years ago.</p> <p>If the package is indeed depre...
<python><dictionary><time><python-3.10>
2024-02-23 11:18:42
1
916
André Clérigo
78,046,927
7,418,045
TypeError: 'NoneType' object is not a mapping
<p>I am trying to concatenate two dictionaries, and I am getting this error:</p> <pre><code>--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[3], line 5 3 dict_list = [{&quot;a&quot;:1}, None, {&quot;b&qu...
<python><dictionary>
2024-02-23 11:02:16
1
743
Anmol Deep
78,046,895
12,415,855
Read detailed style of paragraph in docx-file?
<p>i try to read a doxc-file using python-docx paragraph by paragraph using the following code:</p> <pre><code>for p in document.paragraphs: wStyleName = p.style.name wText = p.text </code></pre> <p>My problem is that i can´t distinguish between a &quot;normal&quot; paragraph and a paragraph where there is also a l...
<python><docx><python-docx>
2024-02-23 10:57:14
0
1,515
Rapid1898
78,046,821
5,021,819
Is is possible to get the last file updated in folder and subfolder with specifique name in artifactory?
<p>I'm looking to find a solution how I can get the path of the last file updated with name &quot;name_file&quot; in specifique folder and subfolder in artifactory directory. From documentation, I see this link <a href="https://jfrog.com/help/r/jfrog-rest-apis/get-last-modified-item" rel="nofollow noreferrer">https://j...
<python><shell><curl><artifactory>
2024-02-23 10:47:47
1
312
Younes Ben Tlili
78,046,777
4,269,851
Python function to filter data from array
<p>I have made function to loop trough array and filter the results.</p> <pre><code>def filter_data(data, match_d=None, trim_matches=False): result_matches = {} # stores matched result_unmatches = {} # stores not matched # loop every record in data for key, value in data.items(): # match rec...
<python><loops><filter>
2024-02-23 10:39:44
1
829
Roman Toasov
78,046,758
7,364,381
Conda installation failed on Ubuntu 22.04
<p>Conda installation failing on WSL Ubuntu 22.04 because of following:</p> <blockquote> <p>anaconda.sh: line 353: bunzip2: command not found</p> </blockquote> <p>Couldn't find bunzip2 package:</p> <p><code>sudo apt-get install bunzip2</code> gives</p> <blockquote> <p>E: Unable to locate package bunzip2.</p> </blockquo...
<python><ubuntu><conda>
2024-02-23 10:37:44
1
713
Sukhmeet Sethi
78,046,656
8,068,825
Pandas - Generate multiple rows and multiple columns from pandas DataFrame where column is lists
<p>So I have this dataframe that's formatted messily. The columns are <code>messages</code> and <code>url</code>, <code>url</code> is the URL to download the audio file associated with the row and <code>messages</code> is the conversation transcribed between 2 people. So for example:</p> <pre><code>[{'role': 'A', 'm...
<python><pandas>
2024-02-23 10:18:45
1
733
Gooby
78,046,643
3,813,424
Regex pattern no working in Python but on RegExr?
<p>From the strings in <code>data</code>, I'm trying to capture &quot;FUND&quot;, respectively &quot;FUND*&quot;, &quot;Total&quot;, and &quot;Rest&quot; in a first group, the following thereafter floating point number, including its prefixed sign, in a second group, and the contents between the parenthesis or brackets...
<python><python-re>
2024-02-23 10:17:41
1
319
St4rb0y
78,046,500
583,464
apply to pandas columns doesn't give the correct results
<p>I have <a href="https://easyupload.io/d8g1dz" rel="nofollow noreferrer">this file</a>.</p> <p>If I read it and do some clean up with regex:</p> <pre><code>import pandas as pd import re df = pd.read_csv('data.csv', index_col=[0]) out = df[['X', 'Y']].apply(lambda s: s.str.extract(r'([a-z\d]+\.[a-z\d]+)', ...
<python><pandas><dataframe><list><csv>
2024-02-23 09:55:19
1
5,751
George
78,046,370
15,803,668
How to Find Text Coordinates for a Given Character Range in a PDF using PyMuPDF?
<p>I am working on a project where I want to extract text coordinates for a specific character range within a PDF document using <code>PyMuPDF</code>. I have a PDF file and a character range defined by the start and end indices. I want to locate the exact position (coordinates) of the text within this character range o...
<python><pymupdf>
2024-02-23 09:31:16
1
453
Mazze
78,046,217
13,944,524
My custom object is not deepcopied when it is used as the default parameter in Pydantic models
<p>I know that Pydantic creates a deepcopy of mutable objects for &quot;<em>every new instances</em>&quot; that we create, if they are placed in the default values.</p> <p>It holds true for my <code>lst</code> field, but not for my custom object <code>item</code>. (The code for <code>__deepcopy__</code> is taken from <...
<python><python-3.x><pydantic>
2024-02-23 09:00:36
1
17,004
S.B
78,046,145
298,847
Why can't an attribute have the same name as a class if its type is a union and uses a default value?
<p>There seems to be some ambiguity in how the use of <code>|</code> in attribute type annotations together with attribute default values is parsed. Leading to the following error:</p> <pre><code>&gt;&gt;&gt; class A: pass ... &gt;&gt;&gt; class B: ... A: A | None = None ... Traceback (most recent call last): Fil...
<python><python-typing>
2024-02-23 08:47:05
2
9,059
tibbe
78,046,131
1,534,638
How to fix smtp connection issue in mail sending?
<p>In my erpnext application I need to send bulk email and I am using <code>smtp.gmail.com</code>. The number vary up to 1000. I can see system can send around 100 email successfully and then getting <strong>Invalid Outgoing Mail Server or Port</strong>. Further deep diving I can see mail exception in smtp login and me...
<python><smtp><erpnext><frappe>
2024-02-23 08:44:16
0
3,839
hizbul25
78,045,657
14,897,644
LSTM forecasting horizontal line with standardized datas
<p>I’ve seen many topics about the problem I have in my situation but nothing help. I am trying to make a forecast on a stock price with a Bidirectional LSTM. My problem here is that the forecast on test datas looks like almost horizontal during the whole period. My data are standardized, and I tried to increase the nu...
<python><tensorflow><keras><time-series><lstm>
2024-02-23 06:58:15
0
417
Rgrvkfer
78,045,588
9,983,652
Invalid argument when saving pickle file
<p>I am trying to save my machine learning model into a pickle file:</p> <pre class="lang-py prettyprint-override"><code>rf_pickle_path=os.path.join(os.getcwd(),&quot;penguin_ml\random_forest_penguin.pickle&quot;) rf_pickle = open(rf_pickle_path, &quot;wb&quot;) pickle.dump(rfc, rf_pickle) rf_pickle.close() </code></pr...
<python>
2024-02-23 06:39:03
2
4,338
roudan
78,045,569
6,521,116
How to get variable from browser context in Selenium and stop breakpoint after getting it?
<p>In the browser's devtools, I've make one XHR breakpoint, when the page do XHR, it will pause at the breakpoint. Then I can print some variable in the console. But when I access the same variable with selenium it throw the variable is not defind.</p> <p>Is it possible to access the same context of the devtools's cons...
<python><selenium-webdriver><devtools>
2024-02-23 06:33:21
1
28,702
LF-DevJourney
78,045,495
5,560,365
How can I run python -m http.server in Visual Studio Code?
<p>I am just starting to learn Python and I'm using VS Code.</p> <p>First of all, how does one open a python terminal without running a python script? &quot;Terminal &gt; New Terminal&quot; opens a new Powershell terminal. The plus in the terminal has no option for opening a Python terminal.</p> <p>The bigger problem: ...
<python><visual-studio-code><terminal>
2024-02-23 06:09:53
1
333
Brad
78,045,211
2,593,383
What type can be used with annotations which won't affect static type checkers
<p>I'd like to use Python (3.12) type annotations at runtime for my own purposes that have nothing to do with variable typing. The syntax is very convenient for adding metadata to variables.</p> <p>So I'd like to annotate with a type that won't affect any static type analysis that may also be occurring. The annotation ...
<python><python-typing><pyright>
2024-02-23 04:40:18
2
3,593
nonagon
78,044,990
716,255
How does a list slice itself?
<p>Maybe the <strong>I am new to python</strong> was lost on many of you. The code below returns 8. Why?</p> <pre><code>numbers = [2,3,5,8] print(numbers[numbers[1]]) </code></pre> <p>When working with slicers, I would expect to see:</p> <pre><code>print(numbers[:]) = [2,3,5,8] or print(numbers[:-1]) = [2,3,5] </code>...
<python><list>
2024-02-23 03:09:00
2
451
user716255
78,044,982
8,968,910
Python: remove unicode from dataframe
<p>I will use a simple dataframe as an example:</p> <pre><code>data = {'A': ['公司\u3000', 'aaaa\uf505'], 'B': ['1', '2']} df = pd.DataFrame(data) print(df) A B 0 公司  1 1 aaaa 2 </code></pre> <p>I want to remove unicode like '\u3000', '\uf505' from column A, however, there are more unicodes in it that I...
<python><pandas><unicode>
2024-02-23 03:06:14
2
699
Lara19
78,044,956
19,787,814
How to convert a Flask simple app to an EXE file (The Flask app is in a PyQt app)?
<p>Let's assume I have an <code>app.py</code> file (which is basically a Flask app containing routes and simple methods), this file imports/requires a db_manager.py (a file that handles the database queries and..)</p> <p>Finally, I am using PyQt5 to make the app running in a desktop application-like app.</p> <p>When I ...
<python><flask><pyqt>
2024-02-23 02:48:32
1
460
Nova
78,044,949
2,195,440
Resolving LinkError with jupyter_latex_envs Post-Link Script Failure in Conda
<p>I'm encountering a LinkError when trying to install jupyter_latex_envs via conda in my conda environment. The post-link script fails, and it seems related to an issue with type annotations in Python 3.11. Here's the error message:</p> <pre><code>LinkError: post-link script failed for package conda-forge::jupyter_lat...
<python><jupyter-notebook><conda><ipython><python-3.11>
2024-02-23 02:45:23
0
3,657
Exploring
78,044,770
1,383,511
How to have many print statements in a project but selectively choose what prints?
<p>I am looking for something similar to how logcat works for android development. In android dev when you are printing to the terminal/logging, the function you call takes a tag and the message to print. That tag can then be used in the logcat terminal to filter what output you see.</p> <p>Is there something similar(i...
<python>
2024-02-23 01:26:03
1
516
NDEthos
78,044,690
93,910
How to evaluate an expression in a pandas df that finds the greater of two variables?
<p>I want to do compute a value that is the maximum of two columns, as follows:</p> <pre><code>df = pd.DataFrame( {'a':[1,3,5], 'b':[6,4,2] } ) df['c'] = df.eval('maximum(a,b)') </code></pre> <p>I am getting 'ValueError: &quot;maximum&quot; is not a supported function'. This is true even when I us...
<python><pandas><eval>
2024-02-23 00:47:36
3
7,056
Sanjay Manohar
78,044,556
5,038,019
What is the correct Splitting of Audio Stream (ByteArray) in python the 2nd file (2nd chunk) is corrupt
<p>I did an test implementation to receive an audio stream over an websocket connection than i buffer and always after 2seconds i would like to save the audio into a file.</p> <p>For the first chunk that is working well. But for the second and all following chunks the audio files have no sound. I guess its because of t...
<python><audio><websocket><stream>
2024-02-22 23:43:46
1
493
shortQuestion
78,044,400
4,281,353
Does iter built in function sort the collection elements whenever possible?
<p><a href="https://docs.python.org/3/library/functions.html#iter" rel="nofollow noreferrer"><code>iter</code></a> generates an ordered collection from the unordered set as below. Is this sorted result a guaranteed behaviour of Python 3?</p> <pre><code>&gt;&gt;&gt; x = {1, 9, 2, 8, 4, 6} &gt;&gt;&gt; y = iter(x) &gt;&g...
<python>
2024-02-22 22:55:51
1
22,964
mon
78,044,357
4,281,353
How to check an object is an ordered collection?
<p>Which object of Python <a href="https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes" rel="nofollow noreferrer">ABC</a> is guaranteed to be ordered and how to check?</p> <p><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterator" rel="nofollow nore...
<python>
2024-02-22 22:45:43
0
22,964
mon
78,044,320
985,845
Python Inferred class hierarchy
<p>I come from a C# background. While learning any OOP language I usually refer back to an old smalltalk interview question I was once asked.</p> <p>How do you make a Rock, Paper, Scissors game without any conditional statements?</p> <p>Here's what I came up with:</p> <p>game_piece.py</p> <pre><code>&quot;&quot;&quot;G...
<python><python-3.x><oop>
2024-02-22 22:32:08
1
479
OneClutteredMind
78,044,249
8,272,788
Calling pd.Series.sum() breaks when using `~` operator
<p>I am trying to sum the inverse of a bool pd.Series. <code>pd.Series.sum()</code> works fine until i use the <code>~</code> operator. At which point <code>.sum()</code> starts throwing negative values.</p> <p>Here is a very simple example:</p> <p><code>.sum()</code> works fine:</p> <pre><code>import pandas as pd &gt;...
<python><pandas>
2024-02-22 22:08:35
1
1,261
MorrisseyJ
78,044,194
4,269,851
Python str = str + value is slow
<p>I am writing 2 Mbyte file line by line and using <code>string</code> variable to populate the data line by line first</p> <p>When i did in loops <code>str = str + new_data</code> it took couple seconds to process the script.</p> <p>Once i changed to <code>str += new data</code> script finishes instantly.</p> <p>Thou...
<python><lag><assignment-operator>
2024-02-22 21:52:53
0
829
Roman Toasov
78,044,157
7,168,098
query a dataframe with conditions in two columns with groupby
<p>I have a dataframe like this:</p> <pre><code>df = pd.DataFrame(data=[['840', '007658', 'EP010A', 'wrwrwr'], ['841', '007658', 'EP019410A', 'wwtert'], ['842', '007658', 'EP0129W', 'erterte'], ['843', '007658', 'EP0629W', 'ertetet'], ['992', '007675', 'EP0275A', 'ete'], ['993', '007675', 'EP0375A', 'ertre'], ['9...
<python><pandas><group-by>
2024-02-22 21:42:55
1
3,553
JFerro
78,044,103
7,211,014
pip install in editable mode from a pyproject in a docker container, ModuleNotFoundError not found
<p>When I <code>pip install -e .</code> my python package in a container (using <code>setup.py</code> and <code>pyproject.toml</code>, not requirements.txt), python cannot find my package. If I remove <code>-e</code> from the pip install, so its just <code>pip install .</code> then it works in the container. I added a ...
<python><docker><pip><dockerfile>
2024-02-22 21:30:23
1
1,338
Dave
78,044,030
14,250,641
Key Error when Implementing Cross Validation with GroupKFold
<p>I have a df with 3 main columns 'label', 'embeddings' (features), 'chr'. I am trying to do a 10-fold cross validation by grouping the chromosomes such that the chr1 rows are all either in the train or test (not split across the train/test). I have a df that looks like: <a href="https://i.sstatic.net/rxmAC.png" rel="...
<python><pandas><dataframe><scikit-learn><cross-validation>
2024-02-22 21:11:16
2
514
youtube