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,510,478
673,642
Can regular python packages contain namespace packages?
<p>I have read <a href="https://peps.python.org/pep-0420/" rel="nofollow noreferrer">https://peps.python.org/pep-0420/</a> but it does not explicitly declare that namespace packages are strictly only allowed on top-level. All examples show namespace packages as top-level packages.</p> <p>Would this work (package1 and p...
<python><package><namespaces>
2024-05-21 08:14:35
1
383
Gunnar
78,510,155
11,922,765
Python Dataframe avoid non-NaN values dropping during <> operations
<p><strong>My code:</strong></p> <pre><code>xdf = pd.DataFrame(data={'A':[-10,np.nan,-2.2],'B':[np.nan,2,1.5],'C':[3,1,-0.3]},index=['2023-05-13 08:40:00','2023-05-13 08:41:00','2023-05-13 08:42:00']) xdf = A B C 2023-05-13 08:40:00 -10.0 NaN 3.0 2023-05-13 08:41:00 Na...
<python><pandas><dataframe><numpy><logical-operators>
2024-05-21 07:09:33
1
4,702
Mainland
78,510,083
671,013
Hint IDE with column names (and types) of a pandas dataframe
<p>Assume you have a <code>pandas</code> dataframe <code>df</code> that has the column <code>foo</code>. Then, in <code>Jupyter</code> when you type <code>df.fo&lt;TAB&gt;</code> the column name will be completed. This works when <code>df</code> is in memory. However, if <code>df</code> is not in memory then you can't ...
<python><pandas><dataframe>
2024-05-21 06:50:58
0
13,161
Dror
78,509,902
5,091,720
pandas quantile vs the Excel equivalent calculation difference
<p>There is probably a way to do this the problem is I don't know it. I have data sets that are often between 80 to 120 values long. I am trying to compute the 90% value for each separate data set. I was testing this out in excel and python and realized that there is a difference with the results when I thought I would...
<python><arrays><pandas><excel><numpy>
2024-05-21 06:05:51
1
2,363
Shane S
78,509,755
10,452,700
How can filter and retrieve specific records from big data efficiently using Python/Pyspark in Google Colab medium?
<p>I'm struggling with a data engineering problem:</p> <h3><strong>Dataset Characteristics</strong></h3> <div class="s-table-container"><table class="s-table"> <thead> <tr> <th>public dataset</th> <th style="text-align: center;">duration</th> <th style="text-align: center;">Total #VMs</th> <th style="text-align: cente...
<python><pyspark><google-colaboratory><dask><python-polars>
2024-05-21 05:14:59
2
2,056
Mario
78,509,742
12,291,425
Cannot get Azure subscriptions using Azure Python SDK
<p>I can get Azure subscriptons list <a href="https://stackoverflow.com/q/78505840/12291425">using REST API</a>.</p> <p>However, when I'm switching to <a href="https://learn.microsoft.com/en-us/azure/developer/python/sdk/azure-sdk-overview" rel="nofollow noreferrer">Azure Python SDK</a>, there seems to be some problems...
<python><azure><azure-management-api><azure-python-sdk>
2024-05-21 05:11:26
2
558
SodaCris
78,509,356
93,910
Best practice to open files for use in a gui
<p>My application opens a video file, plays frames in a GUI, then closes it. The logic is like this</p> <pre><code>import cv2 try: self.vid = cv2.VideoCapture(local_file) self.play_frame() finally: # vid.release() </code></pre> <p>But the problem is that the logic for <code>start_playback()</code> is asyn...
<python><try-catch><with-statement><fclose><file-in-use>
2024-05-21 01:56:45
0
7,056
Sanjay Manohar
78,509,264
2,813,606
How to remove everything in a string before first occurrence of pattern (Python)
<p>I have a string that looks like the following:</p> <pre><code>sample_string = 'Hello, my name is Bob.\nI like sparkling water.\nMy favorite flavor is mango.\n Goodbye.' </code></pre> <p>I want to do two things:</p> <ol> <li>Edit the string in a way that removes all characters before the first occurrence of '\n'</li>...
<python><regex><string>
2024-05-21 00:59:24
1
921
user2813606
78,509,126
1,322,962
Pip download `Cannot Install` Due To Conflict While Showing Exact Version Match?
<h1>Description</h1> <p>I'm attempting to run <code>pip download</code> in order to bundle wheels into a zip file to upload to a service without internet access. I need to download all of my dependencies from PyPI and then upload them to the service for the service to run.</p> <p>While running pip download I hit this e...
<python><python-3.x><pip>
2024-05-20 23:36:11
0
8,598
AlexLordThorsen
78,509,109
6,622,697
Does popen().readline block until all output is read?
<p>I'm running an asynchronous long-running process with <code>popen</code>. If I'm interested in getting all the data written to stdout, can I just do</p> <pre><code>cmd = popen(...) for line in cmd.stdout.readline() ... do something with line </code></pre> <p>I'm wondering if I need to test <code>cmd.poll()</code...
<python><python-3.x><popen>
2024-05-20 23:26:22
1
1,348
Peter Kronenberg
78,509,092
6,622,697
How to serialize subprocess.popen()
<p>This is follow-on to <a href="https://stackoverflow.com/questions/78507222/return-output-of-subprocess-popen-in-webserver?noredirect=1#comment138405770_78507222">Return output of subprocess.popen() in webserver</a>. I have a long running process that is kicked off by a Webserver call (running Django). I'm using <co...
<python><python-3.x><django><popen>
2024-05-20 23:19:52
1
1,348
Peter Kronenberg
78,508,878
3,628,240
Web Scraping Javascript Page with Selenium and Python
<p>I'm looking to scrape a list from a website, where you have to select &quot;Yes&quot;, check the &quot;Show by State&quot; box, click the &quot;Submit and Find Doctor&quot;, and then select a state from the dropdown, and note the doctor's name.</p> <p>Website:</p> <pre><code>https://www.inspiresleep.com/en-us/find-a...
<python><selenium-webdriver><web-scraping>
2024-05-20 21:48:20
2
927
user3628240
78,508,806
234,146
Controlling column order of Numpy txt output
<p>I would like to control the print order of column data in a printout from a Numpy table. The native savetxt function will only print in the order the _table_type was defined. Is there a variant that will allow specifying the column order?</p> <p>I know I can print the values field by field if I need to. I'm looki...
<python><numpy><printing>
2024-05-20 21:14:26
1
1,358
Max Yaffe
78,508,795
398,670
Is there a way to override packages and versions with pipx install, e.g. psycopg2 -> psycopg2-binary?
<p>Say I need to install some Python project 'foo'.</p> <p>It has a <code>requirements.txt</code> or <code>setup.py</code> or <code>setup.cfg</code> or <code>pyproject.toml</code> or <code>omgwtf.python</code> that lists <code>psycopg2</code> as a dependency.</p> <p>But on my install target I don't have a C toolchain o...
<python><pip><psycopg2><pipx>
2024-05-20 21:09:35
0
328,701
Craig Ringer
78,508,758
12,011,902
What is the Rust reqwest equivalent of the following Python requests code?
<p>I am trying to do a Basic Authentication GET, ignoring certificate validation, using <code>reqwests</code>.</p> <p>I have following Python <code>requests</code> code, which works:</p> <pre class="lang-py prettyprint-override"><code>import requests from requests.auth import HTTPBasicAuth session = requests.sessions....
<python><rust><python-requests><reqwest>
2024-05-20 20:59:30
1
658
trozzel
78,508,499
1,591,219
Split a graph so each type of node is only appearing once in in each partition with as little cuts as possible
<p>I have a table in BigQuery that represents the edges of a graph. Each node in the graph has a type. Each edge has a created_at property. Now I want to cut the graph into subcomponents. No subcomponent has more than one node of a selected type (A). I want to do this with as few edge cuts as possible. Prefer to cut yo...
<python><graph><networkx><graph-theory><connected-components>
2024-05-20 19:43:20
1
618
Benedikt
78,508,467
7,547,525
Stitch pictures from rotating camera
<p>I am writing a homography by rotation project by following the example here: <a href="https://docs.opencv.org/4.4.0/d9/dab/tutorial_homography.html#tutorial_homography_Demo5" rel="nofollow noreferrer">https://docs.opencv.org/4.4.0/d9/dab/tutorial_homography.html#tutorial_homography_Demo5</a></p> <p>For my project, I...
<python><opencv><computer-vision>
2024-05-20 19:33:28
0
761
Clayton Rothschild
78,508,381
525,916
Pivot dataframe values and its unit
<p>I have the input dataframe in the following format:</p> <pre><code>id city state date param value unit 1 Phoenix AZ 4-21-2024 temp 100 F 2 Phoenix AZ 4-21-2024 prec 0 mm 3 Phoenix AZ 4-21-2024 wind 2 mph 4 Phoenix AZ 4-20-2024 temp 101 F 5 Phoenix AZ 4-20-2024 prec ...
<python><pandas>
2024-05-20 19:09:52
1
4,099
Shankze
78,508,149
5,924,264
Does equality check for floats in python check against machine epsilon tolerances?
<p>I'm a bit confused about the precision on floats in python and equality checks.</p> <p>e.g.,</p> <pre><code>15 + 1e-16 == 15 </code></pre> <p>evaluates to true b/c 1e-16 is &lt; machine epsilon for fp64.</p> <p>and</p> <pre><code>15 + 1e-15 == 15 </code></pre> <p>evaluates false because 1e-15 &gt; machine epsilon fo...
<python><floating-point><precision>
2024-05-20 18:01:08
1
2,502
roulette01
78,507,738
14,179,793
How to pass arguments containing parentheses to aws ecs execute-command using python subprocess.run?
<p><strong>Goal</strong>: Use the aws cli in a <code>subprocess.run</code> call to execute a command in a container of a running task.<br /> <strong>Example Usage</strong>:</p> <pre><code>task_arn = 'a_task_arn' arg = event = {'something': 'that contains ( )'} # Attempt 1: json string arg = json.dumps(arg) subprocess_...
<python><amazon-ecs><aws-cli>
2024-05-20 16:27:06
1
898
Cogito Ergo Sum
78,507,669
4,483,861
Why is floor division inconsistent with division follow by floor, e.g. 1//0.2 = 4.0
<p>The operator <code>//</code> for integer division is called &quot;floor division&quot; in the python documentation, but comparing to other floor implementations there is a discrepancy, for example:</p> <pre><code>&gt;&gt;&gt; numpy.floor(1/0.2) 5.0 &gt;&gt;&gt; float(math.floor(1/0.2)) 5.0 &gt;&gt;&gt; 1//0.2 4.0 </...
<python><integer-division><floor><floor-division>
2024-05-20 16:14:02
0
2,649
Jonatan Γ–strΓΆm
78,507,605
1,145,666
When I read() a new frame from a cv2.VideoCapture, I get an old frame
<p>When I wait a little between two calls of <code>read()</code> from a OpenCV <code>VideoCapture</code> device, I still seem to get an &quot;old&quot; frame, instead of what is seen by the camera at that point:</p> <pre><code>import cv2, time vid_capture = cv2.VideoCapture(2) ret, frame = vid_capture.read() cv2....
<python><opencv><webcam>
2024-05-20 15:59:13
0
33,757
Bart Friederichs
78,507,580
10,946,777
Python Marshmallow set different fields as 'required' for each schema variant of the same schema
<p>I have the following schema:</p> <pre><code>class MySchema(Schema): id = fields.Str() name = fields.Str() value = fields.Str() description = fields.Str() </code></pre> <p>I want to validate some input data with Flask for different types of requests.</p> <p>For GET requests, I want the id field to be ...
<python><schema><flask-restful><marshmallow>
2024-05-20 15:52:49
1
307
Sederfo
78,507,475
13,150,380
Caching yarn and python pip in google cloud build
<p>Currently building with cloud build takes arround 10 minutes (5 minutes frontend, 5 minutes backend). Is there anyway I can cache the yarn install and pip install so the build time cut significantly? this is my current config for cloud build</p> <pre class="lang-yaml prettyprint-override"><code>steps: - name: &quo...
<python><google-cloud-platform><pip><yarnpkg><google-cloud-build>
2024-05-20 15:29:53
1
599
BlueBeret
78,507,453
5,525,901
Python threads behaviour on ctrl+c during join
<p>I'm struggling to understand what happens to other threads when ctrl+c interrupts the main thread while it's waiting for the other thread to finish.</p> <p>Here's a small snippet of code to illustrate an example.</p> <pre class="lang-py prettyprint-override"><code>import time, threading def worker(): time.sleep...
<python><multithreading>
2024-05-20 15:24:00
1
1,752
Abraham Murciano Benzadon
78,507,425
4,442,337
Django: overriding ForeignKey limit_choices_to in subclasses?
<p>Following the current documentation <a href="https://docs.djangoproject.com/en/5.0/ref/contrib/contenttypes/#generic-relations" rel="nofollow noreferrer">https://docs.djangoproject.com/en/5.0/ref/contrib/contenttypes/#generic-relations</a> I created a <code>GenericReferModel</code> which is an abstract class that de...
<python><django>
2024-05-20 15:18:58
1
2,191
browser-bug
78,507,373
6,619,548
How might my API be receiving an incorrectly formatted ISO 8601 timestamp
<p>I have an iOS/Android app sending data to the Python backend.</p> <p>In both apps, the user selects a date and time from a picker, and it is sent to the server:</p> <p>Android:</p> <pre><code>SimpleDateFormat simpleDateFormat = new SimpleDateFormat(&quot;yyyy-MM-dd'T'HH:mm:ss.SSS'Z'&quot;); String formattedDate = si...
<python><android><ios><datetime><simpledateformat>
2024-05-20 15:08:58
0
1,594
alstr
78,507,260
3,103,399
How to use jsonb_to_record and x() with sqlalchemy
<p>I am trying to make the following SQL alchemy orm query work :</p> <pre class="lang-py prettyprint-override"><code>query = ( sqlalchemy.select( cls.tasks_table.id.label(&quot;task_id&quot;), cls.tasks_table.doc.label(&quot;task_doc&quot;), cls.table.id.label(&quot;job_id&quot;), c...
<python><postgresql><sqlalchemy>
2024-05-20 14:45:01
1
5,386
jony89
78,507,236
2,502,331
Token (Access) Errors Connecting to MS SQL Server From DataBricks Python Notebooks Via PySPark JDBC Driver Using an Azure Service Principal and MSAL
<p>How do I resolve token (Active Directory access) errors when connecting to MS SQL Server from DataBricks Python notebooks via PySPark JDBC driver using an Azure/DataBricks Service Principal and MSAL (Microsoft Authentication Library)? I have tried both the PySpark JDBC driver package (current Maven coordinates: com...
<python><pyspark><jdbc><databricks><azure-ad-msal>
2024-05-20 14:40:09
1
978
StephenDonaldHuffPhD
78,507,222
6,622,697
Return output of subprocess.popen() in webserver
<p>I have a Webserver in Python using Django. I want to be able to kick of a long-running asynchronous subprocess and then have the client poll with a GET or POST and receive stdout as well as other information. For each iteration, the server will return the lines of stdout that it has so far. When the process ends,...
<python><python-3.x><django><webserver><popen>
2024-05-20 14:38:35
1
1,348
Peter Kronenberg
78,507,209
785,349
Error Building 'pycapnp' for AppScale on Ubuntu 18.04 with Python 2.7
<p>As a Java Developer transitioning into the Python ecosystem, I've noticed a difference in how dependencies are handled between the two languages. In Java, project dependencies remain intact and the project builds reliably over time.</p> <p>However, my experience with Python has shown it to be more fragile in this as...
<python><python-2.7>
2024-05-20 14:35:48
0
35,657
quarks
78,507,093
20,920,790
How to make ID with specified length with hashlib?
<p>I need unique ID's to make it primary key in database and use it for join tables. How to make ID with length I need? For example my string:</p> <pre><code>'827263877-13969916-1800-1-0.0' </code></pre> <p>I use this code to make ID:</p> <pre><code>def make_unique_id(*args): data = '-'.join(str(args)) id = has...
<python><hashlib>
2024-05-20 14:11:36
1
402
John Doe
78,506,950
11,439,134
Access row item of Gtk.ListView
<p>I need to add a custom class to some rows in a GtkListView widget so that I can change their background colour. Looking on the inspector, ListItem rows are instances of GtkListItemWidget, but I can't find anything in the docs or online regarding how to access these widgets.</p> <p>I am using Gtk 4. Would anyone have...
<python><listview><gtk><gtk4>
2024-05-20 13:42:44
1
1,058
Andereoo
78,506,927
525,865
getting all the links - that are "stored" in the page: i tried to invest the page thoughroghly
<p>how to get all the links - that are &quot;stored&quot; in the page</p> <p><a href="https://www.wohnungsbaugenossenschaften.de/gaestewohnung-finden/teilnehmende-genossenschaften" rel="nofollow noreferrer">https://www.wohnungsbaugenossenschaften.de/gaestewohnung-finden/teilnehmende-genossenschaften</a></p> <p>tried t...
<python><html><web-scraping>
2024-05-20 13:37:30
1
1,223
zero
78,506,798
4,948,165
Keep/Build a map when doing multiple pandas groupby operations
<p>Imagine a process, where we do several pandas groupbys.</p> <p>We start with a df like so:</p> <pre><code>import numpy as np import pandas as pd np.random.seed(1) df = pd.DataFrame({ 'id': np.arange(10), 'a': np.random.randint(1, 10, 10), 'b': np.random.randint(1, 10, 10), 'c': np.random.randint(1, ...
<python><pandas><group-by>
2024-05-20 13:08:12
2
3,238
Eran Moshe
78,506,774
11,233,365
Rewriting URL request function to satisfy GitHub CodeQL server side request forgery (SSRF) warning
<p>I'm working on a function that returns a HTTP response from <a href="https://pypi.org/simple/" rel="nofollow noreferrer">https://pypi.org/simple/</a> when Python's <code>pip</code> installer requests it for a package. When pushing my code onto GitHub, the CodeQL checks warn of the risk of server side request forgery...
<python><github><codeql><ssrf>
2024-05-20 13:03:29
1
301
TheEponymousProgrammer
78,506,517
7,123,797
What thing is responsible for the explicit line joining?
<p>It seems that the Python tokenizer isn't responsible for the explicit line joining. I mean if we write the following code in file <code>script.py</code>:</p> <pre><code>&quot;one \ two&quot; </code></pre> <p>and then type <code>python -m tokenize script.py</code> in the command prompt, we will got the following tabl...
<python><language-lawyer><tokenize>
2024-05-20 12:12:15
0
355
Rodvi
78,506,404
1,937,473
Pandas apply with "expand result" results in NaN columns when using loc but not [ ]
<p>I am having some issues around setting new column values that are produced by a pandas <code>apply</code> function. If you scroll to the bottom I've provided a MRE you should be able to copy-paste and run.</p> <h2>Explanation</h2> <p>Let's assume we have a DataFrame <code>df</code> as follows:</p> <pre class="lang-p...
<python><python-3.x><pandas><dataframe>
2024-05-20 11:43:56
0
333
DLJ
78,506,400
3,156,085
Annotating a decorator with generic Protocols causes "arg-type" (incompatible type) error involving `Never`
<p>I'm trying to implement and annotate a decorator for functions without keyword arguments (but with variable number of arguments) using <a href="https://docs.python.org/3/library/typing.html#typing.Protocol" rel="nofollow noreferrer"><code>typing</code>'s <code>Protocol</code></a> as <a href="https://docs.python.org/...
<python><mypy><python-typing><python-3.10>
2024-05-20 11:42:12
0
15,848
vmonteco
78,506,301
6,010,635
Select multi-index when one subindex obeys condition
<p>If I build a dataframe like this</p> <pre><code>arrays = [ np.array([&quot;bar&quot;, &quot;bar&quot;, &quot;baz&quot;, &quot;baz&quot;, &quot;foo&quot;, &quot;foo&quot;, &quot;qux&quot;, &quot;qux&quot;]), np.array([&quot;one&quot;, &quot;two&quot;, &quot;one&quot;, &quot;two&quot;, &quot;one&quot;, &quot;t...
<python><pandas><multi-index>
2024-05-20 11:19:37
1
1,297
David
78,506,138
2,338,792
How to convert odd number of hex digits to bytes without loosing its leading zeros
<p>How to convert with Python an odd number of hex digits to bytes without losing its leading zeros?</p> <p>For example, string '0001000' should be converted to bytes 0001000</p>
<python>
2024-05-20 10:44:46
1
2,354
DavidS
78,506,114
2,487,835
SpaCy transformer NER training – zero loss on transformer, not trained
<p>I am training a SpaCy pipeline with <code>['transformer', 'ner']</code> components, ner trains well, but transformer is stuck on 0 loss, and, I am assuming, is not training.</p> <p>Here is my config:</p> <pre class="lang-ini prettyprint-override"><code>[paths] vectors = &quot;en_core_web_trf&quot; init_tok2vec = nul...
<python><machine-learning><spacy><spacy-3><spacy-transformers>
2024-05-20 10:39:58
1
3,020
Lex Podgorny
78,506,106
11,562,537
How to set the same width to the ttk.Combobox and ttk.Entry widgets?
<p>I have to put three widgets (ttk.Combobox, ttk.Entry and ttk.Combobox) in series with the same width. Below an example:</p> <pre><code>import tkinter as tk from tkinter import ttk def configure_column_widths(frame, num_columns): for i in range(num_columns): frame.grid_columnconfigure(i, weight=1) root...
<python><tkinter>
2024-05-20 10:38:33
1
918
TurboC
78,505,970
24,758,287
Python - Subtract Date by First Entry?
<p>I'm using polars library in python to manipulate some dataframe.</p> <p>I'm trying to do the following: :</p> <p>For some dataframe:</p> <div class="s-table-container"><table class="s-table"> <thead> <tr> <th>Person..</th> <th>Fight with</th> <th>On</th> </tr> </thead> <tbody> <tr> <td>A</td> <td>B</td> <td>3 Jan</t...
<python><dataframe><datetime><grouping><python-polars>
2024-05-20 10:13:21
2
301
user24758287
78,505,858
12,415,855
Copy cells with text and font-color with openpyxl?
<p>I try to copy some cells with colored fonts from one worksheet to antoher using openpyxl. The cell A1 is only colored - and the cell A2 is richtext-colored (so only a part of the cell is colored)</p> <p><a href="https://i.sstatic.net/Zq7oRumS.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Zq7oRumS.pn...
<python><openpyxl>
2024-05-20 09:53:15
1
1,515
Rapid1898
78,505,840
12,291,425
Cannot get Azure subscriptions using `msal` and requests in python through REST API
<p>I can get subsriptions using token captured from browser: <a href="https://i.sstatic.net/ex72jBvI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ex72jBvI.png" alt="REST API result" /></a></p> <p>Then I switch to Python and <code>msal</code>. I use the following code:</p> <pre class="lang-py prettypri...
<python><azure><azure-ad-msal><azure-rbac>
2024-05-20 09:47:54
1
558
SodaCris
78,505,497
8,205,554
How to define new values and sort by those values when combining a list with itself?
<p>I have a pandas dataframe like follows,</p> <pre><code>+------------+-------------------+---------+--------+----------+ | process_no | process_durations | columns | orders | customer | +------------+-------------------+---------+--------+----------+ | 0 | 3 | [0] | [3109] | [0] | +-...
<python><pandas>
2024-05-20 08:30:46
2
2,633
E. Zeytinci
78,505,478
3,182,496
How to run a function multiple times with different return values?
<p>I have a test that intermittently fails during automated builds so I want to add some retries to my tool. However, I'm not sure how to force the tool to fail and verify that it has retried before I get the usual satisfactory outcome.</p> <p>The program I am testing is written in Python, but some functionality is pro...
<python><unit-testing><mocking><python-unittest.mock>
2024-05-20 08:26:06
2
1,278
jon_two
78,505,470
9,542,989
skip_on_failure Flag with Pydantic V2?
<p>The <code>root_validator</code> that was available with Pydantic V1 allowed a flag called <code>skip_on_failure</code>, which allowed other validators to be run even if prior ones failed (when set to <code>True</code>).</p> <p>Is there a way to achieve using the <code>model_validator</code> offered by V2? I cannot f...
<python><pydantic><pydantic-v2>
2024-05-20 08:24:08
0
2,115
Minura Punchihewa
78,505,410
8,972,207
Fivetran REST API get all connectors
<p>I'm currently working on a project where I need to list all connectors across multiple groups in Fivetran. I've managed to retrieve all the groups successfully using the REST API, but I'm having trouble listing all the connectors.</p> <p>This is how I get all groups:</p> <pre><code>import requests import json url = ...
<python><rest><fivetran>
2024-05-20 08:09:28
0
573
DarknessPlusPlus
78,505,110
3,662,734
Using register_hook() to freeze a portion of weight tensor does not speed up training
<p>I am doing a sort of transfer learning where I want to freeze a part of the weights tensor and train the other, as explained in <a href="https://stackoverflow.com/questions/78488981/set-a-part-of-weight-tensor-to-requires-grad-true-and-keep-rest-of-values-to-r/78489275?noredirect=1#comment138396465_78489275">my prev...
<python><deep-learning><pytorch><freeze>
2024-05-20 06:58:47
1
579
Emily
78,505,010
12,959,994
how to properly frame websocket messages in python socket library
<p>I'm building a websocket server in python using socket, it's embedded python that I can't install any packages for. I've gotten as far as handling the handshake and establish a connection. I can get data being sent back and forth from my server and client (a React App), but some of the payloads are too large, batchi...
<python><multithreading><sockets><websocket>
2024-05-20 06:30:31
1
652
jbflow
78,504,983
1,039,860
how to create a version.py file that is updated each time any file is pushed via git
<p>I am hoping to have git create a version.py file that looks like this (where the version is incremented each commit):</p> <pre><code># This file is created by the pre-push script class Version: comment = &quot;git commit comment&quot; hash = &quot;some git hash&quot; version = &quot;0.8.9&quot; </code></...
<python><git>
2024-05-20 06:25:39
3
1,116
jordanthompson
78,504,872
9,846,650
Issue accessing deeply nested attributes in Django Rest Framework serializer's validate method
<p>I'm facing an issue while trying to access deeply nested attributes within the <code>validate</code> method of a Django Rest Framework serializer. Here's a simplified version of my serializer:</p> <pre class="lang-py prettyprint-override"><code>from rest_framework import serializers from myapp.models import User cl...
<python><python-3.x><django><django-rest-framework>
2024-05-20 05:52:13
1
712
mad_lad
78,504,721
13,285,583
Why torch.autograd.Function backward pass a grad_output?
<p>my goal is to understand <code>torch.autograd.Function</code>. The problem is I don't understand why backward need <code>grad_output</code>.</p> <p>What I've tried:</p> <ol> <li><p>Read <a href="https://pytorch.org/tutorials/beginner/pytorch_with_examples.html" rel="nofollow noreferrer">Learning PyTorch with Example...
<python><pytorch>
2024-05-20 04:58:49
1
2,173
Jason Rich Darmawan
78,504,499
11,942,776
Pyinstaller cannot detect C-module in package
<p>I'm using Pyinstaller to create a Windows executable from Python code. My Python script depends on a package called MT5Manager, which is compiled from C.</p> <p>I can use <code>python main.py</code> to run the script without error, but when I try running the .exe file, I get an error that says:</p> <pre><code>Traceb...
<python><pyinstaller>
2024-05-20 03:07:35
0
331
Nguyα»…n Đức Huy
78,504,247
5,286,435
Weird Vim Python auto-indent issue
<p>When editing Python files, I am running into a weird auto-indent issue. No matter what I do, when I open a new line, the cursor always ends up in the middle of the terminal. I expect it be aligned with either the start of the previous line or one indent over if its opening a new control block. For example:</p> <pre>...
<python><vim>
2024-05-20 00:20:10
0
372
Dnj Abc
78,503,955
3,168,356
Understanding the shape of np.apply_along_axis output
<p>I have a question regarding output dimensions of <code>np.apply_along_axis</code>.</p> <p>In the first case values of <code>x</code> for the lambda function are <code>[1 2]</code>, <code>[1 3]</code>, <code>[1 4]</code> and they have shape <code>(2,)</code> since we split across <code>axis=0</code>. Each output of t...
<python><numpy>
2024-05-19 21:20:27
2
3,169
Konstantin
78,503,848
116
How can I force devtools.pprint to not colorize its output?
<p>I have some code that uses <a href="https://python-devtools.helpmanual.io/usage/#prettier-print" rel="nofollow noreferrer"><code>devtools.pprint</code></a>:</p> <pre><code>import devtools devtools.pprint(my_dictionary) </code></pre> <p>How can I indicate to <code>pprint</code> that I do not want colorized output? S...
<python>
2024-05-19 20:29:30
1
305,996
Mark Harrison
78,503,790
2,813,606
How to remove string + n preceding characters from pandas dataframe
<p>I have a dataframe that looks like the following:</p> <pre><code>Group Attribute Text 1 A 'The ball is red456placeholder' 1 A 'I like pizza985placeholder.' 2 A 'Fire bad 231placeholder' 2 B 'Sparkling water makes me happy777placeholder' </code></pre> <p>I want to clean...
<python><pandas><substring>
2024-05-19 20:03:52
2
921
user2813606
78,503,756
1,314,901
How do I type generic callables with default value in Python?
<p>I have the following function:</p> <pre><code>T = TypeVar(&quot;T&quot;) def handle_func(x: int, func: Callable[[int], T]) -&gt; T: return func(x) </code></pre> <p>and I can use it like so:</p> <pre><code>handle_func(1, lambda x: x + 1) handle_func(1, lambda x: x == 1) </code></pre> <p>When I run mypy, all is ...
<python><mypy><python-typing>
2024-05-19 19:51:10
2
2,060
Meir
78,503,335
7,658,051
psycopg2.errors.UndefinedTable: relation "mydjangoapp_mymodel" does not exist
<p>I am managing a django app built by third parts.</p> <p>I have configured in settings.py the connection to a new db</p> <pre><code>'default': { # changed 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': 'waterwatch', 'USER': 'waterwatch_main', 'PASSWORD': '****', 'HOST': 'localhost', ...
<python><django><django-migrations>
2024-05-19 17:02:43
1
4,389
Tms91
78,503,334
19,659,857
The splash screen isn't centering exactly according to the screen size
<p>I'm using Custom Tkinter to create a splash screen. I wanted to center the splash screen both horizontally and vertically. I tried the following code, but it didn't work. The splash screen is not exactly centered. I've also attached a screenshot. Please check it and let me know your suggestions. Thanks!</p> <pre><co...
<python><tkinter><customtkinter>
2024-05-19 17:02:21
0
339
user8
78,503,301
11,032,005
Why the sync function is behaving like async function and vice-versa?
<p>I'm trying to understand the difference between sync and async functions using Python fast API. In the following code, I have written a sync function and put a 10-second time delay in it. When I try to call this API two times simultaneously, I get the response time to the two calls is the same (10sec). For example,...
<python><asynchronous><synchronization><fastapi>
2024-05-19 16:52:21
0
489
sachin murali
78,503,297
11,304,830
Unable to tag the right elements to scrape a website using Selenium in Python
<p>I am trying to scrape <a href="https://www.facile.it/energia-dual-fuel/preventivo.html" rel="nofollow noreferrer">this</a> website which would display utility bills information once details have been inserted. The website requires me to insert some info as well as clicking on some options.</p> <p>I have been reading...
<python><selenium-webdriver><web-scraping><selenium-chromedriver>
2024-05-19 16:50:33
2
1,623
Rollo99
78,503,255
10,200,497
How can I get the left edge as the label of pandas.cut?
<p>This is my DataFrame:</p> <pre><code>import pandas as pd df = pd.DataFrame( { 'high': [110, 110, 101, 101, 115, 300], } ) </code></pre> <p>And this is the expected output. Column <code>bin</code> should be created:</p> <pre><code> high bin 0 110 105.0 1 110 105.0 2 101 100.0 3 101 100....
<python><pandas><dataframe>
2024-05-19 16:37:20
3
2,679
AmirX
78,503,222
8,948,544
counting null values in sqlalchemy returns 0
<p>I am trying to get the unique values and their counts from an SQLite table. This is the python statement:</p> <pre class="lang-py prettyprint-override"><code>results = db.session.query(MyTable.rating, db.func.count(MyTable.rating)).group_by(MyTable.rating).all() counts = {str(row[0]): row[1] for row in results} </co...
<python><sqlite><sqlalchemy>
2024-05-19 16:24:40
0
331
Karthik Sankaran
78,503,184
1,028,270
Is there a way to prevent pydantic from calling my function used to find config files on import?
<p>My class looks something like this:</p> <pre><code>class MyConfig(BaseSettings): model_config = SettingsConfigDict( env_file=get_configs(), ) </code></pre> <p>I didn't realize that my <code>get_configs()</code> seems to be getting called on import. I discovered this when I had a bug in that function ...
<python><pydantic><pydantic-settings>
2024-05-19 16:10:52
1
32,280
red888
78,503,121
3,404,480
matplotlib.pyplot not closing window on Mac
<p><code>matplotlib</code> is not closing its window screen after disposal of plot. It is still running on background.</p> <pre class="lang-py prettyprint-override"><code> # python code import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot(getXData(), getYData(), label=&quot;Line 1&quot;) ...
<python><matplotlib><apple-m1>
2024-05-19 15:47:32
0
388
Prashant
78,503,039
10,906,068
How to properly create Python regex for allowing alphanumeric characters, commas, dots, spaces
<p>Am working with Python, trying to allow only alphanumeric characters, commas, dots, spaces</p> <p>When I run the code below, it throws error invalid syntax:</p> <pre><code>strx ='test, 22222 @% te-st test test' result = strx.replace(/[^A-Za-z0-9, .]/g, '') print(result) </code></pre>
<python>
2024-05-19 15:14:45
1
2,498
Nancy Moore
78,502,976
3,565,923
Selenium select click intercepted. Select.select_by_value()
<p>I want to change rows number in table by selecting value in Select object. Select is obscured by google iframe. I can click &quot;x&quot; button for iframe, but google iframe is still there.</p> <pre class="lang-py prettyprint-override"><code>change_rows_el = driver.find_element(By.CSS_SELECTOR, 'select[aria-label=&...
<python><selenium-webdriver>
2024-05-19 14:56:48
2
350
user3565923
78,502,965
11,441,069
OpenAI Assistants API: Is there a better way to wait for the assistant's response, and how do I display the assistant's answer incrementally?
<p>Based on the available information (unfortunately, ChatGPT was not too useful), I created the following code that allows me to interact with the OpenAI Assistants API.</p> <p>However, I still don't like the <code>_wait_for_run_completion</code> method and the <code>while</code> loop. Is there a better way to handle ...
<python><python-3.x><openai-api><openai-assistants-api>
2024-05-19 14:53:00
2
509
Krzysztof Krysztofczyk
78,502,897
2,223,967
Reduce the sum of differences between adjacent array elements
<p>I came across a coding challenge on the internet the question is listed below:</p> <blockquote> <p>Have the function FoodDistribution(arr) read the array of numbers stored in arr which will represent the hunger level of different people ranging from 0 to 5 (0 meaning not hungry at all, 5 meaning very hungry). You wi...
<python><algorithm><dynamic><greedy>
2024-05-19 14:28:17
4
980
Mohd Alomar
78,502,470
9,072,753
How to create HH:MM optimized regex?
<p>Given two times in the form <code>HH:MM</code>, I want to filter logs containing all hours between the given hours.</p> <p>So for example, given 09:30 and 15:30, a simple regex <code>T(09:[345]|1[01234]|15:[123])</code> would suffice. There is the assumption that input is in correct format.</p> <p>Creating a regex l...
<python><regex>
2024-05-19 11:47:45
1
145,478
KamilCuk
78,502,465
20,920,790
How to simulate INSERT INTO VALUES ON CONFLICT DO UPDATE SET in Clickhouse?
<p>I need to update Clickhouse database with Python script (I use clickhouse_connect). So, I need check conflicts before insert any data.</p> <ol> <li>In some tables I need just add new data. For new data I generate manually ID's, so I check last ID in database, make ID's for new data and insert it into database by cli...
<python><clickhouse>
2024-05-19 11:46:18
0
402
John Doe
78,502,213
6,946,110
Python 3.12 Sentry-sdk AttributeError: module 'collections' has no attribute 'MutableMapping'
<p>I tried to use <code>sentry-sdk</code> latest version with Python 3.12, but when I run my django app, it shows me following error:</p> <pre><code>AttributeError: module 'collections' has no attribute 'MutableMapping' </code></pre> <p>Full trace as follows:</p> <pre><code>File &quot;/usr/local/lib/python3.12/site-pac...
<python><django><sentry><python-3.12>
2024-05-19 10:11:58
0
1,553
msln
78,502,175
16,127,735
Search for text in a very large txt file (50+GB)
<p>I have a <code>hashes.txt</code> file that stores strings and their compressed SHA-256 hash values. Each line in the file is formatted as follows:</p> <p><code>&lt;compressed_hash&gt;:&lt;original_string&gt;</code></p> <p>The <code>compressed_hash</code> is created by taking the 6th, 13th, 20th, and 27th characters ...
<python><hash><sha256>
2024-05-19 09:55:06
1
1,958
Alon Alush
78,502,149
13,329,963
User defined logvars for Django application deployed on uWSGI server
<p>I have deployed a Django application on a uWSGI server, which has the following middleware</p> <pre><code># myapp/middleware.py from django.utils.deprecation import MiddlewareMixin class LogUserMiddleware(MiddlewareMixin): def process_request(self, request): request.META['REMOTE_USER'] = 'test' </code>...
<python><django><logging><uwsgi>
2024-05-19 09:43:48
1
2,818
Prateek Gupta
78,502,090
20,920,790
How to connect to Clickhouse with SSL-on in Python?
<p>I trying connect to Clickhouse database in Python with pandahouse . In Dbeaver my connection settings:</p> <pre><code>host: **.***.**.*** port: 8443 database: db_name user: user_name password: *** SSH: off SSL: on SSl mode: None </code></pre> <p>How to add SSL - setting to pandahouse connection?</p> <p>I've also try...
<python><clickhouse>
2024-05-19 09:17:37
2
402
John Doe
78,502,050
10,570,372
How to type hint numpy arrays that accept any types of numpy floats?
<p>As per question, I want to define a numpy type that accepts any numpy floats (i.e. <code>np.float64</code>, <code>np.float32</code> etc. Currently I am doing the below, is there a way to bound the <code>NDArray</code> such any subclass of <code>np.floating</code> is allowed?</p> <pre class="lang-py prettyprint-overr...
<python><numpy><python-typing>
2024-05-19 08:56:07
1
1,043
ilovewt
78,501,972
5,277,235
Iteratively source a value from a dictionary
<p>I have a data set where I know a limited number of values and based on other values in a data set I can figure out what the subsequent values are. I could do this with a huge if function, but I know long ago someone (in a job with code I no longer have access to) showed me how to source these values from a dictiona...
<python><pandas><dictionary><lambda><apply>
2024-05-19 08:16:28
1
607
James Oliver
78,501,884
17,718,669
Is there a better way to update all relation rows with `ForegnKey` relation in `Django ORM`
<p>I have two models, one like this:</p> <pre class="lang-py prettyprint-override"><code>class PhysicalSensor(models.Model): name = models.CharField(unique=True, max_length=255) def __str__(self) -&gt; str: return self.name class Sensor(models.Model): physical_sensor = models.ForeignKey(PhysicalSe...
<python><django><django-models><django-rest-framework><django-serializer>
2024-05-19 07:33:56
1
326
parsariyahi
78,501,868
1,867,328
Define data type in creating custom function
<p>I have below custom function</p> <pre><code>import pandas as pd def MyFn(DF : pd.DataFrame) -&gt; float : return DF['Col_A'].values[1] - DF['Col_B'].values[1] </code></pre> <p>However I want to force user to supply a dataframe with 2 columns and having column names as <code>'Col_A' and 'Col_B'</code></p> <p>Any in...
<python><pandas>
2024-05-19 07:25:17
2
3,832
Bogaso
78,501,768
7,290,715
Generate a SQL string containing UNION and JOIN recursively
<p>I am trying to generate a SQL string recursively that would contain UNION and JOIN using Python.</p> <p>Below are the conditions:</p> <ol> <li><p>Number of columns would be determined from a variable. If v = 2 the number of columns would be 3, with 1st one would always be fixed. If v = 3 the number of columns would ...
<python><sql>
2024-05-19 06:35:08
0
1,259
pythondumb
78,501,737
1,361,802
How do I get the theme color in python-pptx?
<p>Simply put, I want to get an RGB value from a <code>ColorFormat</code> object, ie <code>presentation.slides[0].shapes[0].text_frame.paragraphs.runs[0].color</code>.</p> <p>If <code>color.type == MSO_COLOR_TYPE.SCHEME</code> then it means the color is based off one of the slide deck's preset color schemes.</p> <p>Att...
<python><lxml><python-pptx>
2024-05-19 06:15:17
1
8,643
wonton
78,501,376
9,761,768
Python: How to define a type annotation so that the resulting object has both attributes and keys with the same name?
<p>I would like to annotate an object <code>obj</code> so that the type checker (or the language server protocol) understand that it has both some attributes and keys with same name, giving me the correct intellisense.</p> <p>For example:<br /> If <code>obj.foo</code> is a string and <code>obj.bar</code> is an integer:...
<python><visual-studio-code><python-typing><pyright>
2024-05-19 01:20:29
1
753
Diogo
78,501,281
2,593,878
Change axis ticks with shared axes
<p>When I create a figure with shared axes, by default the tick labels go on the leftmost and bottom-most axes.</p> <pre><code>import matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots(2,2, sharex=True) ax[0,0].plot(np.arange(10)) ax[0,1].plot(np.arange(10)) ax[1,0].plot(np.arange(10)) ax[1,1].axis('of...
<python><matplotlib><xticks><multiple-axes>
2024-05-18 23:50:30
0
7,392
dkv
78,501,274
11,959,501
How to design sub frames separately and add them up in main application
<p>I'm trying to design and create my python application with <code>Qt Designer (using PyQt5)</code>.</p> <p>My Application happens to have lots of buttons and &quot;sub windows&quot; (frames basically) which is quite frustrating to design all at once.</p> <p>I am wondering if there's a way to design a Frame or a Widge...
<python><python-3.x><pyqt5><qt-designer>
2024-05-18 23:48:25
1
577
Jhon Margalit
78,501,237
6,573,259
How to have multiple python multi-process save to a variable
<p>Im working on doing some image processing on a very large image 25 088 pixels by 36 864 pixels big. since the image is very large i do the image processing by 256x256 pixel 'tiles'. I noticed that on my windows task manager neither my CPU,RAM,GPU, or SSD reaches 50% utilization when running my function. This lead me...
<python><python-3.x><multiprocessing><python-multiprocessing><python-3.12>
2024-05-18 23:24:37
4
752
Jake quin
78,501,129
1,545,014
Railroad diagrams in Pyparsing: How about Forward() declarations? Rule renaming?
<p>I'm using pyparsing 3.0.9, python 3.9.16, and I'm trying to write a grammar for a (sub-)set of YAML. Not so much for the produced parser, as for the railroad diagrams. The actual state of the program is shown below.</p> <ul> <li><p>The grammar (<a href="https://pyyaml.org/wiki/LibYAML" rel="nofollow noreferrer">defi...
<python><pyparsing>
2024-05-18 22:12:05
1
5,472
jcoppens
78,500,891
5,686,623
Unable to configure logging for Scrapy
<p>Based on scrapy <a href="https://docs.scrapy.org/en/latest/topics/logging.html#logging-settings" rel="nofollow noreferrer">documentatnion</a> I configured some logging settings:</p> <pre><code>LOG_LEVEL = 'INFO' LOG_FORMAT = '%(asctime)s [%(name)s] [%(levelname)s] %(message)s' DATE_FORMAT = '%Y-%m-%d %H:%M:%S' </cod...
<python><logging><scrapy>
2024-05-18 20:07:50
0
1,777
dorinand
78,500,757
8,372,455
Embedding Python in Rust to call external Python libraries
<p>I'm trying to learn how to embed Python into a Rust application. For learning purposes, I want to create a Rust script/app that runs a forever loop. This loop sleeps for a set interval, and upon waking, it uses the Python requests library to fetch the current time from an internet time server. While this isn't a pra...
<python><rust>
2024-05-18 19:12:30
0
3,564
bbartling
78,500,589
9,642,042
Is there a machines module in Anaconda Spyder or a an alternative?
<p>I am creating a new class and saved the data to a .py file. I read that I could call that class from such file using the machines module. I am using Anaconda Spyder and it seems there is no such module. moreover, where I read it seems the author of the article is using 'MicroPython'.</p> <p>see code below. Notice th...
<python><anaconda><spyder>
2024-05-18 18:08:10
1
301
Eyal Marom
78,500,471
5,024,699
Reading small files is too slow
<p>I have 3 millions small jpeg images (256x256 resolution). When I read them using the PIL library in python (using PIL.Image.open method), the reading time is highly variable. It can take as low as 1ms and as high as 500ms, there is a huge variance in this reading time. The average reading time is 20ms. After I read ...
<python><image><performance><python-imaging-library><filesystems>
2024-05-18 17:15:11
0
1,538
Rodolphe LAMPE
78,500,243
7,123,797
Lexeme evaluation in Python
<p><a href="https://en.wikipedia.org/wiki/Lexical_analysis" rel="nofollow noreferrer">Wikipedia</a> makes a clear distinction between the concept of a lexeme and the concept of a token:</p> <blockquote> <p>Lexing can be divided into two stages: the scanning, which segments the input string into syntactic units called l...
<python><token>
2024-05-18 15:50:13
2
355
Rodvi
78,500,230
7,195,666
Elasticsearch bulk API: how do I know which error "belongs" to which document
<p>I want to use <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html</a></p> <p>with <code>raise_on_error=False</code>.</p> <p>When some of the documents given to the bulk operat...
<python><elasticsearch>
2024-05-18 15:45:36
1
2,271
Vulwsztyn
78,500,180
5,722,359
How to resolve these make install errors for Python 3.11.9?
<p>I am trying to configure and &quot;make install&quot; Python 3.11.9. However, it just quite without building a <code>lib</code> folder and <code>bin</code> folder is empty. Done on Ubuntu 22:04 installed with Python 3.10.12. Below are just a few.</p> <p>Commands sent from debug folder:</p> <pre><code>../configure --...
<python><ubuntu-22.04>
2024-05-18 15:25:21
1
8,499
Sun Bear
78,500,158
11,648,332
How to Implement Cell Execution Control and JavaScript Alerts in Azure Databricks Notebooks?
<p>I am trying to replicate some functionalities in Azure Databricks notebooks that I previously used in Jupyter notebooks, specifically related to controlling the visibility of notebook cells and showing JavaScript alerts and executing cells within the notebook. Below are three code snippets that work perfectly in Jup...
<javascript><python><jupyter-notebook><azure-databricks>
2024-05-18 15:16:09
1
447
9879ypxkj
78,500,113
6,999,569
Generating character ranges in python
<p>I want to &quot;translate&quot; integer values in the range from 0 to 26 to characters 'A' to 'Z', but that seems harder in python than in C++, where it is allowed to add integer values to char variables.</p> <p>The other attempt to generate an array with consecutive characters from a range is apparently also not po...
<python>
2024-05-18 15:00:01
1
846
Manfred Weis
78,500,055
1,967,110
VSCode shows imported function as not defined, but the script runs correctly
<p>I'm trying to import functions located in a Python file outside of my Visual Studio Code workspace. Let’s say my structure is:</p> <pre><code>folder/ β”œβ”€β”€ workspace/ β”‚ └── main.py β”‚ └── python_scripts/ └── utils └── __init__.py └── functions.py </code></pre> <p>And let’s say from main...
<python><visual-studio-code><pylance>
2024-05-18 14:36:43
1
889
Sulli