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,341,375
579,228
Count number of regexp matches in a Queryset regexp filter in Django
<p>I've a queryset I'm running in a django view.</p> <pre><code>sp = Session.objects.filter(year__gte=start_year, year__lte=end_year, data__iregex=word_to_search_for_re) </code></pre> <p>Although it says word_to_search_for, this can be a couple of words separated by whitespace.</p> <p>What I want to do is count how man...
<python><django>
2023-10-22 19:18:26
1
1,850
James
77,341,186
3,143,269
Getting a pipe reference into a task
<p>I have two classes, Task1 and Task2. Task1 should read from a TCP/IP port and send up a pipe to Task2. Task2 should return the data to Task1 who echoes this to the client. This is just an experiment. Task2 will eventually process the data and send to another piece of hardware across a serial line. Task1 and Task2 sh...
<python><python-3.x>
2023-10-22 18:21:42
1
1,124
AeroClassics
77,341,161
5,924,264
How to I change import statements in a pickle file?
<p>I recently removed a module <code>xyz</code> and replace it with another one of a different name <code>abc</code>. In some pickle files, it still imports the <code>xyz</code> module. I want to change it to import the <code>abc</code> module. How can I do this?</p> <p>I don't have much experience with serialization/d...
<python><serialization><pickle>
2023-10-22 18:14:09
1
2,502
roulette01
77,341,038
3,623,537
Is it safe to remove items from reversed list?
<p>I guess <a href="https://stackoverflow.com/questions/1207406/how-to-remove-items-from-a-list-while-iterating">it is a common problem</a> that it's unsafe to remove elements from the list while iterating over it. The typical solution is to make a copy of a list. What I've found that using <code>reversed(list)</code> ...
<python>
2023-10-22 17:38:42
1
469
FamousSnake
77,341,025
3,118,330
docker environment variable not loaded in pytest and FastApi
<p>This is a FastApi test docker environment with postgrade DB. paths are several and it need to test it. As see in FastApi guide I tried to use <code>pytest</code> however enviroment variable in compose.yaml does not pass to path as they're working on main app.</p> <p>error returned is because environment <code>ENVIRO...
<python><docker><pytest><fastapi>
2023-10-22 17:35:40
0
472
dannisis
77,340,854
3,912,693
Recommended way of installing two or more Python applications sharing dependencies
<p>Here is the situation: I have installed applications distributed only via <code>pip install</code>. <code>pip install</code> installs application scripts (entry-points) to one of directories designated by <code>$PATH</code> and I can execute those apps from anywhere.</p> <p>If two apps share a dependency, upgrading ...
<python>
2023-10-22 16:47:11
0
333
Jinux
77,340,804
1,714,490
CRC computation port from C to Python
<p>I need to convert the following CRC computation algorithm to Python:</p> <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt; unsigned int Crc32Table[256]; unsigned int crc32jam(const unsigned char *Block, unsigned int uSize) { unsigned int x = -1; //initial value unsigned int c = 0; ...
<python><c><porting><crc32>
2023-10-22 16:30:59
2
3,106
ZioByte
77,340,552
9,494,140
How to auth user to Django admin site using external API end point
<p>I'm using an external endpoint to check if the username and password are given and if it is valid I return <code>success:true</code> if not I return it as <code>false</code>. and ofc I generate a token and return it back to him.</p> <p>Here is the function amusing for this :</p> <pre class="lang-py prettyprint-overr...
<python><django>
2023-10-22 15:21:50
1
4,483
Ahmed Wagdi
77,340,508
4,348,534
How do I solve this atproto ModelError?
<p>I'm trying to connect to bluesky using <code>atproto</code>:</p> <pre><code>bsky_handle = &quot;_____.bsky.social&quot; bsky_password = &quot;____-____-____-____&quot; from atproto import Client bsky = Client() bsky.login(bsky_handle, bsky_password) </code></pre> <p>(Taken from <a href="https://github.com/Linus2pun...
<python><at-protocol>
2023-10-22 15:08:42
1
4,297
FranΓ§ois M.
77,340,461
5,565,481
ChromeDriver is outdated, how do i update it?
<p>Im currently learning Selenium automation with python and im using chromedriver. Im having an issue running this simple script:</p> <pre><code>from selenium import webdriver from selenium.webdriver.chrome.service import Service options = webdriver.ChromeOptions() options.add_experimental_option(&quot;detach&quot;, ...
<python><google-chrome><testing><automation><selenium-chromedriver>
2023-10-22 14:55:21
5
861
Mr_Shoryuken
77,340,272
5,429,320
JSON from api request in func app encoded differently to that of a Django app
<p>I have a Django application which contains a function that calls an API and adds the data from the response into my database. I am trying to move this function into an Azure function app, however the JSON that is returned from the request seems to be encoded differently which is causing the database insert to fail.<...
<python><json><django><python-requests><azure-functions>
2023-10-22 14:07:51
1
2,467
Ross
77,340,162
12,689,373
How to add an x before each element in a list of strings so I can use it then in a lambda expression
<p>I have the code I show below, where I make a dictionary after grouping by some columns. My goal is to transfer the mean I've calculated in the groupby dataframe to an other dataframe. For that I've created a dictionary. My problem is that I don't know how to make variable this part of the lambda expression: <code>x[...
<python><dictionary><lambda>
2023-10-22 13:36:54
0
349
Cristina Dominguez Fernandez
77,339,948
1,457,380
Pandas: Merge two dataframes with different dates, using interpolate for numeric values and ffill for dates and boolean data
<p>I have two <strong>pandas</strong> dataframes to <code>merge</code> with <code>interpolate()</code> on the missing numeric data and with <code>ffill()</code> on boolean data and dates. The source data looks like this:</p> <pre><code>df1 Date Unemployment Rate Federal Debt 0 1969-01-01 3.4 ...
<python><pandas><merge><python-datetime>
2023-10-22 12:32:03
1
10,646
PatrickT
77,339,598
7,227,146
Get dictionary from list of dictionaries
<p>I have these two dictionaries:</p> <pre><code>objs = [{&quot;code&quot;: 34, &quot;reps&quot;: 0}, {&quot;code&quot;: 59, &quot;reps&quot;: 0}] comments = [{&quot;text&quot;: &quot;a&quot;, &quot;code&quot;: 34}, {&quot;text&quot;: &quot;b&quot;, &quot;code&quot;: 59}] </code></pre> <p>I would like to update the <co...
<python>
2023-10-22 10:39:33
4
679
zest16
77,339,486
16,462,878
How to use super with arguments
<p>I have linear hierarchy of classes, <code>A</code>, <code>B</code>, <code>C</code>, sharing a method with a different implementation which depends on the result of the father's one. Such methods have <em>same identifier</em> but different signature and belongingness (static, class, instance).</p> <p>Since I am worki...
<python><inheritance><dynamic><super>
2023-10-22 10:04:15
1
5,264
cards
77,339,100
10,737,396
float() argument must be a string or a number, not 'BarContainer'
<p>I wanted to fix the number of decimal points for barcontainer (python object)</p> <pre><code>ax = sns.countplot(...) for i in ax.containers: # typecast ax.bar_label(i,) </code></pre> <p>The i has a type &quot;barcontainer&quot;. In the visualization, it's a float number of 8 decimal points. I want to round t...
<python><casting><visualization>
2023-10-22 07:53:10
1
784
Towsif Ahamed Labib
77,338,821
16,556,045
Attempting to migrate an Django ImageField, but failing to migrate
<p>I am currently facing a problem with trying to migrate a Django Image field from a folder named media_root located inside a folder named static_cdn inside of my current project here is what my current file structure looks like as that may help;</p> <pre><code>veganetworkmain -----profiles -------static_cdn ------...
<python><django><django-media>
2023-10-22 05:59:26
1
934
KronosHedronos2077
77,338,685
3,462,509
Deep Learning with Python (Keras): Reuters Multiclass Classification
<p>I'm working through this fantastic book, rewriting the examples in PyTorch so that I better retain the material. My results have been comparable to the book's Keras code for most examples, but I'm having some trouble with this exercise. For those that have the book, this is on page 106.</p> <p>The network used in ...
<python><keras><deep-learning><pytorch>
2023-10-22 04:47:30
1
2,792
Solaxun
77,338,663
2,975,510
In VS code jupyter manim magic command stops autocomplete and hint
<p>I want to use jupyter in VS Code to write manim code. However, if I put the cell magic command <code>%%manim -v WARNING --disable_caching Scene_Name</code> at the top of the cell, the autocomplete and parameter hint will be lost in the cell.</p> <p>I wonder how to include the magic and retain the autocomplete + hint...
<python><visual-studio-code><jupyter-notebook><manim>
2023-10-22 04:38:45
0
2,203
Lelouch
77,338,597
3,595,026
How to add middleware to the Fast API to create metrics to track time spent and requests made?
<p>I am adding Middleware to my Fast API app to create Prometheus metrics to get the Processing Time and Number of requests per route. Can someone tell me what I am missing?</p> <p>Using <a href="https://github.com/prometheus/client_python" rel="nofollow noreferrer">Prometheus/client_python</a></p> <p>This is my middle...
<python><prometheus><fastapi><fastapi-middleware>
2023-10-22 04:02:38
2
629
user3595026
77,338,572
6,719,819
ImportError: No module named langchain.llms
<p>I used the following import statetement:</p> <pre><code>from langchain.llms import OpenAI </code></pre> <p>And I am getting the following error:</p> <blockquote> <p>pycode python main.py Traceback (most recent call last): File &quot;main.py&quot;, line 1, in from langchain.llms import openai ImportError: No modu...
<python><openai-api><langchain>
2023-10-22 03:51:20
4
15,655
Daniel
77,338,348
7,822,387
How to create objective function in pywraplp when looping through multiple variables
<p>I have a linear program with the following variables.</p> <pre><code>X[i, j, k] for i,j,k in range(0,100) Y[j, k] for j, k in range(0,100) </code></pre> <p>I am wondering how I can create the following constraint for X and objective function from Y.</p> <pre><code>Constraint: (creates 100 constraints, 1 for each i) ...
<python><linear-programming>
2023-10-22 01:20:40
1
311
J. Doe
77,338,343
12,310,828
Assigning to nested list with list of indices
<p>Given a nested list, you can access the elements with something like</p> <pre><code>data = [[12, 15], [21, 22], [118, 546], [200, 1200]] assert data[0][0] == 12 </code></pre> <p>The issue is that in this case, I want to index into a nested list with a &quot;list of indexes&quot;, with dynamic at runtime length. For...
<python><list><variable-assignment><nested-lists>
2023-10-22 01:18:13
3
443
k huang
77,338,311
159,072
Save *.csv without spaces and double quote (2)
<p>I want to save CSV data without double quotes.</p> <pre><code># Write the data sets to CSV files training_set.to_csv(os.path.join(output_dir, target_dir, 'training_set.csv'), index=False, header=False) validation_set.to_csv(os.path.join(output_dir, target_dir, 'validation_set.csv'), index=False, header=False) test_s...
<python><pandas><csv>
2023-10-22 00:55:35
1
17,446
user366312
77,338,137
8,030,794
The fastest way to reconnect websocket with update url
<p>I need to recieve some data from binance api. And when coins changes, i need to update url of websocket. But I want to spend as little time as possible.To avoid overloading the main thread, I create the websocket in a separate process This is code, how i impletemented this:</p> <pre><code>from functools import parti...
<python><websocket><multiprocessing>
2023-10-21 23:22:09
1
465
Fresto
77,338,098
1,893,148
Traceback for Phantom KeyError
<p>I have never seen a KeyError traceback that doesn't make immediate sense: it is always pointing at some get item, typically on a dictionary, for a key that does not exist. My mistake.</p> <p>Here, however, I am getting a KeyError even though (a) every attempted get of a dictionary value is guarded with <code>.get()<...
<python>
2023-10-21 23:04:15
0
2,220
user1893148
77,337,997
6,232,518
Why is my qbittorrent search plugin not supported?
<p>I started to write a search plugin for qBitTorrent, to search through a torrent website.</p> <p>I followed the instructions given in qbittorrent's wiki : <a href="https://github.com/qbittorrent/search-plugins/wiki/How-to-write-a-search-plugin" rel="nofollow noreferrer">https://github.com/qbittorrent/search-plugins/w...
<python><plugins><bittorrent><torrent>
2023-10-21 22:18:05
1
316
Alexandre ELIOT
77,337,970
18,215,706
How can you use a Python library with CircuitPython?
<p>I recently got started using CircuitPython on microcontrollers (specifially the Raspberry Pi Pico W and Zero W [I know, technically it's a single-board computer]). There are some Python packages that I would like to use on the microcontroller, but I don't know how to do it. The <a href="https://learn.adafruit.com/we...
<python><package><adafruit-circuitpython>
2023-10-21 22:06:44
0
1,117
Anders
77,337,901
5,568,409
How to draw a point on an ellipse from general form
<p>The following program draws a rotated ellipse from an equation given in general form:</p> <pre><code>import matplotlib as mpl import matplotlib.pyplot as plt x_range = np.linspace(-6, +6) y_range = np.linspace(-10, +1) x, y = np.meshgrid(x_range, y_range) A, B, C, D, E, F = 0.25, 0.40, 0.25, 1.50, 2.00, 1.50 f = ...
<python><draw><point>
2023-10-21 21:40:24
1
1,216
Andrew
77,337,571
8,028,263
Jinja equivalent to __file__?
<p>I would like to record the full path to my template in its output, much like the <code>__FILE__</code> macro expands to the current file in C.</p> <p>I've tried the <code>{{ self._TemplateReference__context.name }}</code> trick, but this doesn't work when extending templates. If A extends from B and A is rendered, ...
<python><jinja2>
2023-10-21 19:54:54
0
303
Dragon
77,337,559
1,142,881
How to extract an int value from a string that matches a given regex?
<p>I have a database url that looks like <code>sqlite+pool:///C:/temp/test.db?max_connections=20&amp;stale_timeout=300</code> I would like to extract the <code>20</code> value.</p> <p>I would do something like:</p> <pre><code>url = 'sqlite+pool:///C:/temp/test.db?max_connections=20&amp;stale_timeout=300' # default val...
<python>
2023-10-21 19:51:21
2
14,469
SkyWalker
77,337,481
13,916,049
Merge two dataframes with partial column name match
<p>I want to merge/concatenate two dataframes <code>tcia</code> and <code>clin</code>. In contrast to the <code>tcia</code> dataframe, the <code>clin</code> dataframe has a substring at the end of the column names (i.e., the 3rd &quot;-&quot; followed by subsequent letters). The dataframes should be combined irrespecti...
<python><pandas>
2023-10-21 19:30:19
2
1,545
Anon
77,337,407
1,759,443
Deploy gen2 Google Cloud Functions with GitHub Actions?
<p>I was able to easily deploy to GitHub Actions for 1st generation Google Cloud Functions, but now with 2nd generation, I get authentication errors.</p> <p>How can I set up a GitHub workflow to deploy my function when I merge or push to my <code>main</code> branch?</p> <p>Here is the workflow I was using before</p> <p...
<python><typescript><google-cloud-functions><github-actions>
2023-10-21 19:04:16
1
8,398
Kyle Venn
77,337,388
17,835,656
how to make the application accept scrolling by touching in PyQt5?
<p>I have an application made by PyQt5 and this application is used by customers use touch screen , without keyboard or mouse only screen and they touch on it to move and to do everything.</p> <p>my application has QScrollArea and this QScrollArea contains choices and i need to scroll up and down to be able to see all ...
<python><python-3.x><qt><pyqt><pyqt5>
2023-10-21 18:58:28
1
721
Mohammed almalki
77,337,197
3,155,945
Problem opening image file using PIL.Image on Windows 11
<p>I'm trying to open images using <code>PIL.Image</code>, but encountering this error:</p> <pre><code>Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32 Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information. &gt;&gt;&...
<python><python-3.x><windows><image><runtime-error>
2023-10-21 18:00:04
1
334
alxmke
77,337,183
4,958,156
Finding regions of interest in image/radio data heatmap
<p>I have this weird 'image' data. It's not really an image, it's more like radio waves/signals. But it can be considered an 'image' for python/opencv purposes. It has dimensions 100x100x3 (100x100 size and 3 channels similar to RGB in an image). As you can see, the 'pixel' values are very small (order of magnitude of ...
<python><opencv><image-processing><computer-vision>
2023-10-21 17:57:08
0
1,294
Programmer
77,337,174
6,263,000
How can I define PotsgreSQL table partitions using SQLAlchemy
<p>I'm using</p> <ul> <li>psycopg2(2.9.9)</li> <li>SQLAlchemy(2.0.22)</li> <li>PostgreSQL(16.0)</li> </ul> <p>and I'm trying to create a SQLAlchemy model that generates a list partitioned table. I can use the following to define a table, BUT (see below)</p> <pre><code>from sqlalchemy import create_engine, Column, Integ...
<python><postgresql><sqlalchemy>
2023-10-21 17:55:45
0
609
Babak Tourani
77,337,150
1,142,881
How to create an instance of subclass from a factory (i.e., constructor) which invokes the super __init__ directly?
<p>I have an abstract class A, and a concrete subclass B. B has a constructor with a large code base depending on it but now I need a new way to construct instances of B without impacting the dependent code, so I need to create an instance of B from a new constructor factory method and by invoking B's parent constructo...
<python>
2023-10-21 17:45:16
1
14,469
SkyWalker
77,337,046
5,272,283
Getting number of followers of a Twitter user using Twitter API for free
<p>I wrote a Twitter bot written in Python 3-4 years back, using tweepy which used to tweet about new followers gained in a day for a specific user ID. I tried reviving it today, but it started giving these errors.</p> <blockquote> <p>tweepy.errors.Forbidden: 403 Forbidden 453 - You currently have access to a subset of...
<python><twitter><tweepy>
2023-10-21 17:16:29
0
707
arjun gulyani
77,336,940
7,076,130
Telegram bot inline search doesn't work for custom gif URLs
<p>The <code>InlineQueryResultArticle</code> API does not work correctly when we pass a custom URL (the URL of gig which is on my own server). <br /> I mean when the search bar opens, it says &quot;No Results&quot;.</p> <p>However, when I pass a gif from a famous website like giphy, it works correctly!</p> <p>Does anyo...
<python><bots><telegram><gif>
2023-10-21 16:45:37
1
383
Alireza Kavian
77,336,926
390,897
Plot Shapely LineStrings overlayed by Points in Jupyter
<p>I'm trying to display points over line strings to debug whether there are multiple points on the same line:</p> <pre><code>def to_shapely(points: list[point]): return shapely.ops.unary_union([ shapely.geometry.LineString(points), shapely.geometry.MultiPoint(points) ]) to_shapely([(0,0), (2,2...
<python><jupyter-notebook><shapely>
2023-10-21 16:41:36
1
33,893
fny
77,336,662
12,415,855
Send date-value to input-field using Selenium?
<p>i try to add a date-value to an input-field on a website using selenium using the following code: (at first i am switching to the iframe, input some other values and press a button - but on the new site this is not working anymore)</p> <pre><code>from selenium import webdriver from selenium.webdriver.chrome.options ...
<python><selenium-webdriver>
2023-10-21 15:29:34
1
1,515
Rapid1898
77,336,649
11,586,205
What and why following two with same apply() functionality differ in their results?
<p>Objective is to convert each string to uppercase in Pandas dataframe (<code>df</code>). Used following 3 approaches but not sure why 1st is NOT working ? Please refer code snippet and 3 dataframes viz <code>df1</code>, <code>df2</code>, <code>df3</code>. Using pandas.<strong>version</strong> == 2.1.1</p> <pre><code>...
<python><pandas><dataframe><apply><python-applymap>
2023-10-21 15:25:18
2
696
afghani
77,336,569
9,133,819
Is there any way to publish pyarmor obfuscated python package which is python version independent?
<p>So I am trying to publish a proprietary python package and I am using <code>pyarmor</code> package to obfuscate it and then publish the obfuscated build on <code>PyPi</code>. It is working on the same python version environment, however as mentioned in the <a href="https://pyarmor.readthedocs.io/en/latest/tutorial/g...
<python><pypi><python-packaging><pyarmor>
2023-10-21 15:05:47
1
445
aakarsh
77,336,357
7,334,203
Create a list that its elements are grouped by type
<p>I have a list:</p> <pre><code>lst = [4,67,8, 'not found', 32, 'missing', 21, 23, 'warning', 'alert', 2.01, [], {}] </code></pre> <p>I want to create a new list that is grouped by its type. For example i want my list to be</p> <pre><code>new = [4,67,8, 32, 21, 23, 2.01,'not found','missing','warning', 'alert', [], ...
<python><python-3.x><list>
2023-10-21 14:08:33
4
7,486
RamAlx
77,336,121
1,293,193
Running DRF endpoints in a venv with gunicorn
<p>I have some APIs implemented with DRF and I want those to run in a venv. I am using gunicorn. I run gunicorn like this:</p> <pre><code>/path_to_venv/bin/gunicorn </code></pre> <p>But in the API code I log <code>os.getenv('VIRTUAL_ENV')</code> and it's None. Is that valid evidence that the code is not running in the ...
<python><django><django-rest-framework><gunicorn><python-venv>
2023-10-21 13:08:32
0
3,786
Larry Martell
77,335,990
3,225,420
Matplotlib cannot find the installed PIL module
<p>I want to print <code>rcParams</code> to see the settings during stages of my program.</p> <p>Here are my imports:</p> <pre><code>import matplotlib as mpl from matplotlib import rcParams </code></pre> <p>I've tried the following:</p> <p><code>print(mpl.rcParamsDefault)</code>,<code>print(mpl.rcParams)</code> and <co...
<python><matplotlib><anaconda><python-imaging-library>
2023-10-21 12:34:59
1
1,689
Python_Learner
77,335,915
8,761,554
Getting the row's occurence of max value by column in pandas
<p>I have the following dataframe:</p> <pre><code>import pandas as pd data = { &quot;a&quot;: [0.02, 0.04, -0.1,-0.02], &quot;b&quot;: [0.04, -0.1, -0.02,0.01], &quot;c&quot;: [0.01, 0.3, 0.02,0.02], &quot;d&quot;: [-0.07,0.02,-0.01,0.0] } df = pd.DataFrame(data) </code></pre> <p>I'd like to get the following...
<python><pandas><dataframe>
2023-10-21 12:12:37
4
341
Sam333
77,335,812
7,055,769
Django not saving data with post
<p>I have this view:</p> <pre><code>class TaskApiView(APIView): def post(self, request): serializer = TaskSerializer(data=request.data) print(request.data) if serializer.is_valid(): print(&quot;valid&quot;, serializer.data) serializer.save() return Respons...
<python><django><django-rest-framework>
2023-10-21 11:41:03
1
5,089
Alex Ironside
77,335,795
3,130,747
How to run a single pre-commit hook with particular arguments that are different to the yaml definition
<p>I know that I <a href="https://pre-commit.com/#pre-commit-run" rel="nofollow noreferrer">can run a hook using</a></p> <pre><code>pre-commit run &lt;hook id&gt; </code></pre> <p>But if <code>&lt;hook id&gt;</code> is typically run with a set of arguments, and I want to run it with a different set, how should I go abo...
<python><pre-commit.com>
2023-10-21 11:34:03
1
4,944
baxx
77,335,784
5,224,341
Is it possible to "brute combine" sections of bitmaps in R (perhaps by incorporating e.g. Python code, if needed)?
<p>This question is an expansion of <a href="https://stackoverflow.com/questions/77076487/how-do-i-add-a-legend-indicating-significance-levels-below-a-ggplot-object/77077095#77077095">an earlier discussion</a>, where a good solution is described, but a more brutal combining method might be necessary in some scenarios.<...
<python><r><ggplot2><ggsave>
2023-10-21 11:31:22
0
522
vlangen
77,335,516
1,195,883
Why can this model predict the rotation of MNIST digits that accurately?
<p>I've trained a model on the MNIST set in order to detect the rotation (0, 90, 180, 270 degrees) of the digits like so:</p> <pre><code># model / data parameters num_classes = 4 input_shape = (28, 28, 1) # load the data and split it between train and test sets (x_train_orig, _), (x_test_orig, _) = keras.datasets.mnis...
<python><machine-learning><mnist>
2023-10-21 10:04:26
0
836
user1195883
77,335,372
12,415,855
Does providing content to input-field inside iframe not possible using selenium?
<p>i try to provide a value to an input-field on a website using the following code:</p> <pre><code>from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.s...
<python><selenium-webdriver>
2023-10-21 09:08:03
1
1,515
Rapid1898
77,335,224
7,055,769
no such column: api_task.content during makemigraions
<p>When trying <code>./manage.py runserver</code> or <code>./manage.py makemigrations</code> or <code>./manage.py migrate</code> I am getting:</p> <blockquote> <p>django.db.utils.OperationalError: no such column: api_task.content</p> </blockquote> <p>All solutions say to</p> <ol> <li>remove db.sqlite3</li> <li>remove m...
<python><django>
2023-10-21 08:17:41
1
5,089
Alex Ironside
77,335,159
859,141
Django Objects Filter received a naive datetime while time zone support is active when using min max range
<p>So this question is specifically about querying a timezone aware date range with max min in Django 4.2.</p> <p>Timezone is set as <em>TIME_ZONE = 'UTC'</em> in settings.py and the model in question has two fields:</p> <pre><code>open_to_readers = models.DateTimeField(auto_now=False, verbose_name=&quot;Campaign Opens...
<python><django><datetime>
2023-10-21 07:52:45
1
1,184
Byte Insight
77,334,975
20,240,835
How to stop the annoying warnings output by reticulate in R
<p>I am trying to read a <code>pickle</code> data in R, I have following R code:</p> <pre><code>library(reticulate) pd &lt;- suppressMessages(import(&quot;pandas&quot;)) hubs.data &lt;- suppressWarnings(pd$read_pickle(&quot;input.pickle&quot;)) </code></pre> <p>The code is worked well, but its will output a warnning:</...
<python><r><pandas><reticulate>
2023-10-21 06:39:12
2
689
zhang
77,334,714
1,144,868
Find and delete/replace a part of bigger string
<p>In my python/Django project, I am trying to write a custom exception class where I want to avoid showing few things to the end user.</p> <p>In the below error message, if you see the project name <code>prj-eng-d-nc-prcd-1077</code> is appearing. I want to remove that before the message goes to UI.</p> <p>I was tryin...
<python><python-3.x><string><replace>
2023-10-21 04:11:57
3
3,355
sandeep
77,334,419
4,047,444
Comparing 2 DataFrames and Get Similarity Based on Columns
<p>I have 2 data frames with different size rows. I would like to compare and get the similarity between the two data frames based on two columns, category_id and size. The results can go into a new data frame. The columns will be equal lengths between the 2 data frames.</p> <pre><code>d1 = {'item_id': [1, 2, 3, 4],...
<python><pandas><dataframe>
2023-10-21 01:11:19
2
861
dreamzboy
77,334,369
12,043,259
Extra redundant new line needed to see the expected result when dealing with multiline input
<p>I am trying to read multiline text and print it which seems to be very easy job but interestingly I see odd behavior</p> <pre><code>while True: client_input = '' print(&quot;Please enter your queries:&quot;) # User input we'll be adding to for line in sys.stdin: # Iterator loops over readline(...
<python><python-3.x>
2023-10-21 00:44:02
2
2,039
Learner
77,334,346
3,951,468
Execute an update using single-quoted columns in sqlalchemy
<p>I am writing some tests for our SQL code and have some defined tables:</p> <pre><code>class CompanyAddressORM(Base): __tablename__ = &quot;company_address&quot; pk = Column(&quot;pk&quot;, Text, primary_key=True) project_id = Column(&quot;PROJECT_ID&quot;, Integer) company_id = Column(&quot;COMPANY...
<python><sql><sqlalchemy><snowflake-cloud-data-platform>
2023-10-21 00:32:12
0
364
Drivebyluna
77,334,325
11,025,049
How do relationships work on the mongoengine?
<p>I'm new in mongoengine and I'm trying to relate two documments.</p> <pre class="lang-py prettyprint-override"><code>class Actor(Document): name = StringField(required=True, unique=True) movies = ListField() class Movie(Document): title = StringField(required=True, unique=True) release_date = DateFie...
<python><mongodb><flask><mongoengine>
2023-10-21 00:18:36
1
625
Joey Fran
77,334,317
5,091,964
PyInstaller-Generated .exe closes Immediately When Running Google Palm-2 program
<p>I wrote a short example of a Python program that sends a prompt to the Google Palm-2 model and receives a reply from the model. My program runs correctly when I run it in the command console with the &quot;.py&quot; extension. However, after I created an &quot;.exe&quot; file using Pyinstaller, and ran the &quot;.ex...
<python><artificial-intelligence><pyinstaller>
2023-10-21 00:15:21
2
307
Menachem
77,334,292
3,476,463
perform peft with lora on flan-t5 model causing no executable batch size error
<p>I'm trying to perform PEFT with LoRA. I'm using the Google flan-T5 base model. I'm using the Python code below. I'm running the code with an nvidia GPU with 8 GB of ram on Ubuntu server 18.04 LTS. In the Python code I'm loading the public dataset from huggingface. I've loaded the pre-trained flan-T5 model. I've set...
<python><python-3.x><large-language-model><huggingface><peft>
2023-10-21 00:01:12
1
4,615
user3476463
77,334,235
2,013,747
Is there a standard function in Python that takes an argument, ignores it, and always returns None?
<p>I need to supply a Callable returning None to a library function of the following form:</p> <pre class="lang-py prettyprint-override"><code>def some_third_party_function(callback: Callable[[], None]) -&gt; None: ... </code></pre> <p>but I have a function that does not return <code>None</code></p> <pre class="lan...
<python><python-3.x>
2023-10-20 23:40:38
1
4,240
Ross Bencina
77,334,172
5,179,643
How to start the x-axis ticks at 1 (instead of 0) when plotting a Numpy array using Seaborn lineplot
<p>Let's assume the following array of length 15:</p> <pre><code>import numpy as np arr = np.array([0.17, 0.15, 0.13, 0.12, 0.07, 0.06, 0.05, 0.05, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.02]) arr array([0.17, 0.15, 0.13, 0.12, 0.07, 0.06, 0.05, 0.05, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.02]) </code></pre> <p>I...
<python><numpy><matplotlib><seaborn>
2023-10-20 23:13:19
2
2,533
equanimity
77,334,146
3,052,438
How to escape an environment variable in a SCons action?
<p>I have a build command that runs a Python script. Because the python command is sometimes <code>python</code> and sometimes <code>python3</code> (depending on operating system), I instead use the full path which I'm keeping in an environment variable.</p> <p>However, this path sometimes has weird characters like spa...
<python><shell><escaping><scons>
2023-10-20 23:05:39
1
5,159
Piotr Siupa
77,334,833
13,142,245
Sampling from conditional distribution to impute NaN values in joint
<p>Suppose that X and Z are sets of non-overlapping dimensions where <code>$P(X,Z)$</code> is the joint distribution over all features. I have two sets of data:</p> <ol> <li>X and Z are observed, and</li> <li>only X is observed.</li> </ol> <p>Given the first set, I would like to MLE fit a multivariate Gaussian. Then us...
<python><sampling>
2023-10-20 23:05:08
0
1,238
jbuddy_13
77,333,861
12,846,804
Have read_html read cell content and tooltip (text bubble) separately, instead of concatenate them
<p>This site <a href="https://stats.gladiabots.com/pantheon?" rel="nofollow noreferrer">page</a> has tooltips appearing when hovering over values in columns <code>&quot;Score&quot;</code> and <code>&quot;XP LVL&quot;</code>.</p> <p>It appears that <code>read_html</code> will concatenate <strong>cell content</strong> an...
<python><html><pandas><web-scraping><tooltip>
2023-10-20 21:31:10
3
1,303
OCa
77,333,860
225,020
What does having o_ (o underscore) do in dir?
<p>I was reviewing the code from this <a href="https://github.com/EvanZhouDev/donut-py" rel="nofollow noreferrer">donut.py</a> code that produces an ASCII spinning taurus like the donut.c code.</p> <p>I was wondering what having these 2 snippets in the code does?</p> <pre><code>'o_' in dir() # and (o_ := True) </code><...
<python>
2023-10-20 21:30:24
1
27,595
Jab
77,333,779
7,776,801
How do I add Select TensorFlow op(s) to a python interpreter in Android using Chaquopy
<p>I'm using <a href="https://chaquo.com/chaquopy/" rel="nofollow noreferrer">chaquopy</a> within the Android code of a Flutter project to leverage a python script that uses some tensorflow lite models.</p> <p>Here's the python script:</p> <pre><code>from io import BytesIO import base64 import tensorflow as tf from sk...
<python><android><tensorflow><chaquopy>
2023-10-20 21:08:18
1
820
Jose Georges
77,333,720
3,821,009
Add series to a polars dataframe by cycling to match the dataframe row count
<p>This:</p> <pre><code>df = polars.DataFrame(dict( j=numpy.random.randint(10, 99, 10) )) print('--- df') print(df) s = polars.Series('k', numpy.random.randint(10, 99, 3)) print('--- s') print(s) dfj = (df .with_row_index() .with_columns( polars.col('index') % len(s) ) .join(s.to_frame().with_row_in...
<python><python-polars>
2023-10-20 20:52:54
1
4,641
levant pied
77,333,710
2,348,290
python won't update globals from imported function
<p>I wrote a script to parse arguments from the command line. It has a function called <code>getFlags</code> which parses <code>sys.argv</code> and a command string from the user to create a dictionary called <code>myVars</code> with the variable name and associated values, and returns the dictionary. If I include th...
<python><global>
2023-10-20 20:49:52
1
2,924
jeffpkamp
77,333,437
616,460
Faster way to pass a numpy array through a protobuf message
<p>I have a 921000 x 3 numpy array (921k 3D points, one point per row) that I am trying to pack into a protobuf message and I am running into performance issues. I have control over the protocol and can change it as needed. I am using Python 3.10 and numpy 1.26.1. I am using protocol buffers because I'm using gRPC.</p>...
<python><numpy><performance><protocol-buffers>
2023-10-20 19:46:10
2
40,602
Jason C
77,333,340
8,940,973
Gunicorn behavior with worker and thread configuration
<p>I'm currently using Gunicorn version 20.1.0, and I have a question regarding the behavior of Gunicorn when using the following command:</p> <p>Dockerfile</p> <pre><code> CMD [&quot;gunicorn&quot;, &quot;--workers&quot;, &quot;20&quot;, &quot;--threads&quot;, &quot;5&quot;, &quot;application:application&quot;, &quot;...
<python><flask><gunicorn>
2023-10-20 19:20:49
3
345
No_One
77,333,320
3,216,318
python-oracledb module fails to use instantclient in a docker container
<p>I'm trying to build a docker image to access an oracle database at runtime, I'm having the following error message: <code>DPI-1047: Cannot locate a 64-bit Oracle Client library: &quot;/oracle/instantclient/libclntsh.so: cannot open shared object file: No such file or directory&quot;.</code></p> <p>Inside the contain...
<python><oracle-database><docker><instantclient><python-oracledb>
2023-10-20 19:16:21
3
2,083
GΓ©raud
77,333,277
11,959,501
DeprecationWarning: sipPyTypeDict() is deprecated PyQt5
<p>I was writing the most simplest piece of code to run some small app.</p> <p>I got the next warning message:</p> <pre><code>~\PycharmProjects\LoggerTest\main.py:10: DeprecationWarning: sipPyTypeDict() is deprecated, the extension module should use sipPyTypeDictRef() instead class MainWindow(QMainWindow): </code></p...
<python><pyqt5><python-3.11>
2023-10-20 19:06:51
4
577
Jhon Margalit
77,333,151
7,916,257
How to programmatically identify the first and second minima and the peak in a bell-shaped curve?
<p>I'm working with a dataset that forms a bell-shaped (normal-like) distribution. I'm trying to find three specific points in this distribution:</p> <ol> <li>The first minimum point before the curve ascends.</li> <li>The peak of the curve (the maximum point).</li> <li>The second minimum as the curve descends after the...
<python><python-3.x><pandas><scipy><signal-processing>
2023-10-20 18:42:48
1
919
Joe
77,333,128
2,728,148
Does Python guarantee that a coroutine will run to its first waiting-point immediately?
<p>If I have three asynchronous methods:</p> <pre><code>async def f(): doSomething1() await g() async def g(): doSomething2() await h() async def h(): # some unspecified content </code></pre> <p>Does Python provide any guarantees that no other coroutines can be executed on the current thread betwe...
<python><asynchronous><async-await><python-asyncio>
2023-10-20 18:38:06
3
11,113
Cort Ammon
77,333,100
18,030,914
Geoalchemy2 Geometry schema for pydantic (FastAPI)
<p>I want to use PostGIS with FastAPI and therefore use geoalchemy2 with alembic to create the table in the DB. But I'm not able to declare the schema in pydantic v2 correctly.</p> <p>My Code looks as follows:</p> <pre class="lang-py prettyprint-override"><code># auto-generated from env.py from alembic import op import...
<python><postgis><pydantic><geoalchemy2>
2023-10-20 18:32:23
1
315
Taraman
77,332,955
6,654,904
How to test Data Bulid Tools(DBT) macros in DBT
<p>I have Data Build Tools (BDT) macro for Snowflake tables in aws and the snowflake table table name is source.customer. The macro is here:</p> <pre><code>{% macro get_customer(customer_status='active') -%} {{ source(&quot;source&quot;, &quot;customer&quot;) }} WHERE {% if customer_status.lower() == 'active' -%}...
<python><sql><snowflake-cloud-data-platform><jinja2><dbt>
2023-10-20 18:02:51
1
353
Anson
77,332,822
633,182
Train a pyg model with edge features only, no node level feature vector
<p>With a dataset containing only edge features. This graph has nodes with no X features. This dataset is a set of edges about a network and its network flow. Ex: ip-address1, ip-address2 are the source &amp; target nodes ... <code>the edge_attr</code></p> <p>To build a model in pytorch geometric (pyg) how do I pass th...
<python><vector><dataset><pytorch-geometric>
2023-10-20 17:38:55
1
651
sAguinaga
77,332,706
3,171,007
Querying Snowflake in Python where the table may not exist
<p>I got this code from a coworker that gets and manipulates data from Snowflake using snowflake.connector:</p> <pre><code>with read_snowflake(user = snf_user, warehouse = snf_warehouse, database = snf_db, schema = snf_schema) as snf_conn: max_date_df = pd.read_sql(max_date_qry, snf_conn) #Read </code></pre> <p>How...
<python><snowflake-cloud-data-platform>
2023-10-20 17:12:13
0
1,744
n8.
77,332,131
580,937
Get name of the current Snowpark Python Stored Procedure
<p>is it possible to retrieve the name of the currently running python sproc?</p> <p>For example if I have a python proc</p> <pre><code>CREATE OR REPLACE PROCEDURE copydata(fromtable VARCHAR, totable VARCHAR, count INT) RETURNS STRING LANGUAGE PYTHON RUNTIME_VERSION = '3.8' PACKAGES = ('snowflake-snowpark-python') HAND...
<python><stored-procedures><snowflake-cloud-data-platform>
2023-10-20 15:26:40
1
2,758
orellabac
77,332,054
2,232,418
Get Process ID of the current running build on Azure DevOps
<p>I'm trying to piece together some scripts to add CodeQL scanning to a existing build pipeline on Azure DevOps. For compiled languages such as .NET, a pre-compile command is required to create a CodeQL database to watch the compile. I have set this up as follows:</p> <p>YAML:</p> <pre><code>parameters: - name: gith...
<python><windows><azure-devops><codeql>
2023-10-20 15:16:18
1
2,787
Ben
77,331,996
10,270,246
Can't manage with lxml to have both pretty printing and not turning xml elements to self-closing elements
<p>I'm currently facing a dilemma.</p> <p>This code below doesn't print my XML properly :</p> <pre class="lang-py prettyprint-override"><code>import lxml.etree xml_tree = lxml.etree.parse(&quot;myFile.xml&quot;) root = xml_tree.getroot() for fruit in root: if fruit.tag == &quot;apple&quot;: for apple in f...
<python><lxml><pretty-print>
2023-10-20 15:07:26
1
633
Autechre
77,331,946
7,385,440
Find Amazon ASIN in an API?
<p>I'm trying to find the Amazon ASIN from an API call, which I'll give some parameters. Example: Google search for: <code>site:amazon.com Top Gun Tom Cruise</code> --&gt; ASIN: B001K3K5MO.</p> <p>Explanation: I'm telling the Google search to only focus on sites containing <code>amazon.com</code> and giving it the keyw...
<python><amazon-product-api>
2023-10-20 14:58:17
1
303
G Buis
77,331,752
8,792,159
Check if a file is a .tsv file
<p>This question is closely related to <a href="https://softwarerecs.stackexchange.com/questions/61996/github-continuous-integration-to-validate-a-csv-tsv-file">this thread</a>. I would like to set up a function that checks if an input file is a <code>.tsv</code> file. I realized that it's not sufficient to only use <c...
<python><testing><spreadsheet>
2023-10-20 14:28:54
1
1,317
Johannes Wiesner
77,331,690
1,128,336
databricks throws OSError: [Errno 95] Operation not supported when appending to azure blob file
<p>Doing some file manipulation on databricks and it's failing due to the following error when using <code>open('\mnt\file\','a')</code></p> <pre><code>OSError: [Errno 95] Operation not supported </code></pre> <p>however, it will succeed if <code>open('\mnt\file\','w')</code>. How can &quot;a&quot; not be supported on ...
<python><azure-blob-storage><databricks><azure-databricks>
2023-10-20 14:18:57
2
4,945
sam yi
77,331,645
10,270,246
Pretty printing is failing with lxml when I add an element to an empty element
<p>The pretty printing of lxml module fails when I add an element to an empty XML element :</p> <p>Here is my python code :</p> <pre class="lang-py prettyprint-override"><code>import lxml.etree xml_parser = lxml.etree.XMLParser(remove_blank_text=True) xml_tree = lxml.etree.parse(&quot;myFile.xml&quot;, xml_parser) roo...
<python><lxml><pretty-print>
2023-10-20 14:12:36
1
633
Autechre
77,331,633
3,608,591
Pandas idxmax() returns 0 if no value matches condition?
<p>I'm trying to understand the behaviour of <code>idxmax()</code>.</p> <p>I'm using <code>idxmax()</code> to get all rows below the first row meeting a condition in a dataframe, like this:</p> <p><code>df = df[df['A'].gt(0).idxmax():]</code></p> <p>I'm then checking if the resulting dataframe is empty. There's one uni...
<python><pandas><dataframe>
2023-10-20 14:11:22
1
317
Xhattam
77,331,482
5,212,614
How can we plot a network graph, using pyvis, in a browser?
<p>When I run the code below, I get this message but no network graph is displayed.</p> <p><strong>Warning: When cdn_resources is 'local' jupyter notebook has issues displaying graphics on chrome/safari. Use cdn_resources='in_line' or cdn_resources='remote' if you have issues viewing graphics in a notebook. example.ht...
<python><python-3.x><networkx><pyvis>
2023-10-20 13:52:38
2
20,492
ASH
77,331,446
4,508,605
How to provide date with specific format in folder path in Python
<p>I received csv file with sysdate attached to the filename with format <code>yyyy-mm-dd</code>. For example today i received file as <code>User_test_2023-10-20.csv</code>.</p> <p>I have below python code where i want to attach this sysdate with format <code>yyyy-md-dd</code> to the filename but not sure how to do thi...
<python><filenames><python-3.9><sysdate>
2023-10-20 13:47:02
2
4,021
Marcus
77,331,415
11,049,287
Remove non alpanumberic characters within doublequotes in a string - Python
<p>My input text looks like this :</p> <pre><code>answer_result = I don’t think we’ll still be doing &quot;prompt engineering&quot; in five years &quot;i.e.&quot; figuring out how to hack the prompt by &quot; ,&quot; adding one magic word to the &quot;&quot; end that changes everything else. &quot; What will always ma...
<python><python-3.x><regex>
2023-10-20 13:42:38
1
838
usr_lal123
77,331,171
4,715,957
How to access NetBox data about Virtualization / Virtual Machines via Python
<p>This is a Python script to create a CSV from NetBox data about Devices:</p> <pre><code>devices = nb.dcim.devices.all() csv_file_path = 'netbox_devices.csv' with open(csv_file_path, mode='w', newline='') as csv_file: csv_writer = csv.writer(csv_file) csv_writer.writerow(['Name', 'Manufacturer', 'Model', 'Ser...
<python><netbox>
2023-10-20 13:09:37
1
2,315
dr_
77,331,168
52,074
In the python functions `all` and `any`, what does the second undocumented argument do?
<h3>Background</h3> <p>The output of <code>help(all)</code> is:</p> <pre><code>Help on built-in function all in module builtins: all(iterable, /) Return True if bool(x) is True for all values x in the iterable. If the iterable is empty, return True. </code></pre> <p>I went to look up the official python d...
<python><built-in>
2023-10-20 13:09:05
2
19,456
Trevor Boyd Smith
77,331,073
865,169
How to make pandas.read_sql consistently return `NULL` values as `NaN`?
<p>Let us say I have a table in a database containing data as follows:</p> <pre><code>date value 2023-10-01 08:00:00 88.3 2023-10-02 08:00:00 75.4 2023-10-03 08:00:00 NULL </code></pre> <p>When I read data from this table using <code>pandas.read_sql()</code>, if I read all of the above...
<python><pandas>
2023-10-20 12:52:10
1
1,372
Thomas Arildsen
77,330,978
3,749,896
Alias for an typable Union
<p>I am looking for a way to create a type alias for a <code>Union</code> that is typeable.</p> <p>In my opinion, there is no suitable default type in the <code>typing</code> module.</p> <ul> <li><code>Typing.Iterable</code> is an <code>iterable</code>, which could be a <code>dict</code> β€” but it shouldn't be.</li> <li...
<python><python-typing>
2023-10-20 12:37:25
1
3,090
Sven Eberth
77,330,931
1,214,547
Python frozen dataclass with an optional parameter but non-optional field type
<p>I have a dataclass such as this one:</p> <pre class="lang-py prettyprint-override"><code>@dataclasses.dataclass(frozen=True) class MyClass: my_field: str other_field: str </code></pre> <p>and I have a complicated function for computing a default value for <code>my_field</code> that depends on <code>other_fie...
<python><python-dataclasses>
2023-10-20 12:29:53
2
893
Pastafarianist
77,330,445
4,143,790
Python 2D array is not initialising properly
<p>I am new to Python and trying to initialise a 2D array like this (pasting the code extracts only)</p> <pre><code> ary = [[0]*cols]*rows </code></pre> <p>for insertion, I am doing</p> <pre><code> def Insert(self, val): ary[0][2] = val </code></pre> <p>After that, I insert value like this: myS.Ins...
<python><python-3.x>
2023-10-20 11:09:06
2
427
sam
77,330,184
19,325,656
FastAPI run heavy compute task asynchronously
<p>Hi all I have an issue with running heavy compute task on fastapi endpoint.</p> <pre class="lang-py prettyprint-override"><code>@app.post(&quot;/run/&quot;) async def run_cases(data: List[schemas.TestID], db: orm.Session = Depends(services.get_db)): try: CONTAINER.create() tcm = TestManager(CONTAINER, data) # ...
<python><multithreading><asynchronous><concurrency><fastapi>
2023-10-20 10:26:50
1
471
rafaelHTML