QuestionId
int64
74.8M
79.8M
UserId
int64
56
29.4M
QuestionTitle
stringlengths
15
150
QuestionBody
stringlengths
40
40.3k
Tags
stringlengths
8
101
CreationDate
stringdate
2022-12-10 09:42:47
2025-11-01 19:08:18
AnswerCount
int64
0
44
UserExpertiseLevel
int64
301
888k
UserDisplayName
stringlengths
3
30
78,756,815
11,117,255
WARNING - Connection pool is full, discarding connection: storage.googleapis.com
<p>I'm working on a Python script that downloads images from an Amazon S3 bucket and uploads them to Google Cloud Storage (GCS) using the google-cloud-storage library. The script processes a large dataset in chunks and uses concurrent.futures.ThreadPoolExecutor to parallelize the downloads and uploads. However, after r...
<python><google-cloud-platform><google-cloud-storage><connection><connection-pooling>
2024-07-16 21:30:25
0
2,759
Cauder
78,756,777
897,272
How to call an async method from a sync method within a larger async method
<p>As said I want to call an async method from a sync method, the problem is the sync method is being called by another async method so roughly something like this...</p> <pre><code>async def parent_async() sync_method() def sync_method(): #call utility_async_method </code></pre> <p>I can't just call asyncio....
<python><asynchronous>
2024-07-16 21:18:10
1
6,521
dsollen
78,756,700
13,381,632
Export Excel Spreadsheet From Website - Python
<p>I am trying to find a way to export a Microsoft Excel spreadsheet (.xlsx) from a website and store locally (to my desktop) or to a database. I am able to parse a URL with tabular content and display/write to file, but I need to determine a way to retrieve spreadsheet content that requires clicking a button to downl...
<python><html><excel><automation><html-table>
2024-07-16 20:50:53
1
349
mdl518
78,756,646
2,153,235
Can't access local dataframe from dictionary comprehension expression
<p>I am using dictionary comprehension to compare each dataframe from within a dictionary to its corresponding dataframe in locals(). For some reason, I am getting a key error when accessing the locals() dataframe from within the dictionary comprehension expression.</p> <p>Here is the setup:</p> <pre><code>imort numpy...
<python><pandas><dictionary>
2024-07-16 20:35:53
1
1,265
user2153235
78,756,412
1,349,428
Panel programmatically changing Select item
<p>I am using Panel Select as the following:</p> <pre><code>selection = pn.widgets.Select(name=&quot;My Selection&quot;, groups= {'group 1':{'item1': {'data1':1, 'data2':2}, 'item2': {'data1':3, 'data2':4}}, 'group 2':{'item3': {'data1':1, 'data2':2}}}) </code></pre> <p>I'd like to programmatically change the selected ...
<python><holoviz-panel>
2024-07-16 19:26:09
1
2,048
Meir Tseitlin
78,756,377
453,851
How to configure mosquitto to retain sessions? Why is it discarding my sessions out of the box?
<p>I'm trying to use paho-mqtt (python client) persuade mosquitto to retain a session between client connects, but every time I connect (with the same user,password,client id) the session is not retained.</p> <p>My mosquitto configuration is trivial:</p> <pre><code>listener 1883 password_file /mosquitto/config/password...
<python><mqtt><mosquitto><paho>
2024-07-16 19:15:51
1
15,219
Philip Couling
78,756,354
1,700,890
Display custom dates on x axis matplotlib
<p>Here is my plot:</p> <pre><code>import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns import matplotlib.dates as mdates dates = pd.date_range('2020-03-31', '2024-06-30', freq='Q') my_df =pd.DataFrame({'dates': dates, 'type_a': [np.nan]*10 + list(range...
<python><date><matplotlib><axis>
2024-07-16 19:11:13
0
7,802
user1700890
78,756,262
11,069,614
how to extract files from a list using substring filter
<p>I have a list of files from os.listdir like:</p> <pre><code> TXSHP_20240712052921.csv TXSHP_20240715045301.csv TXSHP_FC_20210323084010.csv TXSHP_FC_20231116060918.csv </code></pre> <p>how do I extract only the ones where 'FC' is not in the filename</p> <p>Ive tried</p> <pre><code>def get_archive_filelist_chip(arc...
<python><list><filter><substring>
2024-07-16 18:49:07
1
392
Ben Smith
78,756,225
22,370,136
Defined Rules get not called in Scrapy
<p>I am currently working with the Python library Scrapy and I am inheriting from the CrawlSpider so that I can override/define custom Rules. I have defined rules that should block all URLs with <code>auth/</code> and allow only URLs with <code>/tags</code>.</p> <p>My solution:</p> <pre><code>class DockerhubDockerRegis...
<python><web-scraping><scrapy><playwright-python>
2024-07-16 18:39:08
1
407
Vlajic Stevan
78,756,165
6,936,582
How to contract nodes and apply functions to node attributes
<p>I have a simple graph with the attributes <strong>height</strong> and <strong>area</strong></p> <pre><code>import networkx as nx nodes_list = [(&quot;A&quot;, {&quot;height&quot;:10, &quot;area&quot;:100}), (&quot;B&quot;, {&quot;height&quot;:12, &quot;area&quot;:200}), (&quot;C&quot;, {&...
<python><networkx>
2024-07-16 18:18:58
1
2,220
Bera
78,756,077
1,521,218
Using ironpython from C# async-await causes the app to hang
<p>From C# we have to call python function, in this case the nltk lib lemmatize function (which still has no good C# implementation). We call it like this:</p> <pre><code>private string Lemmatize(string word) { using (Py.GIL()) { using (var scope = Py.CreateScope()) { dynamic nltk = Py.Import(&quot;nltk&qu...
<python><c#><async-await><semaphore><ironpython>
2024-07-16 17:55:00
0
1,261
Zoltan Hernyak
78,756,058
11,280,068
Unicode strings in a purely python3 codebase - are these useless?
<p>In the codebase that I'm working on, there seems to be remnants of python2 because a lot of the strings are prefixed with <code>u</code>.</p> <p>From researching, it looks like this denotes a unicode string, but in python3, all strings are unicode by default. If I did a big passthrough of the codebase and removed al...
<python><python-3.x><string><unicode><encoding>
2024-07-16 17:50:41
1
1,194
NFeruch - FreePalestine
78,755,449
38,557
Type of Union or Union of Types
<p>In Python, is <code>Type[Union[A, B, C]]</code> the same as <code>Union[Type[A], Type[B], Type[C]]</code>? I think they are equivalent, and the interpreter seems to agree.</p> <p>ChatGPT (which, from my past experience, tends to be wrong with this type of questions) <a href="https://chatgpt.com/share/cae7cf7d-988f-4...
<python><python-typing>
2024-07-16 15:27:03
1
13,083
noamtm
78,755,264
5,790,653
How to break the loop only if email subject does not contain today or yesterday date
<p>I'm reading this <a href="https://thepythoncode.com/article/reading-emails-in-python" rel="nofollow noreferrer">document</a> regarding connecting to my IMAP server and read the emails, but I have some issues.</p> <p>Currently I have around 10K emails and it's growing (I delete old emails weekly, but they're still a ...
<python>
2024-07-16 14:46:07
2
4,175
Saeed
78,755,224
8,384,910
Ignore sub-dependencies in pyproject.toml
<p>A package I want to include in my <code>pyproject.toml</code>, itself depends on <code>torch</code>, which I don't want automatically installing since it takes up a lot of space and my currently installed version already works with it.</p> <p>So, I want to emulate the functionality of the <code>--no-dependencies</co...
<python><pip><pyproject.toml>
2024-07-16 14:37:10
0
9,414
Richie Bendall
78,755,222
8,595,535
Pandas new column based on other dataframe with matching condition
<p>suppose I have two dataframes:</p> <pre><code>import pandas as pd df1 = pd.DataFrame({'Date': [0, 2, 3], 'Id':['A','B','C'], 'Country': ['US', 'CA', 'DE']}) df2 = pd.DataFrame({'Date': [0, 1, 2, 3], 'US': [10, 20, 30, 40], 'CA':[5, 10, 15, 20], 'DE':[100, 200, 300, 400]}) </code></pre> <p>I would like to add a colum...
<python><pandas>
2024-07-16 14:36:40
2
309
CTXR
78,755,219
1,471,980
How do you summarize data frame in pandas based on values
<p>I have a data frame like this</p> <p>df</p> <pre><code>Node_Name size count Abc1 10 2 Abc1 20 2 Zxd 30 3 Zxd 40 3 Zxd 80 3 Ddd 10 4 Ddd 40 4 Ddd 80 4 Ddd 100 4 </code></pre> <p>I need subset this data frame of as this.</...
<python><pandas>
2024-07-16 14:35:59
3
10,714
user1471980
78,755,217
8,519,830
Why does python return a 64bit negative number as very large positive?
<p>Here's the problem. I expect as a result -100. I get from other stackoverflow questions that python is using the 2's complement for negative numbers. How would I convert a string to a 64bit number?</p> <p>Using Python3 under Windows.</p> <pre><code>Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1...
<python>
2024-07-16 14:35:41
3
585
monok
78,754,936
538,256
micro array image registration
<p>How can I image-register these two images?</p> <p><a href="https://i.sstatic.net/JpMgwRq2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JpMgwRq2.png" alt="imgsat" /></a></p> <p><a href="https://i.sstatic.net/65qru46B.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/65qru46B.png" alt="i...
<python><image-processing><image-registration>
2024-07-16 13:42:05
1
4,004
alessandro
78,754,912
893,254
What are the differences between using mutiple or'ed typehints vs abc and an inheritance hierachy in Python?
<p>Python is a dynamic language. This means that types are dynamic at runtime and Python makes use of the concept of Ducktyping.</p> <p>What this means is that for any object <code>x</code> was can do</p> <ul> <li><code>x.some_function()</code></li> <li><code>x.some_property = y</code></li> </ul> <p>without knowing unt...
<python><python-typing>
2024-07-16 13:39:26
1
18,579
user2138149
78,754,820
17,624,474
AWS Lambda unable to work with \n as string
<p>I have a private key from GCP Pub Sub. It is stored like this</p> <pre><code>secret_manager_data = {'google_pubsub_private_key':'-----BEGIN PRIVATE KEY-----\nYourPrivateKeyHere\n-----END PRIVATE KEY-----\n'} </code></pre> <p>I'm now parsing the private key in the below code</p> <pre><code>signer = crypt.Signer.from_...
<python><amazon-web-services><aws-lambda><google-cloud-pubsub>
2024-07-16 13:20:52
1
312
Moses01
78,754,810
19,573,290
How do I use CSS in PyGObject with Gtk 4?
<p>I'm trying to create a little application with PyGObject and Gtk 4.0. All of the other answers were for Gtk 3 or below, and trying them gave me an error.</p> <p>I tried this piece of code:</p> <pre class="lang-py prettyprint-override"><code>css = '* { background-color: #f00; }' # temporary css css_provider = Gtk.Css...
<python><gtk><pygobject><gtk4>
2024-07-16 13:18:31
2
363
stysan
78,754,768
8,736,713
Generic type that acts like base type
<p>I want to create a generic type <code>A[T]</code> that acts exactly like <code>T</code>, except that I can tell at runtime that the type is in fact <code>A[T]</code> and not <code>T</code>.</p> <p>I tried</p> <pre><code>class A(Generic[T], T): pass </code></pre> <p>but that does not seem to work, as mypy complai...
<python><mypy><python-typing>
2024-07-16 13:08:30
1
890
Knoep
78,754,763
3,437,012
Partition by column value in O(n)
<p>Using polars, can I reorder the rows of a dataframe such that</p> <ul> <li>Rows with equal value in <code>col1</code> appear contiguously</li> <li>Doing this is an O(n) operation.</li> </ul> <p>An alternative way of phrasing this is that I want the output sorted by <em>some</em> arbitrary order of <code>col1</code>,...
<python><python-polars>
2024-07-16 13:07:39
2
2,370
Bananach
78,754,323
19,648,465
Error in PyCharm: Package requirement 'Django==5.0.7' is not satisfied
<p>I'm trying to set up a Django project in PyCharm, but I keep encountering the following error:</p> <pre><code>Package requirement 'Django==5.0.7' is not satisfied </code></pre> <p>I have already tried the following steps:</p> <ol> <li>Ensured that Django==5.0.7 is listed in my requirements.txt file.</li> <li>pip ins...
<python><django><pycharm><virtualenv><requirements.txt>
2024-07-16 11:33:05
1
705
coder
78,754,301
5,885,054
Find a Substring in String with Boardtools is not working if the string contains special chars
<p>Today I got frustrated. I'm implementing a very simple logic with substring finding; it turned out to be a more complex situation.</p> <p>Let's consider this small python code:</p> <pre><code>word_one, word_two = ['(/ %$ss%*++~m/()', 'ss?=)?=)()'] field_content = &quot;5uz8439qvnhfruieoghbvui gfurieaogv ui(/ %$SS%*+...
<python><python-3.x><regex><string>
2024-07-16 11:29:26
1
497
Allan Karlson
78,753,870
2,749,397
I'm using a custom transformation, the PNG is OK but the PDF is empty
<p>This question is a follow up to <a href="https://stackoverflow.com/questions/78746962/making-a-poster-how-to-place-artists-in-a-figure-using-mm-and-top-left-origin">Making a poster: how to place Artists in a Figure using mm and top-left origin</a></p> <p>This code:</p> <pre><code>import matplotlib.pyplot as plt from...
<python><matplotlib><pdf><coordinate-transformation>
2024-07-16 09:58:23
3
25,436
gboffi
78,753,860
4,647,519
What is the proper way of including examples in Python docstrings?
<p>How to include examples for function calls in Python docstrings? See @examples tag in R documentation. Or what is the proper way to include examples?</p> <p>I'm looking for something like this:</p> <pre><code>def my_func(x): &quot;&quot;&quot;prints x. :param x: string to print :example: my_func(&quot;hello...
<python><docstring>
2024-07-16 09:55:54
1
545
tover
78,753,848
18,695,803
Using PyROOT with Anaconda. C system headers must be installed
<p>I want to install ROOT and use it in python to execute a script using <code>import ROOT</code>.</p> <p>I used:</p> <pre class="lang-bash prettyprint-override"><code>conda config --set channel_priority strict conda create -c conda-forge --name root_env root conda activate root_env </code></pre> <p>to install ROOT.</p...
<python><anaconda><root-framework>
2024-07-16 09:54:17
0
464
Felkru
78,753,611
7,664,840
Maps in pdf format generated by python cartopy cannot be concatenated in illustrator (possibly due to Outlines outside the artboard scope)
<p>I want to use illustrator to concatenate my PDF graphics, which were generated using python cartopy. But when I moved the two maps closer, I got an error and I couldn't move the maps. The detailed error information is as follows: Error: Can't move the objects. The requested transformation would make some objects fal...
<python><adobe-illustrator><cartopy>
2024-07-16 08:59:01
0
846
Li Yupeng
78,753,534
719,276
Set QTableView cell size when using fetch more?
<p>I can set the size of my table rows using the following code:</p> <pre><code> table = QTableView() table.setModel(CustomModel(dataFrame)) table.resizeRowsToContents() </code></pre> <p>My CustomModel.data() function returns a size when role is Qt.SizeHintRole:</p> <pre><code>class CustomModel(QAbstractTabl...
<python><qt><qtableview><qlistview><qabstractitemmodel>
2024-07-16 08:42:14
1
11,833
arthur.sw
78,753,422
17,580,381
Python - selenium - element not interactable
<p>I know there's quite a lot in Stackoverflow (and elsewhere) about &quot;element not interactable&quot; but I don't think this is a duplicate.</p> <p>My issue is that I get the selenium.common.exceptions.ElementNotInteractableException <strong>ONLY</strong> if I try to run my code in headless mode.</p> <p>Here's the ...
<python><selenium-webdriver>
2024-07-16 08:16:57
2
28,997
Ramrab
78,753,126
15,222,211
How to clear pydantic object to default values (reset to defaults)?
<p>I need default values to be cleared in a Pydantic model. I cannot recreate the object because, in my use case, it has references that need to be preserved. Could you please show me the best practices for this?</p> <p>I need something like this example.</p> <pre class="lang-py prettyprint-override"><code>from pydanti...
<python><pydantic>
2024-07-16 07:10:21
2
814
pyjedy
78,753,057
1,145,011
Python scrapy: get all URLs in the webpage without duplicate URLs
<p>I want to fetch all URLs in the webpage without duplicate URLs using Python scrapy. I wanted to list only URLs starting with <code>allowed_domains = en.wikipedia.org</code>. In case links has external links, I don't want to scan that external link.</p> <p>When I use the code below, I get a few duplicate URLs, not su...
<python><scrapy>
2024-07-16 06:52:18
1
1,551
user166013
78,752,899
6,357,916
LR not decaying for pytorch AdamW even after hundreds of epochs
<p>I have the following code using <code>AdamW</code> optimizer from Pytorch:</p> <pre><code>optimizer = AdamW(params=self.model.parameters(), lr=0.00005) </code></pre> <p>I tried to log in using wandb as follows:</p> <pre><code>lrs = {f'lr_group_{i}': param_group['lr'] for i, param_group in enumerate(self.optim...
<python><machine-learning><deep-learning><pytorch>
2024-07-16 06:09:44
1
3,029
MsA
78,752,644
19,067,218
Pytest Fixtures Not Found When Running Tests from PyCharm IDE
<p>I am having trouble with pytest fixtures in my project. I have a root <code>conftest.py</code> file with some general-use fixtures and isolated <code>conftest.py</code> files for specific tests. The folder structure is as follows:</p> <pre><code>product-testing/ ├── conftest.py # Root conftest.py ├── tests/ │ └──...
<python><pycharm><pytest><python-decorators><pytest-fixtures>
2024-07-16 04:01:21
2
344
llRub3Nll
78,752,638
10,634,126
How can I get distinct array fields efficiently?
<p>My collection with fields:</p> <pre><code>[ { &quot;_id&quot;: xxx, &quot;field&quot;: { &quot;subfield&quot;: [ { &quot;k1&quot;: &quot;a&quot;, &quot;k2&quot;: &quot;b&quot;, ... }, { &quot;k1&quot;: &quot;a&quot;, &quot;k2&q...
<python><mongodb><pymongo>
2024-07-16 03:57:37
0
909
OJT
78,752,604
7,099,374
How to test Amazon Athena queries
<p>I have a rather complicated Athena query, which I would like to test on a local machine without connecting to Athena. I specified some mock data for testing purposes, and I was hoping that I could use something simple like <strong>SQLite</strong> to spin up a local database, populate it with mock data, run the tests...
<python><sqlite><unit-testing><testing><amazon-athena>
2024-07-16 03:44:58
2
836
Amuoeba
78,752,567
13,642,249
Catch-up time-lapse buffering and lag issues while working with FFpyplayer frames and QPixmap with a UDP stream in MPEG-TS format
<p>I am trying to build from the code found in this <a href="https://stackoverflow.com/a/58604963/13642249">post</a> for my use case. However, I'm having trouble with python <a href="https://matham.github.io/ffpyplayer/player.html" rel="nofollow noreferrer"><code>FFpyPlayer</code></a>; with traditional <code>ffplay</co...
<python><python-3.x><pyqt6><ffpyplayer>
2024-07-16 03:15:33
0
1,422
kyrlon
78,752,520
322,909
How can I get the subarray indicies of a binary array using numpy?
<p>I have an array that looks like this</p> <pre><code>r = np.array([1, 0, 0, 1, 1, 1, 0, 1, 1, 1]) </code></pre> <p>and I want an output of</p> <pre><code>[(0, 0), (3, 5), (7, 9)] </code></pre> <p>right now I am able to accomplish this with the following function</p> <pre><code>def get_indicies(array): indicies = ...
<python><numpy>
2024-07-16 02:46:00
2
13,809
John
78,752,372
474,911
How does the iterm2 Python API determine which tab a script is running in?
<p>I have a set of window tabs I use regularly, and when I start up iTerm2, I restore this using &quot;Window-&gt;Restore Window Arrangement&quot;.</p> <p>In .bashrc, I'd like to use the Iterm Python API to set the bash history filename to match the tab's title.</p> <p>To do this, I wrote a Python script using the iter...
<python><iterm2>
2024-07-16 01:12:52
1
860
Michael Wilson
78,752,355
7,498,328
How to fit an image exactly inside an Excel cell using Python and XlsxWriter?
<p>I'm working on a Python script that inserts images into Excel cells using the XlsxWriter library. My goal is to have each image fit precisely within its cell, without any overflow or unused space.</p> <p>Here's a simplified version of my current approach:</p> <pre class="lang-py prettyprint-override"><code>import xl...
<python><excel><python-imaging-library><xlsxwriter>
2024-07-16 00:55:16
1
2,618
user321627
78,752,121
2,738,698
How does numpy.polyfit return a slope and y-intercept when its documentation says it returns otherwise?
<p>I have seen examples where <code>slope, yintercept = numpy.polyfit(x,y,1)</code> is used to return slope and y-intercept, but the <a href="https://numpy.org/doc/stable/reference/generated/numpy.polyfit.html#numpy.polyfit" rel="nofollow noreferrer">documentation</a> does not mention &quot;slope&quot; or &quot;interce...
<python><numpy>
2024-07-15 22:41:03
1
578
user2738698
78,752,004
2,278,511
Kivy - How can I modify example for using ScrollView + GridLayout (Kivy-Garden Draggable)?
<p>This <a href="https://github.com/kivy-garden/draggable/blob/main/examples/using_other_widget_as_an_emitter.py" rel="nofollow noreferrer">Kivy - Draggable</a> example works great:</p> <pre class="lang-py prettyprint-override"><code>from kivy.properties import ObjectProperty from kivy.app import App from kivy.lang imp...
<python><kivy><draggable><kivy-language>
2024-07-15 21:49:56
1
408
lukassliacky
78,751,958
3,367,091
Implementing __eq__ for class hierarchy
<p>This question is about how <code>__eq__</code> should be implemented in a class hierarchy. Let's say we have the following setup:</p> <pre class="lang-py prettyprint-override"><code>class Person: &quot;&quot;&quot;A person with a name.&quot;&quot;&quot; def __init__(self, name): self.name = name ...
<python>
2024-07-15 21:31:28
1
2,890
jensa
78,751,815
13,076,747
Inconsistent results between PyTorch loss function for `reduction=mean`
<p>In particular, the following code block compares using</p> <p><code>nn.CrossEntropyLoss(reduction='mean')</code> with <code>loss_fn = nn.CrossEntropyLoss(reduction='none')</code></p> <p>followed by <code>loss.mean()</code>.</p> <p>The results are surprisingly not the same.</p> <pre class="lang-py prettyprint-overrid...
<python><pytorch><loss-function>
2024-07-15 20:45:26
1
484
Essam
78,751,680
3,486,684
Nested named regex groups: how to maintain the nested structure in match result?
<p>A small example:</p> <pre class="lang-py prettyprint-override"><code>import re pattern = re.compile( r&quot;(?P&lt;hello&gt;(?P&lt;nested&gt;hello)?(?P&lt;other&gt;cat)?)?(?P&lt;world&gt;world)?&quot; ) result = pattern.match(&quot;hellocat world&quot;) print(result.groups()) print(result.groupdict() if result...
<python><regex>
2024-07-15 19:52:49
1
4,654
bzm3r
78,751,562
1,825,632
How to apply margin between main Y-Axis Title vs. Subplot Y-Axis Title
<p>I created two heatmap objects that I want to combine them into a single subplot. So far, tracing them and setting them together worked out. However, I cannot add spacing between the make_subplot <code>y_title</code> and the subplot titles present. Looking through the documentation for plotly there are no parameters ...
<python><plotly>
2024-07-15 19:13:00
1
1,344
Adib
78,751,159
3,117,006
How to add a Python package from Git a dependency in Bazel
<p>I'm trying to set up a build for a Python project in Bazel.</p> <p>One of the dependencies (nvdiffrast, to be exact) is a Python package, that is not in PyPi.</p> <p>I usually install it directly from Git (pip install git+...). Now I don't know how to set up installing this package in thenBazel build.</p> <p>I'm try...
<python><git><bazel>
2024-07-15 17:16:02
1
1,010
zlenyk
78,751,101
1,592,380
Labelling contour lines with OGR_STYLE
<p>I'm trying to add labels to DEM contour lines.</p> <p>I'm working with GDAL 3.6.2. , which I installed using Anaconda . I have some DEM data from USGS which I wrote as a contour map to a KML file using:</p> <pre><code>gdal_contour small.tif /home/ubuntu/node/geotools/contour.kml -i 3.0 -f KML -a ELEVATION </code></p...
<python><gis><gdal><ogr>
2024-07-15 17:02:56
1
36,885
user1592380
78,751,066
2,466,784
Whenever I am maximizing the subwindow in MDI in Pyqt5 the minimize, maximize and close buttons gets hidden in the extreme right top corner
<p>Inside the method, a new QMdiSubWindow object is created, and its content is set to windowRef. The title of the sub-window is set to subWindowTitle. The sub-window is also set to be deleted when it is closed, and its window flags are set to include minimize, maximize, and close buttons. Finally, the sub-window is ad...
<python><pyqt5><mdi>
2024-07-15 16:51:22
0
805
Arun Agarwal
78,751,051
3,369,417
Error installing mySQLDB using pip Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
<p>Unable to run django application in the latest amazon Linux AL2023 running python3.9</p> <p>It reports mySQLDB module is not installed, I tried installing mysql module using pip and yum but nothing helped to solve the problem. The error we get is &quot;Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manu...
<python><pip><mysql-python>
2024-07-15 16:48:55
1
418
user3369417
78,750,965
7,695,845
How to make argparse work nicely with enums and default values?
<p>I have an enum:</p> <pre class="lang-python prettyprint-override"><code>from enum import auto, Enum class MyEnum(Enum): ONE = auto() TWO = auto() THREE = auto() </code></pre> <p>and I want to use it as an argument with <code>argparse</code>. To be more specific, I want to create an argument that accept...
<python><enums><argparse>
2024-07-15 16:27:45
3
1,420
Shai Avr
78,750,943
6,803,114
Split a pandas dataframe column into multiple based on text values
<p>I have a pandas dataframe with a column.</p> <pre><code>id text_col 1 Was it Accurate?: Yes\n\nReasoning: This is a sample : text 2 Was it Accurate?: Yes\n\nReasoning: This is a :sample 2 text 3 Was it Accurate?: No\n\nReasoning: This is a sample: 1. text </code></pre> <p>I have to break the text_col ...
<python><python-3.x><pandas><dataframe>
2024-07-15 16:23:07
2
7,676
Shubham R
78,750,662
2,014,141
np.where on a numpy MxN matrix but return M rows with indices where condition exists
<p>I am trying to use np.where on a MxN numpy matrix, where I want to return the same number of M rows but the indices in each row where the element exists. Is this possible to do so? For example:</p> <pre><code>a = [[1 ,2, 2] [2, 3, 5]] np.where(a == 2) </code></pre> <p>I would like this to return:</p> <pre><cod...
<python><numpy><indices>
2024-07-15 15:21:26
2
492
KidSudi
78,750,527
5,065,860
Installing Python on Node/Playwright docker image?
<p>I have been using Playwrights node docker image, defined here: <a href="https://playwright.dev/docs/docker" rel="nofollow noreferrer">https://playwright.dev/docs/docker</a></p> <p>This includes all the browser dependencies/etc.. for the node version of docker. This has worked fine however i'm going to be integrating...
<python><docker><playwright><gitlab-ci-runner>
2024-07-15 14:53:05
1
3,307
msmith1114
78,750,450
2,006,674
Correct way to graceful shutdown infinite async task running parallel and FastAPI
<p>Following code is working correctly.<br /> I am interested is this correct way to graceful shutdown FastAPI and infinite async task that is running in parallel.</p> <pre><code>import os import asyncio import signal from contextlib import asynccontextmanager from fastapi import FastAPI previous_signal_handler = Non...
<python><signals><fastapi>
2024-07-15 14:38:48
0
7,392
WebOrCode
78,750,364
8,405,296
Saving Fine-tune Falcon HuggingFace LLM Model
<p>I'm trying to save my model so it won't need to re-download the base model every time I want to use it but nothing seems to work for me, I would love your help with it.</p> <p>The following parameters are used for the training:</p> <pre><code>hf_model_name = &quot;tiiuae/falcon-7b-instruct&quot; dir_path = 'Tiiuae-f...
<python><huggingface-transformers><large-language-model><inference><pre-trained-model>
2024-07-15 14:20:36
1
1,362
Lidor Eliyahu Shelef
78,750,118
2,447,427
Dataclass Enum init item from another item
<p>I'm trying to make an <code>Enum</code> the values of which are of a type which is a <code>dataclass</code>. As per the official <a href="https://docs.python.org/3/howto/enum.html#dataclass-support" rel="nofollow noreferrer">Python Enum HOWTO</a>, this can be achieved by inheriting from both <code>Enum</code> and th...
<python><enums><python-dataclasses>
2024-07-15 13:29:08
0
343
bbudescu
78,750,109
6,622,697
Getting the result from a future in Python
<p>I have the following code which executes a process and calls a callback function when the process is done</p> <pre><code>import os import subprocess import tempfile def callback(future): print(future.temp_file_name) try: with open(future.temp_file_name, 'r') as f: print(f&quot;Output fr...
<python><subprocess><popen><concurrent.futures>
2024-07-15 13:26:34
1
1,348
Peter Kronenberg
78,750,004
6,068,731
Find average x values and average y values for a plot
<p>I have an algorithm that generates two sequences <code>x_values</code> and <code>y_values</code> of the same length <code>len(x_values) = len(y_values)</code>. However, at each different run of the algorithm the length of these two sequences is slightly higher or lower, <code>len(x_values_run1) != len(x_values_run2)...
<python>
2024-07-15 13:06:14
0
728
Physics_Student
78,749,974
131,051
Patching in helper function not appled to instance
<p>I am creating a test with <code>unittest.mock.patch</code> that looks something like this:</p> <pre class="lang-py prettyprint-override"><code>class TestService: def test_patched(self): service = Service() with patch.object(service, &quot;_send_to_third_party&quot;) as patch_send: with patch.object(s...
<python><python-unittest>
2024-07-15 12:59:40
1
3,789
GSP
78,749,938
13,217,286
How do I identify consecutive/contiguous dates in polars
<p>I'm trying to isolate runs of dates using polars. For this, I've been playing with <code>.rolling</code>, <code>.rle</code>, and <code>.rle_id</code> but can't seem to fit them together to make it work.</p> <p>Given this:</p> <pre class="lang-py prettyprint-override"><code>import polars as pl df = pl.DataFrame({ ...
<python><dataframe><date><python-polars><rle>
2024-07-15 12:53:18
2
320
Thomas
78,749,890
19,745,277
Running ns1labs/flame from python in docker
<p>I have a docker container that runs a python script. The python script should periodically run an instance of <a href="https://hub.docker.com/r/ns1labs/flame/tags" rel="nofollow noreferrer">ns1labs/flame</a>. It produces an output file, <strong>flame.out.json</strong>. That file needs to be read by the docker contai...
<python><docker><docker-compose><dockerpy>
2024-07-15 12:44:57
1
349
noah
78,749,739
972,647
Why does iterating break up my text file lines while a generator doesn't?
<p>For each line of a text file I want to do heavy calculations. The amount of lines can be millions so I'm using multiprocessing:</p> <pre><code>num_workers = 1 with open(my_file, 'r') as f: with multiprocessing.pool.ThreadPool(num_workers) as pool: for data in pool.imap(my_func, f, 100): p...
<python><multiprocessing>
2024-07-15 12:09:11
1
7,652
beginner_
78,749,530
17,580,381
Is this a Selenium oddity?
<p>The following piece of code runs without error:</p> <pre><code>from selenium import webdriver from selenium.webdriver import ChromeOptions from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By options = Ch...
<python><css><selenium-webdriver><css-selectors>
2024-07-15 11:14:47
1
28,997
Ramrab
78,749,504
1,714,385
Missing checkpoint files when training multiple models at the same time in tensorflow
<p>I have ~100 tensorflow models to train, and on each training I run <code>keras-tuner</code> to find the best hyperparameters for each model. To save time, I would like to train one of these models per CPU core.</p> <p>However, I think that the parallel trainings are overwriting each other's checkpoint, because when ...
<python><tensorflow><keras>
2024-07-15 11:08:53
0
4,417
Ferdinando Randisi
78,749,458
7,973,301
How to create a Python type alias for a parametrized type
<p><a href="https://docs.kidger.site/jaxtyping/" rel="nofollow noreferrer"><code>jaxtyping</code></a> provides type annotations that use a <code>str</code> as parameter (as opposed to a type), e.g.:</p> <pre class="lang-py prettyprint-override"><code>Float[Array, &quot;dim1 dim2&quot;] </code></pre> <p>Let's say I woul...
<python><python-typing>
2024-07-15 10:56:48
1
970
Padix Key
78,749,454
201,657
Sort x axis of plotly express stacked bar chart by total for the bar
<p>I have created a stacked bar chart in using plotly express that visualises edits made to a files in GDrive, and who made those edits.</p> <p>My source dataframe has columns</p> <ul> <li>file_path</li> <li>emailAddress (of the person editing the file)</li> <li>tally</li> </ul> <p>I have file_path plotted on the x axi...
<python><plotly>
2024-07-15 10:55:59
1
12,662
jamiet
78,749,310
4,467,693
In python Django how to define test database and keep records inserted in test database until cleaned in tearDown method of testcase
<p>I want a test database created for my default database in Django latest version, for that I configured in project <code>settings.py</code> file as below.</p> <pre><code>DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', 'TEST': { ...
<python><python-3.x><django><django-testing><django-tests>
2024-07-15 10:20:19
1
706
Kapil Yadav
78,749,249
4,451,315
How to append string to each element of chunked array?
<p>Say I have</p> <pre class="lang-py prettyprint-override"><code>In [22]: import pyarrow as pa In [23]: t = pa.table({'a': ['one', 'two', 'three']}) </code></pre> <p>and I'd like to append <code>'_frobenius'</code> to each element of <code>'a'</code></p> <p>Expected output:</p> <pre><code>pyarrow.Table a: string ----...
<python><pyarrow>
2024-07-15 10:05:17
2
11,062
ignoring_gravity
78,749,205
22,216,622
Multithreading in Azure Api
<p>I need to write almost 300 different wiki page all separated by type : [Epic, Features, ....] using Azure devops python Api</p> <p>And this take me many minutes when i write them one by one</p> <p>So i tried to do a basic multithreading</p> <pre><code>if (multithreading): threads = [] for task in tas...
<python><multithreading><azure-devops><python-multithreading>
2024-07-15 09:52:05
1
311
Kaiwinta
78,748,860
1,082,349
Rolling mean, timedelta offset, min_periods, and center
<p>I would like an annual rolling window that is centered, and where we have missings when the window is calculated over missing data -- at the start and end of the time series, something like:</p> <pre><code>test.head(20) Out[39]: foo month 2016-08-01 NaN 2016-09-01 NaN 201...
<python><pandas>
2024-07-15 08:40:13
2
16,698
FooBar
78,748,775
10,919,370
implementing __repr__ on a class, if try to add function members, get "RecursionError: maximum recursion depth exceeded"
<p>I'm trying to implement __repr__ for a class, but when I want to access function members to add there value to __repr__ I get &quot;maximum recursion depth exceeded&quot;.</p> <p>I've noticed that if I remove all the class' functions the __repr__ works as expected.</p> <p>I intend to do a workaround to skip the memb...
<python><recursion><repr>
2024-07-15 08:19:34
1
1,215
Marcel Preda
78,748,640
6,898,424
Parse XML to String with <b> tags
<p>I'm only getting value1 when using .findall('string') and rest is ignored. How to get whole value? xml file input:</p> <pre><code>&lt;resources&gt; &lt;string name=&quot;key&quot;&gt;value1 &lt;b&gt;value2&lt;/b&gt;. value3&lt;/string&gt; &lt;/resources&gt; </code></pre> <p>python code:</p> <pre><code>import xml.et...
<python><xml><elementtree>
2024-07-15 07:48:36
1
421
Gorthez
78,748,601
1,308,590
python can not read json file with encoding = 'utf8'
<p>I can not read full text with this json file:</p> <pre><code>{ &quot;messages&quot;: [ { &quot;sender_name&quot;: &quot;test&quot;, &quot;timestamp_ms&quot;: 1554347140802, &quot;content&quot;: &quot;Ch\u00c3\u00a0o Anh/Ch\u00e1\u00bb\u008b, Anh/Ch\u00e1\u00bb\u008b vui l\u00c3\u00b2ng \u00c4...
<python><json><utf-8>
2024-07-15 07:39:33
2
554
famfamfam
78,748,429
12,336,422
Apply permutation array on multiple axes in numpy
<p>Let's say I have an array of permutations <code>perm</code> which could look like:</p> <pre class="lang-py prettyprint-override"><code>perm = np.array([[0, 1, 2], [1, 2, 0], [0, 2, 1], [2, 1, 0]]) </code></pre> <p>If I want to apply it to one axis, I can write something like:</p> <pre class="lang-py prettyprint-over...
<python><arrays><numpy>
2024-07-15 06:58:46
2
733
sams-studio
78,748,223
1,516,331
Multi stage builds made my Python Docker image larger. Why?
<p>When using normal one stage build Dockerfile, the final image is 216MB; but when using a multi-stage build approach shown below, I got a final image of 227MB. Why is this?</p> <pre><code># This multi stage build Dockerfile actually makes the image larger! :( FROM python:3.10.14-slim-bookworm AS base LABEL authors=&...
<python><docker><dockerfile><fastapi><docker-multi-stage-build>
2024-07-15 05:48:25
1
3,190
CyberPlayerOne
78,747,915
13,994,829
How could langchain agent step by step in `astream_event()`?
<h3>Example Code</h3> <pre class="lang-py prettyprint-override"><code>@tool async def tool1(): &quot;&quot;&quot;tool1&quot;&quot;&quot; print('start1...') cmd = { 'cmd': 'Scrape', } await asyncio.sleep(5) # do something need long time. go2_command_queue.put(cmd) print('time1....') ...
<python><streaming><openai-api><langchain><agent>
2024-07-15 03:03:06
1
545
Xiang
78,747,896
3,099,733
some python modules cannot be recognized by pylance in vscode
<p>I have installed a python module from <a href="https://github.com/Isra3l/ligpargen" rel="nofollow noreferrer">source</a> with the following command</p> <pre class="lang-bash prettyprint-override"><code>cd /path/to/ligpargen pip install -e . --config-settings editable_mode=strict </code></pre> <p>According to <a href...
<python><visual-studio-code><pylance>
2024-07-15 02:48:38
2
1,959
link89
78,747,766
826,112
Python bytecode, does compare_op pop the stack?
<p>I'm working with the following bytecode:</p> <pre><code> 6 10 LOAD_FAST 0 (x) 12 LOAD_CONST 3 (255) 14 COMPARE_OP 2 (&lt;) 18 POP_JUMP_IF_FALSE 27 (to 74) </code></pre> <p>LOAD_FAST pushes the value for x (zero in this ...
<python><bytecode>
2024-07-15 01:27:44
1
536
Andrew H
78,747,712
6,525,260
Find number of redundant edges in components of a graph
<p>I'm trying to solve <a href="https://leetcode.com/problems/number-of-operations-to-make-network-connected/description/" rel="nofollow noreferrer">problem 1319</a> on Leetcode, which is as follows:</p> <blockquote> <p>There are n computers numbered from 0 to n - 1 connected by ethernet cables connections forming a ne...
<python><algorithm><graph-theory>
2024-07-15 00:44:18
3
11,847
Arnav Borborah
78,747,442
708,833
How can I set the display environment variable on a Raspberry Pi at boot?
<p>I have a Raspberry Pi 4 with a 1280x800 display and no keyboard or mouse. I ssh into it remotely over WiFi and am coding it to display images, ultimately on its own without my ssh into it. I installed feh and am using it in a python script to display an image:</p> <pre><code>import subprocess image = subprocess.Pope...
<python><raspberry-pi><raspberry-pi4>
2024-07-14 20:58:19
2
4,741
Dribbler
78,747,409
2,988,730
Suppress stdout message from C/C++ library
<p>I am attempting to suppress a message that is printed to stdout by a library implemented in C.</p> <p>My specific usecase is OpenCV, so I will use it for the MCVE below. The <a href="https://docs.opencv.org/4.10.0/d9/d0c/group__calib3d.html#ga1b976b476cd2083edd4323a34e9e1ffa" rel="nofollow noreferrer"><code>estimate...
<python><cpython>
2024-07-14 20:34:44
1
115,659
Mad Physicist
78,747,259
15,547,292
Possibility to implement multiple repr strategies?
<p>In Python, is there a way to implement multiple <code>repr</code> strategies on custom classes, to provide different representation styles, and that recursively on arbitrary data structures, so nested objects would be shown using the parent call's strategy, if available? Like this...</p> <pre class="lang-py prettypr...
<python><repr>
2024-07-14 19:13:04
2
2,520
mara004
78,747,242
8,008,396
Why does a zig const reference cause a segmentation fault when passed to C-function?
<p>Consider the following file <code>hello.zig</code> which defines a basic Python C extension (and which works):</p> <pre><code>const c = @cImport({ @cInclude(&quot;Python.h&quot;); }); var module = c.PyModuleDef{ .m_name = &quot;__name__&quot;, .m_doc = &quot;__doc__&quot;, .m_size = -1, }; export f...
<python><c><zig>
2024-07-14 19:04:07
1
2,654
Tobias Bergkvist
78,746,962
2,749,397
Making a poster: how to place Artists in a Figure using mm and top-left origin
<p>I want to prepare a &quot;portrait&quot; A0 poster (841mm × 1189mm) placing different Artists (no Axes, but Rectangles and Texts) specifying their positions in mm from the top-left corner of the figure.</p> <p>I have already figured out a possible procedure, e.g., if I want a rectangle, 40mm × 18mm, its top left cor...
<python><matplotlib><coordinates><transform>
2024-07-14 17:03:20
1
25,436
gboffi
78,746,932
11,932,910
Can "Go to Definition" go to a concrete class in VSCode / Python (Pylance) during debugging?
<p>I define an attribute of type <code>MyAbstractClass</code> (abstract class), which takes a value of a concrete subclass <code>MyConcreteClass</code>. When I hit &quot;Go to Definition&quot; in VSCode at <code>poke</code> in <code>self.item.poke()</code>, it takes me to <code>MyAbstractClass.poke()</code>, which is e...
<python><visual-studio-code><pylance><dynamic-dispatch>
2024-07-14 16:47:24
0
381
paperskilltrees
78,746,708
6,068,731
Create a boolean array with True for any value between two entries in a certain array
<p>I have a tensor called <code>idx</code> which has integers from <code>0</code> to <code>27</code>, for instance:</p> <pre><code>idx = torch.tensor([9, 0, 6, 5, 2, 1, 10, 18, 26, 0, 11]) </code></pre> <p>I want to generate another array/tensor which has boolean values. I want the value to be True when it is strictly ...
<python><numpy><pytorch>
2024-07-14 15:06:50
2
728
Physics_Student
78,746,691
2,863,527
Django reversed for loop slice
<p>I am currently trying to reverse a slice of a list going from 0 to 11</p> <pre><code>class Game(models.Model): board = models.JSONField(default=list) game = Game(board=[4] * 12, scores=[0, 0], current_player=0, game_over=False) </code></pre> <p>Here is part of <code>index.html</code></p> <pre><code>&lt;div&gt; ...
<python><django><slice><reverse>
2024-07-14 15:00:05
1
400
trexgris
78,746,642
4,379,669
Get hierarchy context in a Strawberry custom field resolver
<h3>TL;DR</h3> <p>I need to access information from the &quot;parent&quot; of an object who's field I'm calculating in a custom resolver, but that information does not seem to be available during the resolver's execution.</p> <hr/> <p>Assuming I have 2 objects that have a many-to-many relation, describing which clients...
<python><graphql><strawberry-graphql>
2024-07-14 14:39:33
1
662
Nimrod Dolev
78,746,578
1,084,416
How to use standard tools to package and install a zipped python package of pyc files and a .pth file
<p>I have a Python package which I have zipped using <a href="https://docs.python.org/3/library/zipfile.html#pyzipfile-objects" rel="nofollow noreferrer"><code>zipfile.PyZipFile</code></a>, so I now have a <code>.zip</code> containing only <code>.pyc</code> files and sub-packages for a particular version of Python.</p>...
<python><build><python-packaging><pyproject.toml>
2024-07-14 14:06:38
0
24,283
Open AI - Opting Out
78,746,094
8,543,025
Plotly Express: Remove Trendline from Marginal Distribution Figures
<p>I'm looking for a &quot;clean&quot; way to remove the trendline from the marginal-distribution subplot created using plotly-express. I know it's a bit unclear, so please look at the following example:<br /> Generating some fake data:</p> <pre><code>np.random.seed(42) data = pd.DataFrame(np.random.randint(0, 100, (10...
<python><plotly>
2024-07-14 10:08:15
1
593
Jon Nir
78,745,907
2,604,247
Is There a Way to Expose a Plot Generated Using a Pandas Dataframe as a Jupyter Notebook as an App to the End User?
<h5>Current Workflow</h5> <p>Right now, me, as an ML engineer, am using a jupyter notebook to plot some pandas dataframes. Basically, inside the jupyter notebook, I am setting some hard-coded configurations like</p> <pre><code>k_1:float=2.3 date_to_analyse:str='2024-06-17' # 17th June region_to_analyse:str='montana' ....
<python><pandas><google-bigquery><jupyter-notebook><google-colaboratory>
2024-07-14 08:36:07
1
1,720
Della
78,745,757
6,017,833
Redisearch not working with wildcard prefix
<p>I am trying to understand why <code>index_test</code> works but <code>index_test_wildcard</code> does not work. The index created in the latter does not match to the records created within the function despite respecting the wildcard syntax. Any help would be appreciated. Thanks.</p> <pre class="lang-py prettyprint-...
<python><json><redis>
2024-07-14 07:11:47
1
1,945
Harry Stuart
78,745,568
4,130,242
Using scenedetect to spot subtle cut edits in a video?
<p>I'm trying to use the Scenedetect Python package to detect subtle cuts in a video. For example, I'm looking at this video:</p> <p><a href="https://www.youtube.com/watch?v=fNb_-Tmxq8Q" rel="nofollow noreferrer">https://www.youtube.com/watch?v=fNb_-Tmxq8Q</a></p> <p>I have downloaded the video and run the following on...
<python><video-processing>
2024-07-14 04:57:05
1
1,637
garson
78,745,394
10,082,415
Python/Regex: Finding a specific pattern to update and then placing it back in the original text
<p>I have a long file containing thousands of lines and a couple of samples are shown below:</p> <pre><code>\begin{align*} H_0 \amp : \mu_1 = \mu_2 = \mu_3 = \mu_4 = \mu_5 \\ H_1 \amp : \text{Some text} \\ H_2 \amp : \text{More text...} \\ \end{align*} \begin{table}[htb] \centering \begin{tabular}{cc} ...
<python><regex>
2024-07-14 02:28:55
2
1,003
M. Al Jumaily
78,745,180
383,958
Pytorch: matrices are equal but have different result
<p>How is this possible?</p> <pre><code>&gt;&gt;&gt; torch.all(w1 == w2) tensor(True) &gt;&gt;&gt; torch.all(i1 @ w1.T == i1 @ w2.T) tensor(False) </code></pre> <p>The matrices are all the same dtype, on the same device, etc:</p> <pre><code>&gt;&gt;&gt; i.dtype, w1.dtype, w2.dtype (torch.float32, torch.float32, torch.f...
<python><pytorch>
2024-07-13 23:18:44
1
1,438
Joel Burget
78,745,143
1,107,474
Error "ModuleNotFoundError: No module named 'pylibpcap'"
<p>I'm trying to use this Python libpcap library:</p> <p><a href="https://pypi.org/project/python-libpcap/" rel="nofollow noreferrer">https://pypi.org/project/python-libpcap/</a></p> <p>I have installed using:</p> <pre><code>sudo apt-get install libpcap-dev pip3 install python-libpcap </code></pre> <p>but when I run th...
<python><pip><libpcap>
2024-07-13 22:44:18
2
17,534
intrigued_66
78,744,986
4,427,375
How do you compile OpenCV with Python with CUDA Support on Rocky Linux 9?
<p>I am trying to build <a href="https://pypi.org/project/opencv-python/" rel="nofollow noreferrer">opencv-python</a> per the official instructions with support for CUDA so I can run SIFT. When I try to build with <code>pip wheel . --verbose</code> I get:</p> <pre><code> -- Configuring incomplete, errors occurred! T...
<python><opencv><python-wheel><sift>
2024-07-13 21:07:02
0
1,873
Grant Curell