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
79,002,929
1,471,980
how do you select the maximum value accross each row in pandas
<p>Hi have this data frame:</p> <pre><code>Server 1-Jun 6-Jun 1-jul Jul-10 ServerA 8 9 5 90 ServerB 100 10 9 90 </code></pre> <p>I need to create another column called maximumval and pick the maximum value from all of the months per Server:</p> <p>Resulting data frame need...
<python><pandas><dataframe><aggregation><rowwise>
2024-09-19 14:03:16
2
10,714
user1471980
79,002,911
5,392,822
pass variable number of arguments to python from shell script
<p>I have a very simple shell script which accepts 2 arguments after some processing pass these 2 arguments to python code. like below</p> <pre><code>arg1=$1 arg2=$2 #some processing... python3.6 abc.py $arg1 $arg2 </code></pre> <p>Now the requirement is my shell script will accept variable number of arguments and it s...
<python><bash><shell>
2024-09-19 13:58:21
1
360
Aniket
79,002,888
10,811,647
Python Selenium getting Error@chrome while using firefox
<p>I am getting this strange error:</p> <pre class="lang-bash prettyprint-override"><code>raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: Stacktrace: RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8 WebDriverError@chrome://remote/content/shared...
<python><selenium-webdriver>
2024-09-19 13:53:25
0
397
The Governor
79,002,774
2,800,918
How to create the cartesian product of a list of lists of tuples
<p>I'm trying to accomplish a cartesian product of a list of lists. The base elements are tuples. Something about the tuples seems to really throw <code>product</code> off. The more products I attempt the more it adds a rat's nesting of tuples.</p> <p>Here's my code</p> <pre><code>from itertools import product listOfL...
<python><python-3.x><cartesian-product>
2024-09-19 13:26:52
1
1,148
CAB
79,002,571
7,462,275
How to create, in a jupyter notebook, an Interactive 2D hystogram with 3D datas
<p>The number of occurrence of an event that depends of many parameters have been calculated. And I would like to create an interactive 2D histogram in a jupyter notebook.</p> <p>To keep things simple in this question, there are three parameters (<code>par1</code>,<code>par2</code>,<code>par3</code>). The 3D histogram ...
<python><matplotlib><jupyter-notebook><interactive>
2024-09-19 12:39:31
0
2,515
Stef1611
79,002,542
196,206
Cannot pass multiprocessing.Manager to process when using forkserver: cannot pickle 'weakref' object
<p>Sample code:</p> <pre class="lang-py prettyprint-override"><code>import multiprocessing def main(): multiprocessing.set_start_method('forkserver') with multiprocessing.Manager() as manager: proc = multiprocessing.Process(target=fun, args=('p1', manager)) proc.start() proc.join() def...
<python><python-3.x><multiprocessing>
2024-09-19 12:31:56
2
25,401
Messa
79,002,503
12,466,687
How to extract data from pdfs which are not in tables or containers into a column based table format in python?
<p>I am trying to convert my pdf data into structured table format data. I have tried bunch of options but none of them have been able to separate fields into columns of table format. I am able to do that using AI models like <code>LlamaParse</code> where fields get separated by <code>|</code> but unfortunately I cant ...
<python><parsing><pdf><python-tesseract><pdfplumber>
2024-09-19 12:22:34
0
2,357
ViSa
79,002,440
2,678,716
Update field in a DO SET UPDATE from a query result value
<p>I have the following query:</p> <pre><code>INSERT INTO table1 ( col1, col2, col3 ) VALUES ( %s, (SELECT id FROM table2 WHERE name = %s), %s, ) ON CONFLICT (fk_id) DO UPDATE SET col1 = %s, ***col2 = (SELECT id FROM table2 WHERE name = %s),*** col3 = %s WHERE EXISTS ( SELECT 1 FROM table1 WHERE fk_...
<python><postgresql><psycopg2>
2024-09-19 12:06:25
1
1,383
Rav
79,002,434
5,467,541
Kafka message compression not working (broker level)
<p>I added compression for log messages on broker level compression.type=zstd on all three brokers with no other changes on the broker level or producer level.</p> <p>When I tried to read messages from my python client (Consumer) for kafka, I started getting timeouts. Consumer didn't respond with any messages from that...
<python><apache-kafka><compression><kafka-consumer-api>
2024-09-19 12:05:14
1
595
Abhinav Ralhan
79,002,206
6,930,340
Concatenate polars dataframe with columns of dtype ENUM
<p>Consider having two <code>pl.DataFrame</code>s with identical schema. One of the columns has <code>dtype=pl.Enum</code>.</p> <pre><code>import polars as pl enum_col1 = pl.Enum([&quot;type1&quot;]) enum_col2 = pl.Enum([&quot;type2&quot;]) df1 = pl.DataFrame( {&quot;enum_col&quot;: &quot;type1&quot;, &quot;value&...
<python><python-polars>
2024-09-19 11:02:26
1
5,167
Andi
79,002,170
19,077,881
Ubuntu 22.04 syntax warning importing Pandas
<p>I have installed Python 3.12 in Ubuntu 22.04 alongside the system Python 3.10. It works as expected as do packages such as Numpy. However after installing Pandas 2.2.2 the line <code>import pandas as pd</code> produces the warning message below. Pandas still then works as expected with Python 3.12. Why does this hap...
<python><pandas><ubuntu>
2024-09-19 10:54:03
1
5,579
user19077881
79,002,136
14,715,428
tqdm not working within another library, but working fine directly in Jupyter Notebook
<p>In my Jupyter Notebook environment, everything works correctly with using <code>tqdm</code> and its progress bar directly. For example, the following code:</p> <pre><code>for i in tqdm(range(100000)): pass </code></pre> <p>is correctly displayed:</p> <p><a href="https://i.sstatic.net/e8OhMGHv.png" rel="nofollow ...
<python><jupyter-notebook><tqdm>
2024-09-19 10:40:58
0
349
TayJen
79,002,102
13,921,816
Folium SideBySideLayers: Markers Not Displaying Correctly on Separate Layers
<p>I’m trying to create a map using the Folium library in Python, where I want to use the SideBySideLayers plugin to compare two different tile layers. Each layer should have its own set of markers, but I’m facing an issue where the markers are visible on both layers, instead of being restricted to their respective lay...
<python><visualization><folium>
2024-09-19 10:34:42
1
354
Mathieu P.
79,001,858
7,959,614
simulate markov chain using networkx and numpy
<p>My goal is to simulate a Markov chain using <code>networkx</code> and <code>numpy</code>. I write the following code</p> <pre><code>import numpy as np import networkx as nx states = [ 'distance', 'strike', 'knockout' ] transition_matrix = np.array([ [0.85, 0.15, 0], [0.98, 0, 0.02], [0, 0...
<python><numpy><networkx><markov-chains>
2024-09-19 09:32:36
1
406
HJA24
79,001,527
6,449,740
how create new column or update column inside a dataframe?
<p>Good morning eveyone</p> <p>I have a question today, that i don't know exactly how to do.</p> <p>Having a dataframe, i need create columns dynamically, and those column will contein a set of validations that i have to do, like: validate number os characters, see if there is strange characters inside a description fi...
<python><dataframe><apache-spark><pyspark><aws-glue>
2024-09-19 08:07:15
0
545
Julio
79,000,901
5,437,264
AVIF for Django-imagekit?
<p>Let’s say this is my code, powered by django-imagekit.</p> <pre><code> from django.db import models from imagekit.models import ImageSpecField from imagekit.processors import ResizeToFill class Profile(models.Model): avatar = models.ImageField(upload_to='avatars') avatar_thumbnail = ImageSpecField(source='a...
<python><django><django-imagekit><avif>
2024-09-19 04:44:55
1
368
ONMNZ
79,000,754
5,049,813
How to type hint a dynamically-created dataclass
<p>I hate writing things twice, so I came up with a decent way to not have to write things twice. However, this seems to break my type-hinting:</p> <pre class="lang-py prettyprint-override"><code>from enum import Enum from dataclasses import make_dataclass, field, dataclass class DatasetNames(Enum): test1 = &quot;...
<python><python-typing><python-dataclasses>
2024-09-19 03:25:17
1
5,220
Pro Q
79,000,554
6,449,740
How convert a list into multiple columns and a dataframe?
<p>i have a challenge today, is: Having a list of s3 paths, inside a list, split this and get a dataframe with one column with the path and a new column with just the name of the folder.</p> <p>my list have the next content:</p> <pre><code>raw/ingest_date=20240918/eventos/ raw/ingest_date=20240918/llamadas/ raw/ingest_...
<python><dataframe><apache-spark><pyspark><aws-glue>
2024-09-19 00:59:35
1
545
Julio
79,000,230
6,357,916
Unable to return a boolean variable from Pytorch Dataset's __get_item__
<p>I have a pytorch <code>Dataset</code> subclass and I create a pytorch <code>DataLoader</code> out of it. It works when I return two tensors from DataSet's <code>__getitem__()</code> method. I tried to create minimal (but not working, more on this later) code as below:</p> <pre><code>import torch from torch.utils.dat...
<python><python-3.x><machine-learning><pytorch>
2024-09-18 21:33:47
1
3,029
MsA
78,999,991
1,909,206
Unable to publish python packages to Gitlab registry (due to 401 Unauthorized) using Poetry from within a CICD Job
<p>I'm using the following three commands in my publish job to (attempt) push Python packages to the Gitlab registry. However, I get 401's and am unable to do so.</p> <p>I'm using Poetry 1.8.3 in a python:3.12 runner image. I'm using Gitlab SAAS (not self-hosted)</p> <pre><code> - poetry config repositories.gitlab &...
<python><gitlab-ci><python-poetry>
2024-09-18 19:57:10
1
672
geudrik
78,999,903
1,601,580
How do I print the arguments passed to a function when using Python Fire?
<p>I'm using the fire library in Python to create a simple command-line interface (CLI). My setup is as follows:</p> <pre class="lang-py prettyprint-override"><code>import fire def main(a): print('hi') if __name__ == '__main__': fire.Fire(main) </code></pre> <p>When I run the script like this:</p> <pre class...
<python><python-fire>
2024-09-18 19:26:00
2
6,126
Charlie Parker
78,999,885
22,407,544
Django `collecstatic` returns `[Errno 13] Permission denied: '/code/static/admin/js/vendor/select2/i18n/pl.6031b4f16452.js.gz'`
<p>I run my django app in Docker. I recently tried running <code>collecstatic</code> and instead was given this error code. Not sure what it means or what to do:</p> <pre><code>&gt;docker-compose exec web python manage.py collectstatic </code></pre> <pre><code>Traceback (most recent call last): File &quot;/code/manag...
<python><django>
2024-09-18 19:19:41
1
359
tthheemmaannii
78,999,867
14,954,262
Django - change form prefix separator
<p>I'm using form <code>prefix</code> to render the same django form twice in the same template and avoid identical fields id's.</p> <p>When you do so, the separator between the prefix and the field name is '-', I would like it to be '_' instead.</p> <p>Is it possible ?</p> <p>Thanks</p>
<python><html><django><prefix><separator>
2024-09-18 19:13:47
1
399
Nico44044
78,999,848
6,555,196
Fixing yaml indentation with python
<p>I'm manipulating existing yaml file (CloudFormation template) and copying needed resources into a new file.</p> <p>The thing is, I'm getting part of the resource in a new line - not according to the correct indentation.<br /> It seems the 3rd line is not adhering to the indentation configuration.</p> <p>I've checked...
<python><amazon-web-services><aws-cloudformation>
2024-09-18 19:06:49
1
305
soBusted
78,999,807
4,996,797
How to activate plt.show() when creating axes without pyplot in matplotlib?
<p>I have a script like this which when executed opens up a new window with the figure.</p> <pre class="lang-py prettyprint-override"><code>import matplotlib.pyplot as plt fig = plt.Figure() # ax = fig.add_axes(rect=(0.1, 0.0, 0.9, 1.0)) # does not open a new window ax = fig.add_subplot() # works plt.show() </code><...
<python><matplotlib><plot><visualization><figure>
2024-09-18 18:54:21
1
408
Paweł Wójcik
78,999,789
2,215,904
Tkinter grid manager height/width nonconsistent
<p>I have issue with tkinter grid manager consistency. I have specified columnconfigure so left part have 6, then one column is 1 as delimiter and then on right side (keyboard) the width is 3. As I understand left side should be twice size of right side. But on screen isn't. The haight have similar problem. All rows ar...
<python><tkinter><grid><row><configure>
2024-09-18 18:49:21
1
460
eSlavko
78,999,687
4,436,517
Polars make all groups the same size
<h1>Question</h1> <p>I'm trying to make all groups for a given data frame have the same size. In <em>Starting point</em> below, I show an example of a data frame that I whish to transform. In <em>Goal</em> I try to demonstrate what I'm trying to achieve. I want to group by the column <code>group</code>, make all groups...
<python><python-polars>
2024-09-18 18:22:22
4
1,159
rindis
78,999,623
825,227
Return the index of a date match
<p>I'm drawing a blank even though it seems straightforward.</p> <p>I have a list of dates in an index:</p> <pre><code>book_df.index Out[44]: DatetimeIndex(['2023-08-13 15:10:47.284558', '2023-08-13 15:10:48.005322', '2023-08-13 15:10:48.005953', '2023-08-13 15:10:49.022438', '2023-08-13 ...
<python><pandas>
2024-09-18 18:06:34
2
1,702
Chris
78,999,491
1,471,980
how do you summarize percentage usage data in pandas data frame groupby a column
<p>I need to count the occurunce of percentage usage by Server name. I have this data frame.</p> <pre><code>df Server Bandwidth 1-Jun 6-June 12-Jun 1-Jul ServerA 10000 5000 6000 7500 8000 ServerB 100000 60000 80000 75000 80000 ServerC 20000 5000 6000 7500 8000 Serv...
<python><pandas>
2024-09-18 17:27:18
2
10,714
user1471980
78,999,483
3,284,297
Extracting data of this xml to Python dataframe
<p>I cannot get the extraction of this xml data to dataframe to work properly. This is my xml sample. In reality I have multiple stacks of &quot;Entity&quot; which represent one line of data in the desired result. To save space I only pasted one instance of &quot;Entity&quot; here:</p> <pre><code>&lt;EntityCollection&g...
<python><pandas><xml>
2024-09-18 17:25:48
2
423
Charlotte
78,999,363
5,086,255
django admin Interdependent validation of formsets
<p>i have two inlines in admin models</p> <pre><code>class AdminModel(admin.ModelAdmin): ... inlines = [inline1, inline2] form = AdminModelForm model =model class inline1(admin.TabularInline): form = inline1form model = inline1model class inline2(admin.TabularInline): form = inline2form...
<python><django><django-forms><django-admin><formset>
2024-09-18 16:51:04
1
11,372
sahasrara62
78,999,309
3,486,684
In Visual Studio Code, how can I rename a variable in Python and also update its occurrences in ReST formatted documentation?
<p>Suppose I have:</p> <pre class="lang-py prettyprint-override"><code>class Hello: &quot;&quot;&quot;An example class.&quot;&quot;&quot; world: str &quot;&quot;&quot;This is the only field on :py:class:`Hello`.&quot;&quot;&quot; </code></pre> <p>It is documented using the <a href="https://www.sphinx-doc.org/en/m...
<python><visual-studio-code><python-sphinx><restructuredtext>
2024-09-18 16:33:48
1
4,654
bzm3r
78,999,284
8,067,642
Pop specific item from Python set and get default if not exists
<p>Is there a simple method, maybe a one-liner, to pop an item from Python set, and get default value if it does not exist?</p> <p>It could be done in four lines of code and two hash table lookups:</p> <pre class="lang-py prettyprint-override"><code>def pop_default(coll: set, v, default=None): if v not in coll: ...
<python><set>
2024-09-18 16:27:44
1
338
makukha
78,999,229
1,173,674
CMake Python execv-based wrapper fails with `CMake Error: Could not find CMAKE_ROOT !!!`
<p>I want to write a Python wrapper for CMake, but even the simplest of wrappings fails:</p> <pre class="lang-py prettyprint-override"><code>#!/usr/bin/env python import os import sys os.execvp(&quot;cmake&quot;, sys.argv) # or 'sys.argv[1:]', both fail </code></pre> <p>Running this Python script with e.g. <code>./pycm...
<python><cmake>
2024-09-18 16:11:19
1
9,358
anol
78,999,116
23,260,297
Create Pivot table and add additional columns from another dataframe
<p>Given two identically formatted dataframes:</p> <p>df1</p> <pre><code>Counterparty Product Deal Date Value foo bar Buy 01/01/24 10.00 foo bar Buy 01/01/24 10.00 foo bar Sell 01/01/24 10.00 foo bar Sell 01/01/24 10.00 fi...
<python><arrays><pandas><dataframe>
2024-09-18 15:43:26
2
2,185
iBeMeltin
78,999,011
615,525
GeoText Package Not Identifying Cities at All in my Array
<p>Using Python, I have an Array that Stores All the Words in my string, which I Loop through:</p> <pre><code> #Loop through Title String Array and have GeoText identify the City for i in range(len(title_str_array)): places = GeoText(title_str_array[i]) print(places.cities) </code></pre> ...
<python><geotext>
2024-09-18 15:19:50
1
353
user615525
78,999,010
695,134
json2html not outputting as described, want to remove generated outer table
<p>I'm using json2html (python) and the outputs are not matching what is shown at the website. <a href="https://pypi.org/project/json2html/" rel="nofollow noreferrer">https://pypi.org/project/json2html/</a></p> <p>Basically, using the site example:</p> <pre class="lang-py prettyprint-override"><code>from json2html impo...
<python><json2html>
2024-09-18 15:19:35
1
6,898
Neil Walker
78,998,998
10,735,143
Could not connect to dockerized service which registered in eureka server
<p>Here is eureka_client.init:</p> <pre><code>eureka_client.init( eureka_server=&quot;http://&lt;EUREKA_SERVER_IP&gt;:8070/eureka&quot;, app_name=&quot;&lt;EUREKA_APPNAME&gt;&quot;, instance_port=&quot;&lt;API_PORT&quot;, instance_ip=&quot;&lt;MACHINE_IP&gt;&quot;, ) </code></pre> <p>At the first my fas...
<python><docker><netflix-eureka>
2024-09-18 15:16:34
1
634
Mostafa Najmi
78,998,888
11,267,783
Matplotlib issue with mosaic and colorbars
<p>I am facing a strange behaviour with my code.</p> <p>I don't understand why the subplot at the top left has a different space between the imshow and the colorbar compared to the subplot at the top right. And also I don't understand why the colorbar at the bottom is not aligned with the one at the top right.</p> <p>C...
<python><matplotlib>
2024-09-18 14:53:41
2
322
Mo0nKizz
78,998,782
16,525,263
How to handle accented letter in Pyspark
<p>I have a pyspark dataframe in which I need to add &quot;translate&quot; for a column. I have the below code</p> <pre><code>df1 = df.withColumn(&quot;Description&quot;, F.split(F.trim(F.regexp_replace(F.regexp_replace(F.lower(F.col(&quot;Short_Description&quot;)), \ r&quot;[/\[/\]/\{}!-]&quot;, ' '), ' +', ' ...
<python><apache-spark><pyspark>
2024-09-18 14:33:21
1
434
user175025
78,998,619
5,756,179
Why this does not show any error during initial checks?
<p>The following is a derived excerpt from the cookiejar.py file for FileCookieJar and MozillaCookieJar implementation. <a href="https://github.com/python/cpython/blame/main/Lib/http/cookiejar.py#L1802" rel="nofollow noreferrer">https://github.com/python/cpython/blame/main/Lib/http/cookiejar.py#L1802</a></p> <pre><code...
<python><compilation>
2024-09-18 13:58:44
1
582
DaiCode-1523
78,998,389
1,308,807
Matplotlib warning due to multiple versions: how to handle this in Ubuntu 24?
<p>So Ubuntu 24LTS recently came out and it uses Python3.12 as the systemwide python version. Starting from 23, we now cannot really &quot;play&quot; with the default installation: we cannot install python3.12 packages locally with pip. That is ok, it is safer.</p> <p>I installed python3.11 and I want to use it locally...
<python><matplotlib><ubuntu>
2024-09-18 13:07:48
0
1,075
Chicoscience
78,998,245
9,703,039
VSCode, Pylance how to get proper help popup?
<p>I enhanced a class by adding some few methods from another class (Jira's class from <a href="https://github.com/atlassian-api/atlassian-python-api/blob/master/atlassian/jira.py#L374" rel="nofollow noreferrer">atlassian-python</a> package) My class is called <code>JiraExtended</code>.<br /> Original methods from the ...
<python><visual-studio-code><pylance>
2024-09-18 12:37:52
1
339
Odyseus_v4
78,998,174
4,489,082
5 minute OHLC data to hourly at quarter past the hour
<p>I have OHLC data at 5 minute interval. I want to convert it to hourly, but I want those values at quarter past the hour, meaning between 9:15-10:15, 10:15-11:15, 11:15-12:15 and so forth. The following code can do it between the o'clock measurements. How can I modify the code to get the behaviour I want?</p> <pre cl...
<python><pandas><ohlc>
2024-09-18 12:20:02
1
793
pkj
78,998,074
8,040,287
Pattern matching in python to catch enum-flag combination
<p>When using <a href="https://docs.python.org/3/library/enum.html#enum.Flag" rel="nofollow noreferrer">Flags</a> in Python, pattern matching only catch direct equality and not inclusion. It can be circumvented with a condition and an <code>in</code> however, provided you catch the <code>0</code> flag before if you con...
<python><pattern-matching><enum-flags>
2024-09-18 11:57:42
1
1,215
JackRed
78,998,063
1,005,423
How to avoid the "Duplicate Module Import Trap" in python?
<p>I recently encountered a perplexing issue regarding module imports in Python, particularly with the way instances of classes can be duplicated based on different import styles.</p> <p>I had to fight to be able to reproduce. It was not so easy.</p> <p><strong>Main issue</strong></p> <p>According to the import style, ...
<python><python-import><python-module>
2024-09-18 11:54:42
1
329
Nico
78,998,041
17,721,722
PostgreSQL COPY command is much slower locally compared to remote server with identical specs
<p>I'm encountering a performance issue with the PostgreSQL <code>COPY</code> command when running it locally. Specifically, my .csv files are on my local machine, and I am pushing them into a remote PostgreSQL server using COPY. Both my remote backend app server and my local PC have identical specs (both with SSDs, si...
<python><database><postgresql><multiprocessing><psycopg2>
2024-09-18 11:47:32
1
501
Purushottam Nawale
78,997,912
10,829,044
Pandas create % and # distribution list in descending order for each group
<p>I have a pandas dataframe like as below</p> <pre><code>data = { 'cust_id': ['abc', 'abc', 'abc', 'abc', 'abc', 'abc', 'abc', 'abc', 'abc', 'abc'], 'product_id': [12, 12, 12, 12, 12, 12, 12, 12, 12, 12], 'purchase_country': ['India', 'India', 'India', 'Australia', 'Australia', 'Australia', 'Australia', 'A...
<python><pandas><dataframe><list><group-by>
2024-09-18 11:21:25
2
7,793
The Great
78,997,869
5,999,591
error in PyTorch dataloader with num_workers>0 in VSC under WSL
<p>I want to utilize my GPU by adjusting the workers number, but I have a problem with the number of workers &gt; 0.</p> <p><code>test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False, num_workers=0)</code> - no problem<br /> <code>test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False, num_w...
<python><pytorch><tf.keras><pytorch-dataloader>
2024-09-18 11:11:41
1
581
Kalin Stoyanov
78,997,729
2,791,346
Disable stoping the container after stop debuging in Pycharm
<p>I set up the debugging for my Django app that is inside the docker container in PyCharm.</p> <p>I did it with:</p> <ul> <li>a new interpreter via Docker Compose</li> <li>created the new run configuration Django Server.</li> </ul> <p>My settings are:</p> <ul> <li>Interpreter: new docker-compose interpreter</li> <li>h...
<python><django><debugging><docker-compose><pycharm>
2024-09-18 10:31:40
0
8,760
Marko Zadravec
78,997,621
2,546,099
Best practice for creating new release in gitlab CI/CD-pipeline
<p>I have a python-project on gitlab, with an integrated pipeline to both run tests, and if these tests are successful and are run on the main branch, the documentation and a wheel file should be build. Now, however, I would like to expand this by automatically creating releases for new versions and compiling the proje...
<python><git><gitlab><cicd>
2024-09-18 10:01:31
1
4,156
arc_lupus
78,997,541
9,542,989
Slack SocketModeClient - Respond Only to Messages That Mention App in Channels
<p>I am attempting to create Slack bot using <code>SocketModeClient</code> that only responds to messages in channels where it has explicitly been mentioned. My initial thought process was to do something as follows:</p> <pre><code> socket_mode_client = SocketModeClient( # This app-level token will be used o...
<python><slack><slack-api>
2024-09-18 09:41:31
1
2,115
Minura Punchihewa
78,997,523
17,519,895
How to concatenate a list of byte audio data (from frontend) into a single WAV file?
<h3>Body:</h3> <p>I am working with two types of audio data, both in byte form. One type works fine with audio processing libraries like <code>pydub</code> and <code>AudioSegment</code>, allowing me to concatenate and export the audio as a WAV file. However, the second type of audio data, which I receive from the front...
<python><audio><wav>
2024-09-18 09:37:03
0
421
Aleef
78,997,513
1,540,660
Why is there "TypeError: string indices must be integers" when using negative indices or slices in string formatting?
<p>I would like to understand why this works fine:</p> <pre><code>&gt;&gt;&gt; test_string = 'long brown fox jump over a lazy python' &gt;&gt;&gt; 'formatted &quot;{test_string[0]}&quot;'.format(test_string=test_string) 'formatted &quot;l&quot;' </code></pre> <p>Yet this fails:</p> <pre><code>&gt;&gt;&gt; 'formatted &q...
<python><formatting>
2024-09-18 09:34:06
2
336
Art Gertner
78,997,232
8,078,237
How to prevent scientific notation when exporting a pandas dataframe to csv?
<p>I read and modify excel files with pandas and export them as csv at the end. One column can contain all kinds of text and sometimes a numeric string like &quot;0123456789&quot;, note the leading zero. That leading zero seems to cause excel to autoformat those cells and display them in scientific format. I do not wan...
<python><excel><pandas><csv>
2024-09-18 08:24:13
1
317
jfordummies
78,997,194
4,690,023
Create discord bot buttons programmatically
<p>In my python discord bot I can define a <code>discord.ui.View</code> like this:</p> <pre><code>class ConfirmResetView(discord.ui.View): def __init__(self, cog): super().__init__(timeout=60) self.cog = cog # Reference to the cog for resetting the event self.answer = None # To store the u...
<python><discord.py>
2024-09-18 08:14:18
1
1,870
Luca
78,997,191
17,082,611
FastAPI app works locally, but /blogs endpoint causes redirect loop on AWS Lambda deployment
<p>I’ve developed a FastAPI app and deployed it on AWS Lambda as a <code>.zip</code> archive. Locally, when I run:</p> <pre class="lang-bash prettyprint-override"><code>uvicorn src.main:app --reload </code></pre> <p>I can access the <code>/blogs</code> endpoint (<code>http://127.0.0.1:8000/blogs</code>) and it returns ...
<python><amazon-web-services><aws-lambda><fastapi><redirect-loop>
2024-09-18 08:13:57
2
481
tail
78,997,019
6,074,182
In Python 3.12, why does 'Öl' take less memory than 'Ö'?
<p>I just read <a href="https://peps.python.org/pep-0393/" rel="noreferrer">PEP 393</a> and learned that Python's <code>str</code> type uses different internal representations, depending on the content. So, I experimented a little bit and was a bit surprised by the results:</p> <pre><code>&gt;&gt;&gt; sys.getsizeof('')...
<python><string><python-internals><python-3.12>
2024-09-18 07:30:44
1
2,445
Aemyl
78,996,929
7,916,348
Python recursion limits and functools.cache
<p><code>sys.setrecursionlimit</code> doesn't appear to affect functions declared using the <code>@cache</code> decorator:</p> <pre class="lang-py prettyprint-override"><code>from functools import cache import sys sys.setrecursionlimit(100000) @cache def f1(n): if n == 1: return 1 return n * f1(n-1) mycache ...
<python><decorator><stack-overflow><functools>
2024-09-18 07:02:12
0
792
Zachary Barbanell
78,996,709
9,097,114
Multipage PDF to single image with multi page conversion
<p>I am trying to convert a multipage PDF to a single image.</p> <p>From my code, I can only generate a multi(list of) images.</p> <p>How can we create a single image with a multi page from PD?</p> <p>Below is my code:</p> <p>**</p> <pre><code>import requests from pdf2image import convert_from_path url = 'https://educa...
<python><pdf>
2024-09-18 05:48:22
3
523
san1
78,996,541
4,701,852
Python Shapely - Selection of a given part of a Geopandas geometries
<p>I've got a <strong>geopandas</strong> (EPSG:4326) that when I plot, this is the result (a road intersection):</p> <p><a href="https://i.sstatic.net/jtJCpJ4F.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jtJCpJ4F.png" alt="enter image description here" /></a></p> <p>What I'm trying to achieve is to &...
<python><shapely>
2024-09-18 04:23:23
1
361
Paulo Henrique PH
78,996,443
10,461,632
How can I get the timezone based on the latitude and longitude using python?
<p>I want to get the timezone of a specific latitude and longitude, but formatted in a specific way. For example, instead of returning <code>America/New_York</code>, I'd like <code>Eastern</code>/<code>Eastern Standard Time</code>/<code>EST</code>. I tried to search the documentation for <a href="https://timezonefinder...
<python><python-3.x><timezone>
2024-09-18 03:16:20
0
788
Simon1
78,995,649
327,258
New to fifo in linux, reading with python produces gibberish? (binary)
<p>I am trying to grab some sensor data so I can toss it into a influxdb. We have very old sensors writing this out to a server via a fifo on that server. I know I can read it (made a quick program):</p> <pre><code># reader.py import os FIFO = '/var/axis/sensor1' FIFO_PATH = FIFO fifo_path = FIFO print(&quot;about...
<python><linux><fifo>
2024-09-17 20:08:07
2
3,856
Codejoy
78,995,607
1,182,299
How to calculate the center-line or baseline of a polygon
<p>I work on a segmentation model for historical documents. My dataset has the text lines as polygons but for a usable model training I need also the center-lines or baselines of the polygons.</p> <p>As an example, these are the coordinates of the line as tuples of polygons:</p> <pre><code>603,1220 600,1288 687,1304 69...
<python><polygon><shapely><baseline>
2024-09-17 19:55:45
2
1,791
bsteo
78,995,579
13,606,345
Is Python multiprocessing.Lock also thread safe?
<p>I am wondering if Lock imported from multiprocessing module is also thread safe.</p>
<python><multithreading><multiprocessing><thread-safety>
2024-09-17 19:48:11
0
323
Burakhan Aksoy
78,995,550
267,364
How to setup a celery worker to consume high priority tasks only?
<p>Celery allow to route tasks by task-name to avoid a load from a kind of task to delay tasks from other kinds.</p> <p>Celery also handle priority with manual scale (often 0 : top priority -&gt; 10 : lowest priority).</p> <p>Priority can be set when you queue the task</p> <pre class="lang-py prettyprint-override"><cod...
<python><celery>
2024-09-17 19:36:29
0
6,477
christophe31
78,995,526
5,468,905
Cannot get pylance to properly typecheck variable in extended class
<p>Here's my setup simplified:</p> <pre class="lang-py prettyprint-override"><code>from abc import ABC from typing import TypeVar from pydantic import BaseModel _M = TypeVar(&quot;_M&quot;, bound=BaseModel) class A(BaseModel): a = 1 b = 2 c = 3 class Base(ABC): cfg_model: type[_M] def __init__(s...
<python><python-typing><pyright>
2024-09-17 19:25:15
0
314
HYBRID BEING
78,995,452
3,670,765
SIGFPE while importing numpy into Python3
<p>I ran into a very odd issue. If I have the following C and Python codes:</p> <pre class="lang-c prettyprint-override"><code>#include &lt;Python.h&gt; int main(int argc, char *argv[]) { Py_Initialize(); FILE* to_run_script= fopen(&quot;script.py&quot;, &quot;r&quot;); if (to_run_script != NULL) PyRun_Simpl...
<python><c><numpy><sigfpe>
2024-09-17 19:00:42
0
973
LaszloLadanyi
78,995,379
15,848,470
How can I map a field of a polars struct from values of another field `a`, to values of another field `b`?
<p>I have a Polars dataframe with these columns. I want to replace the values in each list in column C with the corresponding value in column b, based on the position the value in c has in column a.</p> <pre><code>┌────────────────────┬─────────────────────────────────┬────────────────────┐ │ a ┆ b ...
<python><dataframe><vectorization><python-polars>
2024-09-17 18:38:35
1
684
GBPU
78,995,189
2,276,054
CP-SAT | OR-Tools: Select max. 5 out of 10 total options?
<p>I have an optimization problem where I need to pick max. 5 out of 10 available options according to different criteria. I was wondering how to encode this constraint. Is any of the 3 alternative versions below better/faster than the others? If not, I would go with the first one, as it is the most concise...</p> <pre...
<python><or-tools><cp-sat>
2024-09-17 17:35:03
1
681
Leszek Pachura
78,995,179
22,407,544
What is the best way to handle potentially large file uploads in django?
<p>I've been reading the django docs and posts here on stackoverflow but still not sure how to. So far this is my code:</p> <p>forms.py:</p> <pre><code>def validate_file(file): # Validate if no file submitted if not file: #raise ValidationError(&quot;No file submitted&quot;) raise ValidationErro...
<python><django>
2024-09-17 17:31:29
0
359
tthheemmaannii
78,994,944
4,560,685
Snowflake/ Snowpark "import sklearn" results in "no module found."
<p>I'm using a python worksheet in Snowflake.</p> <p>When I got to information_schema.packages, scikit-learn is clearly there and installed.</p> <p>But when I reference <code>'sklearn'</code> (don't really understand where this full-name vs. shortened name comes from, but sklearn is obviously the reference to scikit-le...
<python><scikit-learn><snowflake-cloud-data-platform>
2024-09-17 16:14:07
2
983
user45867
78,994,681
3,458,788
Is it possible to install spaCy models using a different C++ compiler
<p>I am trying to install a spaCy model:</p> <pre><code>pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.0.0/en_core_web_sm-3.0.0.tar.gz </code></pre> <p>and getting the following error:</p> <pre><code>error: Microsoft Visual C++ 14.0 or greater is required. Get it with &quot;Mic...
<python><c++><spacy>
2024-09-17 15:09:20
0
515
cdd
78,994,612
4,706,952
Adjust console width to print the whole Pandas dataframe
<p>When printing to the console in Python I get output like:</p> <pre><code> Körpergrösse (cm) ... Motivation (1-10) Körpergrösse (cm) 1.000000 ... 0.226576 Schuhgrösse 0.710021 ... 0.096692 Alter (Jahre) -0.206736 ... 0.2037...
<python><pandas>
2024-09-17 14:50:42
1
7,517
symbolrush
78,994,566
9,846,358
How to Fetch GraphQL JSON Data from a URL in Python?
<p>I am trying to fetch GraphQL data from the URL:</p> <blockquote> <p><code>https://URL</code></p> </blockquote> <p>I’ve tried using Python’s requests library to make a POST request, but I’m not sure how to structure the request to get the desired JSON data.</p> <p>Here’s what I’ve tried so far:</p> <pre><code>import ...
<python><json><python-requests><graphql>
2024-09-17 14:37:00
1
797
Mary
78,994,516
32,043
How to initialize db connection in FastAPI with lifespan events?
<p>I would like to initialize a DB connection for my FastAPI application and tried to follow the tutorial for <a href="https://fastapi.tiangolo.com/advanced/events/#lifespan" rel="nofollow noreferrer">Lifespan Events</a>.</p> <p>I set up a lifecycle function and plugged it into my app and within the function, the varia...
<python><fastapi>
2024-09-17 14:23:16
2
24,231
guerda
78,994,503
6,751,456
django StreamingHttpResponse to return large files
<p>I need to get pdf files from s3 and return the same file to the frontend.</p> <pre><code>def stream_pdf_from_s3(request, file_key): s3_client = boto3.client('s3') try: response = s3_client.get_object(Bucket=settings.AWS_STORAGE_BUCKET_NAME, Key=file_key) pdf_stream = response['Body'] ...
<python><django><large-files><streaminghttpresponse>
2024-09-17 14:20:29
0
4,161
Azima
78,994,467
12,466,687
Unable to concatenate dataframes in streamlit
<p>I am trying to concatenate all the <code>dataframes</code> which are starting with <code>user_</code> string in the streamlit but have been getting error.</p> <p>sample code:</p> <pre><code>import streamlit as st import pandas as pd st.set_page_config(page_title=&quot;Science&quot;, layout='wide...
<python><pandas><dataframe><streamlit>
2024-09-17 14:12:29
1
2,357
ViSa
78,994,274
12,466,687
how to panda concatenate on list with string dataframe names?
<p>This may sound silly but I have <code>list</code> containing <strong>dataframe names</strong> and I am trying to <strong>concatenate</strong> those <strong>dataframes</strong> based on <strong>for loop</strong> or <strong>list comprehension</strong> or just <code>pd.concat()</code> them.</p> <p>Code sample:</p> <pre...
<python><pandas><dataframe><concatenation>
2024-09-17 13:24:00
2
2,357
ViSa
78,994,224
587,680
Register Hook to Intermediate Nodes in PyTorch
<p>Imagine you have something simple like this:</p> <pre class="lang-py prettyprint-override"><code>import torch x = torch.tensor([4.0], requires_grad=True) y = torch.tensor([2.0], requires_grad=True) output = x * y + x / y grad_x = torch.ones_like(output) torch.autograd.grad(output, x, grad_outputs=grad_x) </code></...
<python><pytorch>
2024-09-17 13:10:51
1
532
xotix
78,994,156
9,189,389
facet figure - polynomial + linear in Altair
<p>I want to make a facet figure with Linear and Polynomial regression in Altair. Stacking together scatter and regression plots seems understandable. However, adding additional polynomial analysis seems problematic. I cannot display the result. I was trying to go around by making a degree list for 1, 3, and 5 as in Al...
<python><altair><polynomials>
2024-09-17 12:55:19
1
464
Luckasino
78,993,852
2,155,362
How to load config.json file which define by myself?
<p>My work dir like below:</p> <pre><code>base--- |--- dir1 | |---test2.py |--- public.py |--- config.json |--- test1.py </code></pre> <p>In public.py, I coded like below:</p> <pre><code>def getCfg(key): with open(&quot;config.json&quot;, 'r',encoding='utf-8') as f: c...
<python>
2024-09-17 11:32:50
1
1,713
user2155362
78,993,769
2,397,542
Deleting an Azure Loadbalancer Frontend IP configuration from python?
<p>I'm writing something to clean up our old Azure resources, and one thing that comes up from time to time is public-ips still bound to a kubernetes-created loadbalancer even after the Ingress was deleted.</p> <p>Using the azure CLI, I can get the public IP, find the ipConfiguration from that, which is used to name th...
<python><azure><network-programming><azure-sdk>
2024-09-17 11:07:00
1
832
AnotherHowie
78,993,417
4,432,498
Mapper class between API and DB field properties
<p>I would like to implement a kind of mapper between db data and some other data like obtained from the response of API.</p> <p>The expected behavior is following:</p> <pre><code>class IData: a: str = ('db_a', 'type_a') b: str = ('db_b', 'type_b') c: str = ('db_c', 'type_c') class MyData(IData): a = '...
<python><database><mapping>
2024-09-17 09:32:35
2
550
Anton
78,993,284
14,202,481
How to improve pandas DF processing time on different combinations of calculated data
<p>I got a big dataset, something like 100 K or 1 mil rows, and I got a function that makes vector calculations that take 0.03 sec. Now all my columns before the process can be the same for every iteration. I want to calculate the 2^n combinations of conditions I make. So currently it will take me 2^n * 0.03 s to run i...
<python><pandas><algorithm><numpy>
2024-09-17 08:56:29
3
557
mr_robot
78,993,267
448,317
Calling QDialog.reject() has no effect - why? How do I close my dialog when certain conditions are met?
<p>Calling <code>QDialog.reject()</code> has no effect. What am I missing?</p> <pre class="lang-py prettyprint-override"><code>from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QDialog, QVBoxLayout class MyDialog(QDialog): def __init__(self): super().__init__() print('MyDialog cr...
<python><qt><pyqt><pyside>
2024-09-17 08:51:58
0
864
Troels Blum
78,993,127
6,672,026
Vs-code unable to import modules modules load
<p>I'm opening the same python project in pycharm and everything is working well opening same folder on vs code with same interpreter I'm getting error 'Unable to import' on local modules in the project what do i miss</p> <p>Example tree</p> <pre><code>MyFile.py │ ├── csv (standard library) ├── io (standard library) ├─...
<python><visual-studio-code><import><python-import><python-module>
2024-09-17 08:16:49
3
465
Michael Gabbay
78,992,703
10,200,497
What is the best way to filter groups by conditionally checking the values of the first row of each group only?
<p>This is my DataFrame:</p> <pre><code>import pandas as pd df = pd.DataFrame( { 'group': list('xxxxyyy'), 'open': [100, 150, 200, 160, 300, 150, 170], 'close': [105, 150, 200, 160, 350, 150, 170], 'stop': [104, 104, 104, 104, 400, 400, 400] } ) </code></pre> <p>Expected output i...
<python><pandas><dataframe><group-by>
2024-09-17 05:57:41
2
2,679
AmirX
78,992,592
3,796,236
How to add pytest markers to multiple paramterize
<p>I have the below block of code.</p> <pre class="lang-py prettyprint-override"><code>import pytest @pytest.mark.parametrize(&quot;project_name&quot;, [ pytest.param(&quot;default&quot;, marks=pytest.mark.defa), pytest.param(&quot;remote&quot;, marks=[pytest.mark.remote, pytest.mark.nightly]) ]) @pytest.mark...
<python><pytest><parameterized-tests>
2024-09-17 05:04:05
1
641
Joshi
78,992,529
11,770,390
how to perform http request via proxy using sshtunnel and python
<p>I'm trying to create an ssh tunnel to a <code>remote_server</code> using a PKey entry from the known_hosts file. All seems to work using this configuration:</p> <pre><code>with sshtunnel.open_tunnel( (remote_server, 22), ssh_username=&quot;process&quot;, ssh_host_key=ssh_host_key, remote_bind_address...
<python><ssh><ssh-tunnel><proxy-server>
2024-09-17 04:21:55
0
5,344
glades
78,992,492
1,716,733
setting consistent column type for streamlit tables
<p>I need to append rows of a serialized subclass of BaseModel and display in streamlit. The problem is that some fields are Optional and sometimes are missing. When they are missing, the column type will of the initialized table will deviate. I tried a few ways to pre-specify column types:</p> <ul> <li>by setting them...
<python><pandas><streamlit>
2024-09-17 03:55:14
0
13,164
Dima Lituiev
78,992,321
1,716,733
getting argument of typing.Optional in python
<p>I would like to create a typed DataFrame from a Pydantic BaseModel class, let's call it MyModel that has Optional fields. As I create multiple instances of MyModel, some will have Optional fields with None values, and if I initialize a DataFrame with such rows, they will may have inconsistent column dtypes. I'd like...
<python><pandas><python-typing>
2024-09-17 02:09:07
1
13,164
Dima Lituiev
78,992,265
3,727,678
Generic[T] class with access to type parameter of classmethod in Python 3.12
<p>Similar to how one could <a href="https://stackoverflow.com/questions/78376096/generict-classmethod-implicit-type-retrieval-in-python-3-12">retrieve a type from a generic class type signature via a class method</a>, I am now interested in doing the same for the class method's type signature itself. This is for use i...
<python><generics><python-typing>
2024-09-17 01:30:23
0
369
clintval
78,992,237
188,331
BertTokenizer.from_pretrained raises UnicodeDecodeError
<p>I pre-trained a <code>pytorch_model.bin</code> from a pre-train script. Yet when I load it with the following codes, it raises <code>UnicodeDecodeError</code>. Codes are as follows:</p> <pre><code>from transformers import BertTokenizer tokenizer = BertTokenizer.from_pretrained(&quot;/path/to/pytorch_model.bin&quot;)...
<python><huggingface-transformers>
2024-09-17 01:04:53
1
54,395
Raptor
78,992,094
4,690,023
Access class properties or methods from within a commands.Command
<p>I'm building a Discord bot. The bot should store some information into some internal variables to be accessed at a later time. To do so I'm structuring it as a class (as opposed to many examples where the commands are outside a <code>class</code> definition). However, I discovered that when you use the <code>@comman...
<python><discord.py>
2024-09-16 23:20:43
1
1,870
Luca
78,992,089
6,213,809
AttributeError: module 'ibis.selectors' has no attribute 'index'
<p>I'm trying to select columns by index just like this reference from the <a href="https://ibis-project.org/reference/selectors#examples-10" rel="nofollow noreferrer">ibis docs</a>:</p> <pre><code>import ibis import ibis.selectors as s spotify = ibis.duckdb.connect() spotify.read_csv(&quot;hf://datasets/maharshipandya...
<python><attributeerror><ibis>
2024-09-16 23:16:35
1
896
Mark Druffel
78,992,045
8,116,305
Rolling mode in Polars
<p>I have a ~100M rows long data frame containing IDs in different groups. Some of them are wrong (indicated by the 99). I am trying to correct them with a rolling mode window, similar to the code example below. Is there a better way to do this, since rolling_map() is super slow?</p> <pre class="lang-py prettyprint-ove...
<python><dataframe><python-polars><rolling-computation>
2024-09-16 22:40:08
1
343
usdn
78,991,975
11,779,147
Get an <a> tag content using BeautifulSoup
<p>I'd like to get the content of an <code>&lt;a&gt;</code> tag using BeautifulSoup (version 4.12.3) in Python. I have this code and HTML exemple:</p> <pre class="lang-py prettyprint-override"><code>h = &quot;&quot;&quot; &lt;a id=&quot;0&quot;&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th scope=&q...
<python><html><beautifulsoup>
2024-09-16 22:00:16
1
527
maggle
78,991,883
1,720,737
Converting an HTML to PDF consuming too much memory
<p>I am trying to create a PDF using xhtml2pdf lib, but there is always a memory usage issue. There are around 4,000 pages in this HTML.</p>
<python><django><xhtml2pdf>
2024-09-16 21:36:07
0
398
Ansuman
78,991,877
7,700,802
Checking count discrepancies from one date to another in dataframe
<p>Suppose I have this data</p> <pre><code>data = {'site': ['ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', 'ACY', '...
<python><pandas>
2024-09-16 21:35:13
1
480
Wolfy