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
⌀
77,511,043
15,414,616
Python faster JWE decryption
<p>I have python code that decrypt JWE, but my issue is that I need to keep up with quite high load of data to decode per second and my code is too slow...</p> <p>Does someone maybe has a suggestion on how to make this code work faster?</p> <p>This is the decryption code which should return <code>{&quot;test&quot;: &qu...
<python><encryption><jwe>
2023-11-19 14:02:53
0
437
Ema Il
77,511,011
8,030,746
What's wrong with this search query (Python and SQLite3)?
<p>I'm trying to search my database and show the results, but my code is returning nothing, and I can't figure out where the mistake is.</p> <p>This is how I'm scraping the data and inserting it into the database:</p> <pre><code>def getJobsData(url): headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x6...
<python><sqlite>
2023-11-19 13:52:22
1
851
hemoglobin
77,510,981
4,878,911
'Go to Definition' from a Python file in a symlinked directory redirects me to the canonical path
<p>Example:</p> <ul> <li>I Have <code>/mnt/extra-drive/Git</code> that contains multiple projects</li> <li>I symlinked this directory to <code>~/Git</code> <ul> <li><code>ln -s /mnt/extra-drive/Git ~/Git</code></li> </ul> </li> <li>And I open the projects using vscode from this new directory <code>~/Git</code></li> <li...
<python><visual-studio-code><symlink><go-to-definition>
2023-11-19 13:44:54
1
645
Ahmed Kamal
77,510,935
19,694,624
Can't delete bot message discord.py / pycord)
<p>I am having trouble deleting discord bot's message. Here is the code to replicate the problem I am having:</p> <pre><code>import discord from tools.config import TOKEN bot = discord.Bot() @bot.event async def on_ready(): print(f&quot;{bot.user} is ready and online!&quot;) @bot.slash_command(name=&quot;chat&qu...
<python><python-3.x><discord><discord.py><pycord>
2023-11-19 13:28:28
1
303
syrok
77,510,858
284,932
CUDA 11.8 not recognized by Tensorflow but Pytorch does
<p>I am currently working on a machine learning project using Ubuntu 23 with an RTX 3060 Ti GPU. I have successfully installed CUDA 11.8, and <strong>PyTorch is functioning perfectly</strong>, recognizing and utilizing the GPU without any issues.</p> <p>However, I am encountering difficulties with TensorFlow. Despite i...
<python><tensorflow><ubuntu>
2023-11-19 13:06:02
0
474
celsowm
77,510,855
13,014,274
Android write problems PermissionError: [Errno 13] Permission denied
<p>I wrote a script that updates exif data of the WhatsApp images. I wanted to run it on my Android phone using Pydroid app, however I end up with the PermissionError: [Errno 13] Permission denied error.</p> <pre><code>import os import piexif import datetime dir_path = '/storage/emulated/0/Android/media/com.whatsapp/W...
<python><android><kivy><exif>
2023-11-19 13:05:19
1
437
Filip Szczybura
77,510,803
22,221,987
How to make a simple HTTPS server in Python 3x
<p>How can i create the simpliest python server, which will receive just one response and than die?</p> <p>I've tried <a href="https://stackoverflow.com/a/19706670/22221987">this</a>, but modified it a bit, because of deprecation of some methods.</p> <pre class="lang-py prettyprint-override"><code>import http.server fr...
<python><ssl><https><request><slack>
2023-11-19 12:45:06
1
309
Mika
77,510,638
3,943,162
How to use a second retriever in LangChain to get extra info?
<p>In the following LangChain code, how can I add a second retriever to get extra info when the information is not found in the first documents?</p> <pre class="lang-py prettyprint-override"><code># Build prompt from langchain.prompts import PromptTemplate template = &quot;&quot;&quot;Use the following pieces of contex...
<python><langchain><large-language-model>
2023-11-19 11:48:01
0
1,789
James
77,510,636
519,779
Where is /tmp/q debugging file on macOS?
<p>On macOS, when I execute this simple Python code using <a href="https://github.com/zestyping/q" rel="nofollow noreferrer">q package</a>:</p> <pre><code>import q q('test') </code></pre> <p>I have not the file <code>/tmp/q</code> created as my zsh session shows:</p> <pre><code>cat /tmp/q cat: /tmp/q: No such file or d...
<python><python-3.x><macos><debugging>
2023-11-19 11:47:26
1
2,425
Jean-Pierre Matsumoto
77,510,573
1,405,689
Python: Extract different columns and assign to a new dataframe
<p>I have this df:</p> <pre><code>A B C D 1 2 3 4 </code></pre> <p>I want to extract columns 0:1 and 3rd one</p> <p>But first thought would be:</p> <pre><code>X = DS.iloc[:, 0:1:3].values </code></pre> <p>But, this approach does not work</p>
<python><pandas><dataframe>
2023-11-19 11:25:02
1
2,548
Another.Chemist
77,510,571
5,618,856
Is .diff(period=-10) working on pandas series?
<p>I have a dataframe like so:</p> <pre><code>import pandas as pd import numpy as np date_rng = pd.date_range(start=&quot;2023-11-18&quot;, periods=3, freq=&quot;10S&quot;) values = [4, 2, 3] df = pd.DataFrame(data={&quot;values&quot;: values}, index=date_rng) df[&quot;dt&quot;] = df.index.to_series().diff().dt.second...
<python><pandas><dataframe><series>
2023-11-19 11:24:23
1
603
Fred
77,510,519
8,157,102
How can I bookmark all search results in PyCharm/JetBrains IDE?
<p>In a large-scale project, sometimes the number of search results is large, and I want to bookmark all the ones found in the search so that I can edit them later. How can I do it?</p> <p>For example, in the following search, more than 100 items were found, and I want all 100 lines of code to be marked.</p> <p><a href...
<python><android-studio><pycharm><webstorm><jetbrains-ide>
2023-11-19 11:06:42
1
961
kamyarmg
77,510,368
14,978,092
How can i read csv from zip file python?
<p>I am trying to read csv which is in zip file. My task is to read the file rad_15min.csv file but the issue is when i read zip file (I copied link address by clicking on download button) it gives me error:</p> <p><strong>Code:</strong></p> <pre><code>import pandas as pd df = pd.read_csv('https://www.kaggle.com/datase...
<python><python-3.x><pandas><csv>
2023-11-19 10:12:56
1
590
Hamza
77,510,160
15,222,211
How to strikethrough substrings without spaces in Sphinx?
<p>I need to <strike>strike</strike> substrings without spaces in Sphinx .rst file to transform it to HTML in a similar manner as <code>&lt;span style=&quot;text-decoration: line-through;&quot;&gt;strike&lt;/span&gt;substring</code>. The following example is not working for me. Is it possible?</p> <p>conf.py</p> <pre c...
<python><python-sphinx><restructuredtext><font-style>
2023-11-19 08:41:15
2
814
pyjedy
77,510,115
2,840,697
Effective way to iterate through all directories in python
<p>Let's say we want the following:</p> <p>directory A contains directory B, and directory B contains three directories: C_one, C_two We want to combine lists (all named 'features') in C_one, C_Two, C_three</p> <p>we want</p> <pre><code>from A.B import C_one, C_two, C_three my_list = C_one.features + C_two.features + ...
<python><list><directory>
2023-11-19 08:26:17
1
942
user98235
77,510,100
15,063,341
How to step into standard library while debugging?
<p>I was curious to see how <code>pickle</code> works and wanted to learn with debugging.</p> <p>I have already searched for this question and disabled <code>justMyCode</code>, below is my <code>launch.json</code> file:</p> <pre class="lang-json prettyprint-override"><code>{ // Use IntelliSense to learn about possi...
<python><visual-studio-code><debugging>
2023-11-19 08:20:00
1
762
Visrut
77,509,988
4,584,863
Streamlit fixed text search box and a clickable button at the bottom of streamlit app
<p>I'm trying hard to fix both a text search box and a voice search button at the bottom of the streamlit app UI but only textbox is getting fixed at the bottom. Button is not getting fixed but instead getting scrolled as I scroll the page. I tried many combinations in python, below is one straightforward approach</p> ...
<python><html><css><streamlit>
2023-11-19 07:27:37
1
510
Bhanu Chander
77,509,924
3,637,646
If statement inside for-loop for assigning values to dictionary in python
<p>I am trying to assign values to a dictionary <code>test_dict</code> based on the values in an array <code>array_type</code>. Namely, I would like to assign a value of <code>beta</code> to <code>test_dict</code> in correspondence of the positions in which <code>array_type</code> is equal to 1. For this I use a for-lo...
<python><for-loop><if-statement>
2023-11-19 07:01:18
2
1,268
CafféSospeso
77,509,904
14,250,641
Not able to see results from trained huggingface model
<p>I'm new to huggingface and after reading the documentation, I've been trying to fine-tune DNABERT2 on my simple dataset.</p> <p>Basically, the idea is I have some DNA sequences that are labeled as '1' or '0', and I want to use the pre-trained DNABERT2 model to predict the label.</p> <p>Example:</p> <pre><code>AATTGG...
<python><tensorflow><huggingface-transformers><bert-language-model><large-language-model>
2023-11-19 06:52:58
1
514
youtube
77,509,892
5,790,653
check if the value of one json field is true based on yaml
<p>This is my <code>yaml</code>:</p> <pre><code>- dedicatedip: 1.1.1.1 status: active type: typeA - dedicatedip: 2.2.2.2 status: active type: typeB - dedicatedip: 2.2.2.2 status: active type: typeA - </code></pre> <p>This is <code>json</code>:</p> <pre><code>{ &quot;error&quot;: fa...
<python>
2023-11-19 06:49:02
1
4,175
Saeed
77,509,875
10,200,497
Finding the longest streak of numbers, sum the values of that group and create an new dataframe
<p>This is an extension to this <a href="https://stackoverflow.com/questions/77505772/finding-the-largest-groups-with-conditions-after-using-groupby/77505997#77505997">post</a>.</p> <p>My dataframe is:</p> <pre><code>import pandas as pd df = pd.DataFrame( { 'a': [ 'a', 'a', 'a', 'a', 'a', 'a', ...
<python><pandas><dataframe>
2023-11-19 06:39:48
2
2,679
AmirX
77,509,556
1,377,354
How to check whether Python code raised any exceptions
<p>I want to test that a large chunk of Python code doesn't raise any exceptions. Both because they're a bit expensive so I want to avoid them under &quot;normal&quot; execution, and because I want my debugger's ability to break on any raised exception to pinpoint the earliest sign of something going wrong.</p> <p>I ca...
<python>
2023-11-19 03:56:04
0
840
Nicolas Capens
77,509,047
3,107,664
h2ogpt custom Prompt wrong: invalid syntax. Maybe you meant '==' or ':=' instead of '='? (<unknown>, line 1)
<p>my prompt looks like this:</p> <pre><code>GPT4 User: {prompt}&lt;|end_of_turn|&gt;GPT4 Assistant: </code></pre> <p>I tried to set it up like this:</p> <pre><code>--prompt_type=custom \ --prompt_dict=&quot;{humanstr=GPT4 User: ,terminate_response=&lt;|end_of_turn|&gt;, botstr=GPT4 Assistant: }&quot; \ </code></pre> <...
<python><large-language-model><h2ogpt>
2023-11-18 23:15:15
1
1,932
Shery
77,508,980
998,291
Pydantic list containing two different types of dictionaries but never either
<p>I can't seem to get around this problem. Consider the following JSON</p> <pre><code> {&quot;sourceInfo&quot;: { &quot;list&quot;: [ { &quot;Ec2AssetSourceSimple&quot;: { &quot;instanceType&quot;: &quot;t2.micro&quot;, &quot;subnetId&quot;: &quot;subnet-xxxxxxxx&quot...
<python><json><pydantic>
2023-11-18 22:44:23
1
881
shluvme
77,508,717
1,447,207
Where to find the code for ESRK1 and RSwM1 in the Julia library source code?
<p>I'm trying to implement the SDE solver called ESRK1 and the adaptive stepsize algorithm called RSwM1 from Rackauckas &amp; Nie (2017). I'm writing a python implementation, mainly to confirm to myself that I've understood the algorithm correctly. However, I'm running into a problem already at the implementation of ES...
<python><math><julia><stochastic><differentialequations.jl>
2023-11-18 21:07:16
1
803
Tor
77,508,682
6,063,706
Correct way to do Lagrange dual optimization PyTorch?
<p>I am trying to optimize a simple dual of a linear program using PyTorch. This is my code, but I keep getting an error with the backwards pass after the first loop:</p> <pre><code>c_t = torch.tensor(c).float() A_t = torch.tensor(A).float() b_t = torch.tensor(b).float() x_t = torch.rand(n, 1, requires_grad=True) def ...
<python><pytorch><linear-programming>
2023-11-18 20:54:24
1
1,035
Tob
77,508,603
843,458
python finding indexes of strings does not work
<p>I have a list of filenames and a filename. Now I want to get the index.</p> <p>I can check that an entry exists, does that match only for identical entries?</p> <pre><code>count = tfilename.count(filename) if count &gt; 0: print(f'{filename} is present in the list for {count} times.') </code></pre> <p>I can ...
<python><find>
2023-11-18 20:28:32
1
3,516
Matthias Pospiech
77,508,528
2,813,606
How to reverse order of pandas string column
<p>I have a tennis dataset that looks similar to the following:</p> <pre><code>import pandas as pd player_name = ['Novak Djokovic','Rafael Nadal','Roger Federer','Andy Murray'] match_id = [202, 202, 203, 203] score = ['6-3 5-7 6-4', '6-3 5-7 6-4', '6-4 7-6', '6-4 7-6'] outcome = [1,0,1,0] df = pd.DataFrame( {'pla...
<python><pandas><string><reverse>
2023-11-18 20:04:51
1
921
user2813606
77,508,513
19,694,624
Check if message was sent in a thread (discord.py / pycord)
<p>I need my discord bot to check if slash command is being executed in a thread or not. Couldn't find anything related in the discord.py docs <a href="https://discordpy.readthedocs.io/en/stable/api.html" rel="nofollow noreferrer">https://discordpy.readthedocs.io/en/stable/api.html</a> and there's no info on that on st...
<python><python-3.x><discord><discord.py><pycord>
2023-11-18 19:59:13
1
303
syrok
77,508,476
3,903,337
pandas: groupby, add new column of unique occurances in one column with condition on a different column
<p>I've seen a lot of variants of this question on stack overflow but none of them seem to work for this specific case.</p> <p>I have a dataframe with 3 columns, as follows:</p> <pre><code>df = pd.DataFrame({ 'col1': ['a', 'a', 'b', 'b', 'b', 'c', 'c', 'c', 'c', 'a'], 'col2': [1,2,1,4,5,6,6,6,9,1], 'col3': ['LOW', 'HIG...
<python><pandas><group-by>
2023-11-18 19:48:45
2
308
kpriya
77,508,414
13,950,870
Using BCP to write data to azure sql database not (much) faster than pandas to_sql
<p>I have written this quick test script to compare the performance of bcp (using <code>bcpandas</code> package) to the performance of regular pandas <code>df.to_sql</code>. See the script below:</p> <pre class="lang-py prettyprint-override"><code>import time import pandas as pd import os import numpy as np from dotenv...
<python><pandas><bcp>
2023-11-18 19:27:45
0
672
RogerKint
77,508,343
1,725,553
memory leak reading video frames to numpy array using ffmpeg as a python subprocess
<p>I can stream videos frame by frame to an OpenGL Texture2D OK in python (pi3d module, example in pi3d_demos/VideoWalk.py) but I've noticed that it gradually leaks memory. Below is a stripped down version of the code that shows the problem.</p> <p>Can anyone see where I'm leaking? The memory seems to be recovered when...
<python><numpy><ffmpeg><memory-leaks><subprocess>
2023-11-18 19:05:24
1
2,277
paddyg
77,508,096
6,296,821
How to scrape past a "Show More" button using BeautifulSoup
<p>I've seen a number of questions on this topic, but it seems like what really matters is how the &quot;show more&quot; button functions, and I'm not fluent enough to figure that out.</p> <p>I'm trying to scrape <a href="https://www.llbean.com/llb/shop/630?page=womens-footwear&amp;csp=f&amp;bc=474&amp;gnrefine=1*BRAND...
<python><web-scraping><beautifulsoup>
2023-11-18 17:55:48
2
569
bkula
77,508,041
998,291
Normalize two different jsons according to shared values
<p>I have two data sources that I retrieve different format Json's from and I want to create a normalized object that will represent the merged Json's according to distinct values.</p> <p>For example, the first json:</p> <pre><code>[ { &quot;zone_group&quot;: &quot;us-east-1b&quot;, &quot;kernel_version&quot;...
<python><pandas><normalize><data-pipeline>
2023-11-18 17:41:34
2
881
shluvme
77,507,844
4,285,386
Poetry not installing via official method successfully - ModuleNotFound: No module named 'poetry.core.toml'
<p>I'm on MacOS, with a 2020 MBP. When I tried updating <code>poetry</code> (which I think was on 1.3, to 1.7.1, the current version as of writing) via <code>poetry self update</code>, I got this error:</p> <pre><code>ModuleNotFoundError: No module named 'poetry.core.toml' </code></pre> <p>I deleted every trace of <cod...
<python><python-poetry>
2023-11-18 16:46:31
1
896
Daniel Soutar
77,507,817
11,356,272
Override the __str__ of ExceptionGroup to include the exceptions' message
<p>I was trying to use the new API of <code>ExceptionGroup</code> (reference <a href="https://docs.python.org/3/library/exceptions.html#exception-groups" rel="nofollow noreferrer">https://docs.python.org/3/library/exceptions.html#exception-groups</a>)</p> <p>And it was just great, so for example if I do:</p> <pre><code...
<python><exception>
2023-11-18 16:39:58
0
1,199
Dorki
77,507,745
843,458
Python hickle SerializedWarning when using dataclass
<p>I have a dataclass</p> <pre><code>@dataclass class ImageFile: path: str folder: str </code></pre> <p>when trying to save this list using hickle</p> <pre><code>hkl.dump(ImageList) </code></pre> <p>it leads to this warning</p> <pre><code>\lib\site-packages\hickle\lookup.py:1491: SerializedWarning: 'ImageFile' ...
<python>
2023-11-18 16:22:46
1
3,516
Matthias Pospiech
77,507,627
11,751,609
Using tensorflow model maker how to save checkpoints during training
<p>I am using the <a href="https://www.tensorflow.org/lite/models/modify/model_maker" rel="nofollow noreferrer">TensorflowLite model maker</a> and I would like to know how I can during training regularily save checkpoints so I can check the loss graphs with tensorboard. How is this done?</p> <p>This function I call whe...
<python><tensorflow><tensorflow-lite>
2023-11-18 15:50:16
2
1,647
finisinfinitatis
77,507,580
159,072
UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown plt.show()
<p>I am using</p> <ul> <li>Windows 10</li> <li>PyCharm 2021.3.3 Professional Edition</li> <li>python 3.11.5</li> <li>matplotlib 3.8.1</li> </ul> <p>How can I permanently resolve this issue in my development environment?</p> <pre class="lang-py prettyprint-override"><code>import numpy as np import matplotlib matplotlib....
<python><matplotlib><pycharm>
2023-11-18 15:40:11
12
17,446
user366312
77,507,537
5,801,127
Pandas how to vectorize this loop
<p>I am currently trying to calculate the pnl of a portfolio and I am having difficulties thinking about a way to vectorize the following code</p> <pre><code>df_test_copy = df.copy() df_test_copy['NV'] = 10000 df_test_copy['pnl'] = 0 last_nw = 10000 for idx, row in df.iterrows(): shares = last_nw / row['close_t+1']...
<python><pandas><dataframe>
2023-11-18 15:29:29
1
1,011
PutsandCalls
77,507,520
13,955,154
cannot import name 'LangchainEmbedding' from 'llama_index'
<p>I'm trying to build a simple RAG, and I'm stuck at this code:</p> <pre><code>from langchain.embeddings.huggingface import HuggingFaceEmbeddings from llama_index import LangchainEmbedding, ServiceContext embed_model = LangchainEmbedding( HuggingFaceEmbeddings(model_name=&quot;thenlper/gte-large&quot;) ) service_co...
<python><google-colaboratory><embedding><langchain><llama-index>
2023-11-18 15:26:32
6
720
Lorenzo Cutrupi
77,507,403
667,301
How do I get the interface IP address from of a Cisco IOS configuration?
<p>When using the following Cisco IOS configuration, how do you get the interface IP address of <code>GigabitEthernet1/3</code> with <code>CiscoConfParse()</code>?</p> <pre><code>! hostname Example ! interface GigabitEthernet1/1 description Example interface ip address 192.0.2.1 255.255.255.128 no ip proxy-arp ! int...
<python><cisco><ciscoconfparse>
2023-11-18 14:59:33
1
43,231
Mike Pennington
77,507,389
893,254
Python project directory structure. ModuleNotFoundError
<p>I have attempted to follow what I believe to be a standard Python project directory structure to create a minimal working test example.</p> <p>Here is the structure I am currently using.</p> <pre><code>python-project-test/ .venv/... scripts/ main.py src/ __init__.py liblocal/ __init__.py ...
<python>
2023-11-18 14:55:37
2
18,579
user2138149
77,507,372
9,964,625
pickle fails to load data: TypeError: _unpickle_timestamp() takes exactly 3 positional arguments (4 given)
<p>I have a dataset, stored in a pandas dataframe, that I have built and pickled in one environment. The pickle file loads fine in that environment (environment 1). However, when I try to load it in a different environment (environment 2), I get an error regarding unpickling timestamps. The error and the pickle versi...
<python><timestamp><pickle>
2023-11-18 14:48:06
1
737
Jeremy Matt
77,507,370
11,833,435
create multiple objects in model serializer create method
<p>I need the below DRF API View to list and create <code>Withdraw</code> records in my Django project.</p> <pre class="lang-py prettyprint-override"><code>class WithdrawListCreateAPIView(PartnerAware, WithdrawQuerySetViewMixin, generics.ListCreateAPIView): permission_classes = (TokenMatchesOASRequirements,) re...
<python><python-3.x><django><django-rest-framework><django-views>
2023-11-18 14:48:00
1
2,133
Javad
77,507,319
2,304,735
How can I read CSV file from function attribute into a pandas dataframe?
<p>I wrote a function that calculates the log returns of a dataframe. The arguments of the function takes the csv file name and should return a dataframe of the log returns of the csv file. The csv file is already located on my machine. Below is the code I am trying to execute.</p> <pre><code>import pandas as pd import...
<python><python-3.x><pandas><dataframe>
2023-11-18 14:33:09
1
515
Mahmoud Abdel-Rahman
77,507,293
7,169,895
Why am I failing to get the IP Address of one website url using networkx and requests?
<p>I am trying to map website urls to their ip addresses and graph it using networkx. My code looks for all links on a webpage using BeautifulSoup and follows those links. I had trouble assigning attributes directly to the node, so I used networkx <code>set_node_attributes</code> with two lists containing the urls and ...
<python><networkx>
2023-11-18 14:27:43
1
786
David Frick
77,507,263
3,368,201
Create a static instance of the same class
<p>I'd like to create a static instance of a class. Assume I have the following data class:</p> <pre class="lang-py prettyprint-override"><code>from dataclasses import dataclass @dataclass(frozen=True) class MyTag: tag: str </code></pre> <p>(i.e. a class with a string member called tag).</p> <p>Now I want to creat...
<python><python-3.11>
2023-11-18 14:18:27
0
2,880
frarugi87
77,507,255
22,466,650
How to get the metadata of a file compressed in a gzip archive?
<p>I have a very basic request.</p> <p>All I need is to retreive the modification time of <code>my_text.txt</code> compressed in <code>my_archive.gz</code>.</p> <p><a href="https://i.sstatic.net/bbOen.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bbOen.png" alt="enter image description here" /></a></p>...
<python><metadata><gzip>
2023-11-18 14:15:36
1
1,085
VERBOSE
77,507,225
233,516
Extracting feature embeddings from an image
<p>I'm trying to use TensorFlow.js to extract feature embeddings from images.</p> <p>Elsewhere I'm using PyTorch and ResNet152 to extract feature embeddings to good effect.</p> <p>The following is a sample of how I'm extracting those feature embeddings.</p> <pre class="lang-py prettyprint-override"><code>import torch i...
<python><tensorflow><keras><pytorch><tensorflow.js>
2023-11-18 14:06:54
0
1,347
Tombatron
77,507,167
1,390,993
Random error "AttributeError: 'NoneType' object has no attribute 'find_all'"
<p>I have written the following code and it works most times. However, i get a random error</p> <pre><code>error &quot;AttributeError: 'NoneType' object has no attribute 'find_all'&quot; </code></pre> <p>sometimes on consecutive runs.</p> <p>It mostly indicates line 13 find_all for <code>products</code>.</p> <p>What co...
<python><python-3.x><web-scraping><beautifulsoup>
2023-11-18 13:50:53
1
1,158
sifar
77,506,997
15,222,211
python sphinx autodoc exclude __init__
<p>I have 2 classes. Class1 needs to display all docstrings, while Class2 needs to display only method docstrings. In the following example, I am trying to disable Class2 without success, docstrings of Class2 still displayed. Please help me disable class and init docstrings in Class2.</p> <p>conf.py</p> <pre class="lan...
<python><python-sphinx><autodoc>
2023-11-18 13:02:56
0
814
pyjedy
77,506,884
590,335
How is it possible to convert a polars dataframe to a huggingface dataset?
<p>Both formats are based on arrow, but I couldn't find a way to transform one to the other.</p> <p>The best I could find is:</p> <p>The dataset library has a <a href="https://huggingface.co/docs/datasets/package_reference/main_classes#datasets.Dataset.from_buffer" rel="nofollow noreferrer"><code>from_buffer</code></a>...
<python><python-polars><pyarrow><huggingface-datasets>
2023-11-18 12:29:20
2
8,467
Ophir Yoktan
77,506,840
140,367
How can I generalize this model_post_init in Pydantic?
<p>I have a human-editable YAML configuration where I'd like to allow fields that are either strings or lists:</p> <pre class="lang-yaml prettyprint-override"><code>examples: foo: red bar: red, green qaz: - red - green - blue </code></pre> <p>This is intended to be deserialized as</p> <pre class="lan...
<python><pydantic>
2023-11-18 12:16:36
2
24,101
Tamás Szelei
77,506,789
843,458
python fails to run due to a call of jupiter notebook in another file (not related)
<p>I simply want to run a .py file in a folder where a .ipynb file exists. It results (using visual studio code) in this error</p> <pre><code>(venv) PS Z:\python&gt; &amp; 'z:\python\venv\Scripts\python.exe' 'c:\Users\matth\.vscode\extensions\ms-python.python-2023.20.0\pythonFiles\lib\python\debugpy\adapter/../..\...
<python><visual-studio-code>
2023-11-18 11:58:16
1
3,516
Matthias Pospiech
77,506,782
3,225,420
How to convert key value pairs of rcParams to dictionary
<p>I want to get <code>key:value</code> pairs of <code>rcParams</code> for further manipulation.</p> <pre><code>from matplotlib import rcParams x = rcParams print(x) </code></pre> <p>Yeilds:</p> <pre><code>_internal.classic_mode: False agg.path.chunksize: 0 animation.bitrate: -1 animation.codec: h264 animation.convert...
<python><matplotlib>
2023-11-18 11:57:17
2
1,689
Python_Learner
77,506,714
1,046,474
How does Psycopg2 handle sessions and transactions concurrency on high traffic apps?
<p>I've been going through <strong>psycopg2</strong> documentation to understand how it handles transactions and so on and so forth.</p> <p>I got that a transaction is <strong>created on a connection level</strong>, regardless of the cursor you use, the <strong>session is visible to all</strong> of them.</p> <blockquot...
<python><database><transactions><psycopg2>
2023-11-18 11:35:12
1
572
BrunoX
77,506,563
5,790,653
how to check two json and yaml files to compare
<p>This is the <code>yaml</code> file (the <code>type</code> field is both in Persian and English, and also <code>Type TypeB</code> is correct and is not a typo):</p> <pre><code>- dedicatedip: 1.1.1.1 status: Active type: 'نوع اول' - dedicatedip: 2.2.2.2 status: Active type: 'Type TypeB' - d...
<python>
2023-11-18 10:49:15
1
4,175
Saeed
77,506,217
3,834,483
16-bit texture through PyOpenGL
<p>I am trying to create a 16-bit texture in PyOpenGL using below statement.</p> <pre><code>img_data = cv2.imread(&quot;Texture.png&quot;,cv2.IMREAD_UNCHANGED) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, width, height, 0, GL_RGB, GL_UNSIGNED_SHORT, img_data) </code></pre> <p>But it throws invalid operation with tracebac...
<python><opengl><pyopengl>
2023-11-18 08:50:38
1
472
bsguru
77,506,060
386,861
Date filtering in pandas
<p>I'm trying to filter some data based around datetime and particular years. Tried two approaches and neither works. What's wrong?</p> <p>This is the data.</p> <pre><code>surname forename initials age_text honours_awards date_of_death date_of_death2 rank regiment unitshipsquadron country servicen...
<python><pandas><datetime>
2023-11-18 07:48:11
3
7,882
elksie5000
77,505,898
11,953,250
Exception: InvalidRequestError: Resource not found
<p>I want to transcribe a audio file using openai whisper model. And I am able to do it locally. But when the same code I am trying to run azure functions by creating python api. I am getting this error <code> Exception: InvalidRequestError: Resource not found</code> I tried resolving it. but not able find why I am ge...
<python><azure><azure-functions><openai-api><openai-whisper>
2023-11-18 06:27:06
1
546
Nitin Saini
77,505,812
3,487,441
Dynamically add methods to a python class
<p>I have to create a decent number of classes with attributes that all follow the same pattern. I want to create a succinct way to do this with the goal of using a script to lay out all the classes so I can avoid repetitive work.</p> <pre><code>add_get_for(class_type, property): class_type[property] = lambda self: s...
<python><python-3.x>
2023-11-18 05:42:15
1
1,361
gph
77,505,772
10,200,497
Finding the largest groups with conditions after using groupby
<p>This is my dataframe:</p> <pre><code>import pandas as pd df = pd.DataFrame( { 'a': ['a', 'a', 'a', 'c', 'b', 'a', 'a', 'b', 'c'], 'b': [20, 20, 20,-70, 70, -10, -10, -1, -1], } ) </code></pre> <p>And this is the output that I want. I want to create a dataframe with two rows:</p> <pre><code> ...
<python><pandas>
2023-11-18 05:18:05
2
2,679
AmirX
77,505,611
16,808,528
Matching the criteria and return the result
<p>I have a jason file like this:</p> <pre><code>{ &quot;Rank&quot;: 1259, &quot;Title&quot;: &quot;Ischemic Nerve Block to Improve Hand Function in Stroke Patients&quot;, &quot;Status&quot;: &quot;Completed&quot;, &quot;Study Results&quot;: &quot;No Results Available&quot;, &quot;Conditions&quot;: &quot...
<python>
2023-11-18 03:39:12
1
477
Rstudyer
77,505,480
7,077,532
Dataframe: Using "Name" Column as Segmentation, Get all dates between Startdate and Enddate columns While Excluding Weekend Dates
<p>Let's say I have the starting input table below.</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Name</th> <th>_leavestartdate</th> <th>_leaveenddate</th> </tr> </thead> <tbody> <tr> <td>Jerry Rice</td> <td>2023-12-26</td> <td>2023-12-26</td> </tr> <tr> <td>Pablo Picasso</td> <td>2023-08...
<python><pandas><dataframe><date><group-by>
2023-11-18 02:18:57
1
5,244
PineNuts0
77,505,378
1,245,262
Why are histograms incorrectly displayed when the distribution is tightly clustered?
<p>I'm trying to display some data in a histogram, but when the data is too tightly clustered, I get either an empty graph, or one I believe to be inaccurate.</p> <p>Consider the following code:</p> <pre><code>import numpy as np from matplotlib import pyplot as plt # Generate data nums = np.random.rand(1000)+1000 # M...
<python><matplotlib><histogram><dpi><antialiasing>
2023-11-18 01:34:33
2
7,555
user1245262
77,505,367
219,153
How can I derive axis index from mouse click event?
<p>This Python 3.11 script displays two graphs (axes):</p> <pre><code>import numpy as np, matplotlib.pyplot as plt def onclick(event): print(event.inaxes) fig, axs = plt.subplots(ncols=2, nrows=1, figsize=(3.5, 2.5), layout=&quot;constrained&quot;) axs[0].plot(np.random.rand(10)) axs[1].plot(np.random.rand(10)) cid...
<python><matplotlib><onclick>
2023-11-18 01:29:47
3
8,585
Paul Jurczak
77,505,351
1,492,613
how to save/load pandas dataframe that contain non-ordered dictonary as field without knowing possible key name and value type to/from parquet?
<p>In our application, we need to append segments of dataframe to parquet storage. However the following code will fail at the load time, due to unmatched type</p> <pre><code>import pyarrow as pa import pyarrow.parquet as pq import pandas as pd df_test1 = pd.DataFrame({'a': [1, 2], 'b': [{'k1': 0, 'k2':1}, {'k3': 'ok'}...
<python><pandas><parquet><pyarrow>
2023-11-18 01:22:57
0
8,402
Wang
77,505,227
3,171,007
Returning a Python dataframe (or other) into a Powershell datatable (or other)
<p>I have a lot of automation in Powershell but am trying to branch off into Python. I have written some Python scripts and are executing them from PS, but have hit a wall where I am trying to pass arguments from PS into py, and return values from py back to PS.</p> <p>My PS:</p> <pre><code>$qry = &quot;SELECT COUNT(*...
<python><pandas><dataframe><powershell>
2023-11-18 00:25:02
2
1,744
n8.
77,505,030
12,954,896
OpenAI API error: "You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0"
<p>I am currently working on a chatbot, and as I am using Windows 11 it does not let me migrate to newer OpenAI library or downgrade it. Could I replace the <code>ChatCompletion</code> function with something else to work on my version?</p> <p>This is the code:</p> <pre><code>import openai openai.api_key = &quot;priva...
<python><pip><artificial-intelligence><openai-api><chatgpt-api>
2023-11-17 23:09:08
2
353
Petrutz
77,504,855
11,890,443
Website detects selenium despite trying a lot of measures
<p>I have a toolset for (ebay) kleinanzeigen.de to post and delete old adds. Lastweek everything worked fine. As I wanted to use the script today it didn't work anymore.</p> <p>Even without any automated action they block you.</p> <p>try this code. It just opens a window and kleinanzeigen.de</p> <pre class="lang-py pre...
<python><selenium-webdriver>
2023-11-17 22:06:28
0
326
Hannes
77,504,794
1,543,042
python importlib.import_module into current scope
<p>I'm following in a long line of people struggling with <code>importlib</code> (<a href="https://stackoverflow.com/questions/301134/how-can-i-import-a-module-dynamically-given-its-name-as-string">1</a>, <a href="https://stackoverflow.com/questions/67631/how-can-i-import-a-module-dynamically-given-the-full-path">2</a>...
<python><python-import>
2023-11-17 21:47:28
1
3,432
user1543042
77,504,781
11,329,736
Read 4 lines at a time, in parallel, from text file
<p>I have these two data sets:</p> <p>data1.txt:</p> <pre><code>@SRR14820084.1 A00794:192:HJNGKDRXX:1:1101:1208:1047/1 CCCCCCTCTCACGGGCTTCTCGGACACAAACGGGAAGGCACACAGCCAGACGGAGCACCGGAGGCACACCAGGGAATGGGAAGCGCCACCACCAGCTCAGAAGCA + FFFFFFFFFFFFFFFF::F:FFF:F,F:,FFFFFF,FFFFFFFFFFF,FFFFFFFFFFFFFFFFF:FFFF:FFFF,FFFFF,FFFFF,FF,FF...
<python><parallel-processing>
2023-11-17 21:42:58
0
1,095
justinian482
77,504,754
10,520,077
Editor suggestions for function arguments with **kwargs in Python
<p>I'm currently working on a Python project and using an editor to write my code. I have a function that takes **kwargs, and I was wondering how I can enable suggestions for the keyword arguments in my editor. I'm looking for a more efficient way to explore and use these arguments during development.</p> <p>Is there a...
<python><visual-studio-code><ide><spyder>
2023-11-17 21:35:49
1
911
DomDunk
77,504,715
1,167,890
Downloading an attachment from Trello cards
<p>I am trying to download all the attachments from my cards on a Trello board using <code>py-trello</code>.</p> <p>Here is the sample code (private information removed):</p> <pre><code>from trello import TrelloClient import requests personal_token = '' account_token = '' client = TrelloClient(api_key=personal_token,...
<python><python-3.x><python-requests><trello>
2023-11-17 21:23:40
1
9,347
Simon O'Doherty
77,504,680
4,403,891
regex to find string between repeating markers
<p>I have a string that looks like this:</p> <pre><code>**** SOURCE#24 **** [1] Source Location [Local/Remote] : Remote Remote Host Name : PNQ User Name : foo [2] Source directory : HDPGWRF [3] Directory poll interval : 30 [4] File name format ...
<python><regex><multiple-occurrence>
2023-11-17 21:15:49
4
381
musca999
77,504,633
7,176,676
Order pandas dataframe on contiguous points
<p>Suppose I have a dataframe in which each row has a <em>row_id</em> as well as the boundary coordinates (left and right) of a line. The dataframe consists of lines that can be ordered such that each line connects to another one, i.e., the lines are contiguous. The way to easily see this is when the right boundary of ...
<python><pandas><dataframe>
2023-11-17 21:06:09
2
395
flow_me_over
77,504,626
2,568,521
scrapy.core.scraper ERROR: Error downloading -- OSError: Errno 24 Too many open files
<p>I inherited a scrapy application which crawls through several 1000 pages on a domain and writes the final results out to a json file. The author had been running this on a mac and had encountered a limitation with OS where it complained the limit on open files had been reached. He addressed this by overriding the ...
<python><windows><scrapy>
2023-11-17 21:04:07
1
4,487
Mark Wojciechowicz
77,504,574
345,427
How to import a generated python module
<p>I am generating python modules (using antlr). e.g. foo_pb2.py, bar_pb2.py</p> <p>If I generate them into my python source directory; then, importing those modules works as expected. However, I do not want to contaminate my source directory with generated files; so, I generate the files into a <code>gen_module</code>...
<python><import><code-generation>
2023-11-17 20:52:53
0
1,869
phreed
77,504,424
19,694,624
Get active threads in a discord channel (Discord.py / Pycord)
<p>I am having an issue fetching active threads on a discord channel. There is not much info about it, or maybe I just couldn't find it. So maybe it's not even possible idk</p> <p>My code:</p> <pre><code>import discord from tools.config import TOKEN bot = discord.Bot() @bot.event async def on_ready(): print(f&quo...
<python><python-3.x><discord><discord.py><pycord>
2023-11-17 20:18:23
1
303
syrok
77,504,345
9,386,819
I'm trying to generate synthetic data using Python. The data should be bivariate and have a specified correlation. Why doesn't my code work?
<p>Here is what I've tried. I've been playing with this for a very long time and cannot figure out what I'm doing wrong. Can anyone help identify what I'm not seeing?</p> <p>I'm trying to create 1,000 samples, each containing two variables, where one variable is correlated to the other with r=0.85 (or whatever correlat...
<python><numpy><linear-algebra><correlation>
2023-11-17 20:03:05
1
414
NaiveBae
77,504,217
446,347
Using NewRelic monitor of Django Channels/asyncio/asgi
<p>NewRelic doesn't have a documented example of how to monitor a Django Channels application. Mostly concern about monitoring the eventloop, using the methods provided <a href="https://docs.newrelic.com/docs/apm/agents/python-agent/python-agent-api/asgiapplication-python-agent-api/" rel="nofollow noreferrer">here</a>...
<python><django><django-channels><newrelic><asgi>
2023-11-17 19:36:43
0
634
LiteWait
77,504,063
4,398,966
Difference between colon and exclamation point
<p>In Python 3 is there a difference between <code>{0:s}</code> and <code>{0!s}</code> when used in a print statement? For example:</p> <pre><code>print(&quot;Hello {0:s} and {0!s}&quot;.format('foo')) </code></pre> <p>prints out the same thing twice.</p> <p>From the documentation it says:</p> <blockquote> <p>The <em>f...
<python>
2023-11-17 19:02:53
0
15,782
DCR
77,503,953
1,094,836
Why annual granularity of annotation?
<p>I import a simple data frame from Excel. Seven dates, 12/2021 - 12/2027, each date a year apart, each associated with a number. I want to add an annotation (a vertical line separating the actual historical value from forecasted numbers), and text making this clear.</p> <pre><code>df.plot() #annotation plt.axvline(p...
<python><matplotlib>
2023-11-17 18:39:57
1
487
Michael Stern
77,503,938
11,154,841
Setting a new value for a NumPy array item saves a much smaller value. How can I just set the value?
<p>Code:</p> <pre><code>import numpy as np data = '12345\n54321\n13542\n12354\n53124' n = data.find('\n') mat = np.array(list(data.replace('\n','')), dtype=np.uint8).reshape(-1, n) mat </code></pre> <p>Out:</p> <pre><code>array([[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 4, 2], [1, 2, 3, 5, 4], ...
<python><arrays><python-3.x><numpy>
2023-11-17 18:37:17
1
9,916
questionto42
77,503,667
5,592,430
Get asyncio results not empty
<p>I have some problem in using of the asyncio for Web Scraping task. I'd like to collect the information about realtors on cian site - I use asyncio because on this site the pagination is used. I encountered two problems . When I use fully async approach I cannot receive requested information - I receive message about...
<python><web-scraping><python-asyncio>
2023-11-17 17:46:52
1
981
Roman Kazmin
77,503,593
4,000,113
python tabulate tablefmt=rounded_outline prints 3 spaces instead of 1 space between columns
<p>How can i avoid extra spaces in the tabulate grid?</p> <pre><code>rows = [ [&quot;A1&quot;, &quot;B2&quot;], [&quot;C3&quot;, &quot;D4&quot;], [&quot;E5&quot;, &quot;E6&quot;], ] print(tabulate(rows, headers=&quot;firstrow&quot;, tablefmt='rounded_outline')) </code></pre> <p>gives me 2 extra spaces in ev...
<python><tabulate>
2023-11-17 17:32:28
2
423
gsxr1300
77,503,516
16,623,197
How do I make a plotly graph where I can change the coloring parameter interactively?
<p>In plotly express I can create scatter plots using data.frames easily:</p> <pre><code>import plotly.express as px df = px.data.gapminder() fig = px.scatter(df, x=&quot;gdpPercap&quot;, y=&quot;lifeExp&quot;, log_x=True, color='continent') </code></pre> <p>Is there a way to add a dropdown menu into the plot so I ca...
<python><plotly>
2023-11-17 17:17:54
1
896
Noskario
77,503,434
6,865,225
Why this multi-threaded code behaves in a safer way when I add thread.join()?
<pre class="lang-py prettyprint-override"><code>import threading # Shared variable shared_variable = 0 NUM_THREADS = 999 NUM_INCREMENT = 1_000_000 # Function to increment the shared variable def increment(): global shared_variable for _ in range(NUM_INCREMENT): shared_variable += 1 # Creating multi...
<python><thread-safety>
2023-11-17 17:03:30
2
779
Anis Smail
77,503,327
21,864,938
Why do I get "This field is required" error from Django imageField?
<p>I have problems with Django's image field. It says that the image field is empty even though I have selected an image This is my models.py:</p> <pre><code>from django.db import models class Post(models.Model): picture = models.ImageField(upload_to=&quot;uploads&quot;) </code></pre> <p>This is my forms.py:</p> <...
<python><django><django-models><django-forms>
2023-11-17 16:46:20
1
478
Lukinator
77,503,315
5,036,928
Near-neighbor Point Cloud Downsampling/Decimation
<p>I'm looking for a way to downsample a point cloud based on the proximity of points to their neighbors (from what I can tell, this is synonymous with &quot;decimation&quot;). While I am currently using PyVista as my main library, I'm not seeing any class/methods that seem to achieve what I am looking for since the <c...
<python><nearest-neighbor><downsampling><pyvista><decimation>
2023-11-17 16:44:29
1
1,195
Sterling Butters
77,503,313
586,424
aiohttp: infinite streaming with long wait periods
<p>I am trying to connect to a REST API which will stream data infinitely when events are happening. In the meantime no data is sent through the API.</p> <p>I have the following code:</p> <pre><code>async with self.client_session.get( self._url(path), headers=self._headers, timeout=aiohttp.ClientTimeout(total=0, ...
<python><asynchronous><python-asyncio><aiohttp>
2023-11-17 16:44:24
0
675
Daniel Mühlbachler-P.
77,503,261
5,765,649
Changing examples value in langchain chain
<p>Assuming we have langchain chain <code>my_chain</code> created using <code>my_schema</code> via:</p> <pre><code>from langchain.chat_models import ChatOpenAI from kor.extraction import create_extraction_chain from kor.nodes import Object, Text, Number from langchain.chat.models import ChatOpenAI from langchain.llms ...
<python><nlp><langchain><large-language-model><chatgpt-api>
2023-11-17 16:36:32
1
827
singa1994
77,503,260
3,385,948
Can we stop the Dash "POST /dash/_dash-update-component HTTP/1.1" log messages?
<p>Has anyone figured out how to stop the following Dash log messages? They clutter up my logs, and on a busy website, make it almost impossible to see actual, useful log messages when errors occur.</p> <pre><code>[17/Nov/2023:16:28:10 +0000] &quot;POST /dash/_dash-update-component HTTP/1.1&quot; 204 0 &quot;https://ex...
<python><flask><plotly-dash>
2023-11-17 16:36:20
1
5,708
Sean McCarthy
77,503,140
12,016,688
What does RESUME opcode actually do?
<p>The <a href="https://docs.python.org/3/library/dis.html#opcode-RESUME" rel="noreferrer">documentation</a> is not very informative (at least for me):</p> <blockquote> <p>opcode:: RESUME (context)</p> <p>A no-op. Performs internal tracing, debugging and optimization checks.</p> <p>The <code>context</code> oparand cons...
<python><cpython><python-internals>
2023-11-17 16:19:54
1
2,470
Amir reza Riahi
77,503,138
4,999,991
Developing a FreeCAD Plugin Using PyFlow: Issues with Python Interpreter and Module Import
<p>I'm working on developing a plugin for FreeCAD that leverages the PyFlow library. To clarify and avoid an XYZ problem, I aim to create a FreeCAD plugin using PyFlow.</p> <p>For development, I face a dilemma:</p> <ul> <li>I can't find the Freecad module using a separate Python interpreter when installing it via pip.<...
<python><python-3.x><pip><freecad>
2023-11-17 16:19:15
0
14,347
Foad S. Farimani
77,503,109
10,036,039
How to fix InvalidManifestError for pre-commit with black?
<p>Running python <code>pre-commit</code> with <code>black</code> latest version <code>23.11.0</code> leads to a wired <code>InvalidManifestError</code>.</p> <p>snippet from <code>.pre-commit-config.yaml</code></p> <pre class="lang-yaml prettyprint-override"><code>repos: - repo: https://github.com/psf/black rev: ...
<python><pre-commit><pre-commit.com><python-black>
2023-11-17 16:15:11
3
12,920
zerocewl
77,503,093
7,869,636
Why in Python the parent's init calls child's overridden method?
<p>I have two classes. The <em>Child</em> has a different signature (number of arguments). Take a look at this MRE (minimal reproducible example):</p> <pre class="lang-py prettyprint-override"><code>class Parent: def __init__(self, arg): self.some_method(arg) # it was intended to call the Parent's some_me...
<python><oop>
2023-11-17 16:12:43
1
839
Ashark
77,503,083
12,320,370
Accessing BitBucket Variables directly inside a Python Script
<p>I've set up some Repository Variables (also tried deployment variables) that hold some secrets for DB connections.</p> <p>I would like to use these variables directly in my .py file, trouble is I have no idea how to, I tried accessing them a few different ways and the error is always the variables being null. Althou...
<python><variables><bitbucket><bitbucket-pipelines>
2023-11-17 16:10:29
1
333
Nairda123
77,503,042
238,230
How to access Python dependencies when SSH'ing to Paketo image?
<p>I have an image built using the <a href="https://paketo.io/docs/howto/python/" rel="nofollow noreferrer">Paketo Python Buildpack</a>. It executes the command in the <code>Procfile</code> fine including python dependencies. However, when I exec on to the running instance e.g. using <a href="https://docs.aws.amazon.co...
<python><buildpack><paketo>
2023-11-17 16:05:17
1
752
Gids