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,033,762
3,840,940
Caused by: java.lang.NullPointerException: Cannot invoke "org.apache.flink.types.Row.getFieldNames(boolean)" because "from" is null
<p>I try to implement Apache Flink jdbc codes which read data from Apache Kafka and insert them into MySQL. First I make simple codes which read data from Kafka single topic and insert into MySQL single table. Below are the codes.</p> <pre><code>from title_flink_stream import TITLE_FLINK_STREAM from pyflink.common im...
<python><apache-flink><flink-streaming><pyflink>
2024-09-28 08:35:17
0
1,441
Joseph Hwang
79,033,456
3,156,085
Why does ctypes also load standard C library functions and how could I prevent that?
<p>EDIT: The problem was completely misdiagnosed and was related to linking rather than <code>ctypes</code> itself (the libc is implicitly linked with gcc) and I found an actual solution somewhere else. Hence the duplicate flag.</p> <hr /> <ol> <li><p>Loading a homemade shared library with <code>ctypes</code> seems to ...
<python><ctypes>
2024-09-28 04:45:14
0
15,848
vmonteco
79,033,035
12,131,013
What binary format is the binary mesh export and how can it be converted to ASCII with Python?
<p>I have generated some large meshes using Gmsh via the Python API. The ASCII files can be Gigabytes. Since binary files are smaller and faster to read, I set Gmsh to save the mesh files in binary format. My current issue is trying to figure out how to read that binary mesh back into Python in an interpretable format....
<python><binary-data><gmsh>
2024-09-27 22:10:23
1
9,583
jared
79,032,931
7,693,707
SciPy curve_fit covariance of the parameters could not be estimated
<p>I am trying to estimate the Schott coefficients of a glass material given only its <code>n_e</code>(refraction index at <code>e</code> line) and <code>V_e</code>(<a href="https://en.wikipedia.org/wiki/Abbe_number" rel="nofollow noreferrer">Abbe number</a> at <code>e</code> line).</p> <p>Schott is one way to represen...
<python><scipy><curve-fitting>
2024-09-27 21:16:16
2
1,090
Amarth GΓ»l
79,032,873
418,413
How to arbitrarily nest some data in a django rest framework serializer
<p>An existing client is already sending data in a structure like…</p> <pre><code>{ &quot;hive_metadata&quot;: {&quot;name&quot;: &quot;hive name&quot;}, &quot;bees&quot;: [{&quot;name&quot;: &quot;bee 1&quot;, &quot;name&quot;: &quot;bee 2&quot;, ...}] } </code></pre> <p>For models like:</p> <pre><code>class H...
<python><django><django-rest-framework><django-serializer>
2024-09-27 20:52:56
1
77,713
kojiro
79,032,867
6,775,670
Coroutine function generic type alias
<p>I'm trying to achieve a typing shorthand for coroutines just like basic callables like Callable[[..args..], ..return value..]</p> <p>My idea is to write something like that, but in the attempt, I cannot understand how TypeAlias would later match where the P, and where the RV...</p> <pre><code>P = ParamSpec('P') RV =...
<python><pycharm><python-typing>
2024-09-27 20:45:14
0
1,312
Nikolay Prokopyev
79,032,841
825,227
Parse dataframe into list of subinterval dataframes for processing
<p>I have a dataframe, <strong>esu_tos</strong>:</p> <pre><code>Time TickType Price Size 2023-08-13 15:10:46.166 1 4487.25 1 2023-08-13 15:10:47.375 1 4487 1 2023-08-13 15:10:54.656 1 4487.25 2 2023-08-13 15:10:57.627 1 4487 1 2023-08-13 15:10:57.628...
<python>
2024-09-27 20:36:48
1
1,702
Chris
79,032,813
718,057
How do I tell mypy that except() will bail a pytest test?
<p>The following code works, but I fell like I shouldn't have to write it:</p> <pre class="lang-py prettyprint-override"><code>def test_transaction(self, the_client): [...] transaction: Transaction = transactions.filter([...]).first() # NOTE: this is stupid and unnecessary just to satisfy mypy....
<python><django><testing><python-typing><mypy>
2024-09-27 20:26:01
0
626
Skaman Sam
79,032,773
277,329
Stuck on scraping with BeautifulSoup while learning. Need some pointers
<p>I started learning screen scraping using BeautifulSoup. To get started I took a wikipedia article in the following format</p> <pre><code>&lt;table class=&quot;wikitable sortable jquery-tablesorter&quot;&gt; &lt;caption&gt;&lt;/caption&gt; &lt;thead&gt; &lt;tr&gt; &lt;th colspan=&quot;2&qu...
<python><web-scraping><beautifulsoup>
2024-09-27 20:08:15
1
2,212
motiver
79,032,746
7,387,243
no such option: --platform linux-x86-64 when running pip install --platform
<p>I get an error:</p> <blockquote> <p>no such option: --platform linux-x86-64</p> </blockquote> <p>when using: <code>python -m pip install --platform linux-x86-64.</code></p> <p><code>python -m pip --version</code> shows 24.2.</p> <p><code>python -m pip install --help</code> shows --platform argument in the list.</p> ...
<python><pip>
2024-09-27 19:55:06
1
777
Telion
79,032,626
607,722
What does _weakrefset calls in python stack trace mean?
<p>I captured stack traces of a running Python process and noticed many <code>_weakrefset.py</code> calls at the end of the trace.</p> <p>These <code>_remove</code> calls are never explicitly called in the code.</p> <p>Does anyone know what this is about?</p> <p>Samples:</p> <pre><code>/usr/local/lib/python3.11/datacla...
<python>
2024-09-27 19:05:52
1
1,686
user607722
79,032,620
279,097
Polars: series to column broadcast
<p>This code used to work with polars &lt; 1:</p> <pre><code>df.with_columns(pl.Series('k_list', [0, 1])).explode('k_list') </code></pre> <p>But now I have this error: SΓ©ries k_list, length 2 doesn't match the dataframe height of ...</p> <p>What is the proper way to add a series forn each row of a column?</p>
<python><python-polars>
2024-09-27 19:01:38
1
415
Mac Fly
79,032,568
774,575
How to force a lambda function to return an object rather than the None value of the last method on the object?
<p>Sometimes I cannot use a lambda function on an object because the last method applied to the object returns <code>None</code>. What is the trick to be able to return the object itself instead of the method returned value?</p> <p>Example, I want to get the updated copy of the dictionary instead of <code>None</code>:<...
<python><lambda>
2024-09-27 18:39:21
1
7,768
mins
79,032,509
3,655,069
png file not creating in visual studio code for mingrammer diagram
<p>I am running a sample mingrammer diagram python code provided <a href="https://diagrams.mingrammer.com/docs/getting-started/examples" rel="nofollow noreferrer">here</a> in Microsoft Visual Studio Code. It will create a <code>.png</code> file as output but I am getting some file with some text content. Like below:</p...
<python><python-3.x>
2024-09-27 18:14:11
0
3,594
Sun
79,032,494
14,958,374
User actions graph layout calculation
<p>So, I have a weighted directed graph. Each node represents a page in web site, each node represents user action on moving from one page to another, weight means the amount of users that have performed such action. I need to calculate a good informative layout for this graph, that will be informative for visual analy...
<python><ocr><directed-graph><graph-layout><user-activity>
2024-09-27 18:08:08
0
331
Nick Zorander
79,032,225
562,970
Aggregating output from langchain LCEL elements
<p>I have two chains, one that generates a document and one that creates a short document resume. I want to chain them, using the output from the first on inside the other one. But I want to get both outputs in the result.</p> <p>Before LCEL, I could do it using LLMChain's output_key parameter. With LCEL, there seems t...
<python><langchain><py-langchain>
2024-09-27 16:30:32
1
1,546
Igor Deruga
79,031,970
15,520,615
Unable to generate ERD diagram with Python code
<p>The following Python is designed to generate an ERD using Visual Studio Code.</p> <p>The chart is to created locally with matplotlib. The code executes without any errors, however the ERD diagram shows blank.</p> <p>The python code is as follows:</p> <pre><code>import matplotlib.pyplot as plt # Define the entities ...
<python><matplotlib>
2024-09-27 15:12:46
1
3,011
Patterson
79,031,934
2,626,865
match OptionMenu and Button width (and resizable images in expandable containers)
<p>I have an OptionMenu and a Button in adjacent rows of the same column of a grid. I don't want the grid to manage the size of these widgets, because it can make the widgets much too wide. Instead, I would like for the OptionMenu and Button to be a fixed size - the maximum of the Button width, the OptionMenu width, an...
<python><tkinter><tkinter-layout>
2024-09-27 15:04:31
1
2,131
user19087
79,031,876
505,328
Why does redis report no subscribers to a channel after I subscribe to that channel without errors?
<p>I am trying to send realtime feedback over websockets, and I'm doing that by sending data over redis from a rest-api server to a websocker server (both written in python/django). In the websocket server, I subscribe to a channel named &quot;events&quot; like this:</p> <pre><code>redis_connection = redis.Redis( h...
<python><django><redis><publish-subscribe><redis-stack>
2024-09-27 14:52:54
1
379
WindowsWeenie
79,031,830
15,358,800
How to convert list of calendar dates into to_datetime in pandas
<p>I have some function which returns list of holidays. The list looks so</p> <pre><code>['30 May 2024','1 May 2024', '29 Aug 2024', '14 Aug 2024', '19 May 2024'] </code></pre> <p>When iam trying to do</p> <pre><code>print(pd.to_datetime(['30 May 2024','1 May 2024', '29 Aug 2024', '14 Aug 2024', '19 May 2024'])) </cod...
<python><pandas>
2024-09-27 14:43:10
1
4,891
Bhargav
79,031,752
2,056,452
ipywidgets interactive with variable containers of widgets
<p>For some interactive data analysis with Jupyter and ipywidgets, I generate a number of widgets depending on the data.</p> <p>I.e. eventually I have a number of GridBoxes with Checkboxes, RangeSliders and ColorPickers which I layout in a Tab-Widget.</p> <p>Now I tried to use</p> <pre><code>categories = [&quot;A&quot;...
<python><jupyter-notebook><ipywidgets>
2024-09-27 14:22:29
2
13,801
derM
79,031,616
268,847
Python request to second endpoint fails after using client certificate to first endpoint
<p>I am using Python's <code>requests</code> package to make API calls. I have <em>two</em> different API endpoints I am making calls against. The first is to &quot;https://api.example.com&quot; and the second is to &quot;https://work.myserver.com&quot;. The first API endpoint requires the use of a client certificate w...
<python><python-requests><client-certificates>
2024-09-27 13:42:53
0
7,795
rlandster
79,031,470
1,914,781
python notify thread exit with multiple loops
<p>I have code with two loops in thread, I wish to exit the thread after done in main thread.</p> <p>Currently I use a global variable to notify it but it looks not good since multiple thread access the same variable. And code looks ugly to break in multiple loops.</p> <p>What's graceful way to exit thread in this case...
<python><python-3.x><multithreading>
2024-09-27 12:58:55
1
9,011
lucky1928
79,031,454
7,307,125
How to add vertical line to existing plot in matplotlib
<p>I have a large dataset (5M points) to visualise. There are datapoints and time axes.<br /> There are events in time, where values changing significantly.<br /> I want to add two 'clickable' elements in form of vertical lines to mark two of mentioned events, later I want to display time values of them and calculated ...
<python><matplotlib>
2024-09-27 12:54:48
1
351
smajli
79,031,420
8,722,421
Holoviews / Bokeh - redim an axis making no difference
<p>Trying to resequence the heatmap such that y-axis actually runs from 0 to -19 <em>under</em> the x-axis (like a normal negative would descend downward).</p> <p>Instead, regardless of sort order onto redim.values it &quot;ascends&quot; from 0 to -19 on the y-axis. See encircled axis in red.</p> <p><a href="https://i....
<python><holoviews>
2024-09-27 12:47:57
1
1,285
Amiga500
79,030,989
4,096,572
Problems moving f2py-based Python module from numpy.distutils to scikit-build-core
<p>I maintain <a href="https://github.com/johncoxon/tsyganenko" rel="nofollow noreferrer">a Python module called Tsyganenko</a> which currently has a <code>setup.py</code> file as below:</p> <pre><code>from numpy.distutils.core import Extension, setup ext = Extension('geopack', sources=['src/tsyganenko...
<python><cmake><f2py><scikit-build>
2024-09-27 10:44:31
2
605
John Coxon
79,030,984
2,515,313
How to delete old class file referenced in django migration
<pre><code>class Migration(migrations.Migration): dependencies = [ (&quot;buckets&quot;, &quot;0001_auto_20230420_2018&quot;), ] operations = [ # Delete existing tables migrations.RunSQL( sql=buckets.my_models.models.RefObjModel.get_create_table_sql(), reverse_sql=migrations.RunSQL.noop, ...
<python><django><django-models>
2024-09-27 10:43:35
2
954
RQube
79,030,890
19,475,185
Cannot schedule Google Colab Pro+ when using Gspread, Selenium
<p>I have a Colab notebook which connects to my Drive, authenticates for Gspread, downloads &amp; installs Chromium with Selenium, downloads &amp; uses XVFB and pyvirtualdisplay. The notebook runs several python .py files from my Drive.</p> <p>When I try to schedule it, it fails to run. The copy of the notebook doesn't...
<python><google-colaboratory>
2024-09-27 10:17:27
1
10,508
Barry the Platipus
79,030,706
7,403,431
Python, numpy and the cacheline
<p>I try to follow <a href="https://igoro.com/archive/gallery-of-processor-cache-effects/" rel="nofollow noreferrer">https://igoro.com/archive/gallery-of-processor-cache-effects/</a> in python using <code>numpy</code>. Though it does not work and I don't quite understand why...</p> <p><code>numpy</code> has fixed size ...
<python><numpy><cpu-cache>
2024-09-27 09:24:17
1
1,962
Stefan
79,030,673
5,490,316
Message: session not created: This version of ChromeDriver only supports Chrome version 114 Current browser version is 129.0.6668.60 with binary path
<p>I'm using selenium and ChromeDriver, worked with it several times and have no errors. Suddenly today I got this warning:</p> <blockquote> <p>The chromedriver version (114.0.5735.90) detected in PATH at C:\Work\Scrape\chromedriver.exe might not be compatible with the detected chrome version (129.0.6668.60); currently...
<python><google-chrome><selenium-webdriver><selenium-chromedriver>
2024-09-27 09:15:59
1
387
louislugas
79,029,563
11,626,909
How to scrape all customer reviews?
<p>I am trying to scrape all reviews in this website - <a href="https://www.backmarket.com/en-us/r/l/airpods/345c3c05-8a7b-4d4d-ac21-518b12a0ec17" rel="nofollow noreferrer">https://www.backmarket.com/en-us/r/l/airpods/345c3c05-8a7b-4d4d-ac21-518b12a0ec17</a>. The website says there are 753 reviews, but when I try to sc...
<python><beautifulsoup>
2024-09-27 01:21:24
2
401
Sharif
79,029,557
1,890,061
Polars dataframe: how to efficiently aggregate over many non-disjoint groups
<p>I have a dataframe with columns <code>x</code>, <code>y</code>, <code>c_1</code>, <code>c2</code>, ..., <code>c_K</code>, where K is somewhat large (K β‰ˆ 1000 or 2000).</p> <p>Each of the columns <code>c_i</code> is boolean column, and I'd like to compute an aggregation <code>f(x, y)</code> over rows where where <cod...
<python><python-polars>
2024-09-27 01:17:40
2
804
Kevin
79,029,447
1,048,404
KeyError: 'Name' in pipenv/vendor/importlib_metadata/_adapters.py:54 using pipenv
<p>I got this weird error in my CI/CD pipeline running in GCP Cloud build.</p> <blockquote> <p>Package installation failed... KeyError: 'Name' site-packages/pipenv/vendor/importlib_metadata/_adapters.py:54 everything is working locally when runnning <code>pipenv install</code>.</p> </blockquote> <p>I'm running in <code...
<python><cicd><google-cloud-build><pipenv><kaniko>
2024-09-26 23:52:39
1
1,772
allexiusw
79,029,400
6,599,898
Regular expression for Python to detect a string and find code block corresponding to the string
<p>I have below text</p> <pre><code>text = ''' here are some examples @with some text @then some more text @ some more@text @moretext probedetail how are you something is going on } how has it been weather is good ''' </code></pre> <p>I want to do the following -</p> <ol> <li>Find a string 'probedetail'.</li> <li>Find ...
<python><regex>
2024-09-26 23:26:45
1
301
Harneet.Lamba
79,029,223
3,879,857
Order of system-wide locations and virtual environment in `sys.path`
<p>I created a virtual environment using</p> <pre class="lang-none prettyprint-override"><code>python -m venv venv </code></pre> <p>Now I'm opening a Python shell without activating the virtual environment by running</p> <pre><code>import sys print(sys.path, sys.prefix) </code></pre> <p>I get</p> <pre class="lang-none ...
<python><python-3.x><python-venv>
2024-09-26 21:37:55
2
887
MaPo
79,029,220
14,250,641
Efficient Mapping of Average Scores Across Interval Windows
<p>I have a df of genomic intervals with millions of rows for example:</p> <pre><code>chromosome start end 1 300 500 1 400 600 ... ... ... </code></pre> <ol> <li>find the center of each interval (+/- 250 from the center the start/end)</li> </ol> <pre><code>chromosome start ...
<python><pandas><dataframe><matplotlib><bioinformatics>
2024-09-26 21:36:08
1
514
youtube
79,029,168
3,453,776
How to unit test a gRPC client by simulating a grpc.GrpcError in Python
<p>I have implemented a gRPC server and and client <a href="https://github.com/avinassh/grpc-errors/blob/master/python/client.py" rel="nofollow noreferrer">following this example</a>. I'm using the <code>grpc.ServicerContext.abort_with_status()</code> method to raise the exceptions in the server.</p> <p>The unit tests ...
<python><grpc><grpcio>
2024-09-26 21:15:17
0
571
nnov
79,029,009
12,336,422
How to get nice types from python `dataclass` without instantiating the class
<p>Let's say I have the following class:</p> <pre class="lang-py prettyprint-override"><code>from dataclasses import dataclass from typing import Annotated @dataclass class Pizza: price: Annotated[float, &quot;money&quot;] size: Annotated[float, &quot;dimension&quot;] @dataclass class Topping: ...
<python><python-typing><python-dataclasses>
2024-09-26 20:24:18
1
733
sams-studio
79,028,930
19,299,757
How to maximize browser window in Playwright
<p>I've 2 questions related to python playscript when launching a browser. Looks like I can use</p> <pre><code>def test_has_title(page: Page): page.goto(&quot;https://my-url.com&quot;) </code></pre> <p>Another way is</p> <pre><code>with sync_playwright() as p: browser = p.chromium.launch(headless=False, args=[&quo...
<python><playwright><playwright-python>
2024-09-26 19:53:26
2
433
Ram
79,028,844
11,951,910
Is it possible to get the owner of a file from S3 bucket
<p>I am new to aws and have been tasked with a few aws s3 related items. One is can I get the owner of a file in S3. Multiple people are uploading files to S3, but I would like to get the original owner. After downloading any file locally it has me as the owner when I check the properties. Checking S3 it looks like th...
<python><python-3.x><amazon-web-services><amazon-s3>
2024-09-26 19:23:53
0
718
newdeveloper
79,028,838
12,162,229
Polars Rolling Mean, fill start of window with null instead of shortened window
<p>My question is whether there is a way to have null until the full window can be filled at the start of a rolling window in polars. For example:</p> <pre><code>dates = [ &quot;2020-01-01&quot;, &quot;2020-01-02&quot;, &quot;2020-01-03&quot;, &quot;2020-01-04&quot;, &quot;2020-01-05&quot;, &quo...
<python><python-polars>
2024-09-26 19:22:12
2
317
AColoredReptile
79,028,654
7,872,857
fmin_slsqp taking too long
<p>I am using fmin_slsqp to find the weights that minimize mean squared error. The weights need to be positive. For each pair of X and y, it takes ~10 seconds. (Each X is (10, 1000) and y is (10,)). I have 8000 pairs that need to be calculated:(</p> <p>Is there any error with the code, or it is just my data takes too l...
<python><scipy><scipy-optimize>
2024-09-26 18:13:59
2
481
Anonny
79,028,538
19,299,757
Playwright timeout
<p>I am very new to playwright and I am trying a simple POC where I open a URL, enter user and password and click LOGIN button. Then checking if a particular title is present or not. This is my simple code.</p> <pre><code>import pytest import asyncio from playwright.sync_api import Page, expect, async_playwright @pyte...
<python><pytest><playwright><playwright-python>
2024-09-26 17:35:41
0
433
Ram
79,028,133
7,758,213
Managing all modules imports in a single file in Python/Django project, while avoiding circular imports
<p>I’m working on a Django project that has numerous imported modules across various files, sometimes totaling up to 50 lines of imports per page. To reduce cluttering, I created a single file, &quot;imports.py&quot;, to centralize my imports.</p> <p>Here’s a brief example of what it looks like:</p> <pre><code>from dat...
<python><django><python-import>
2024-09-26 15:49:51
1
968
Izik
79,028,098
1,088,979
How to detect and properly handle signal.SIGTERM in Windows 11
<p>In my Python program, I need to detect and gracefully handle <code>signal.SIGTERM</code></p> <p>I use the following two small Python programs to send and handle <code>signal.SIGTERM</code>:</p> <p><strong>Receiver and handler:</strong></p> <pre><code>import signal, time, os def handle_signal(signum, frame): glo...
<python>
2024-09-26 15:40:05
0
9,584
Allan Xu
79,028,082
20,591,261
Polars Pivot Dataframe an count the cumulative uniques ID
<p>I have a polars dataframe that contains and ID, DATE and OS. For each day i would like to count how many uniques ID are until that day.</p> <pre><code>import polars as pl df = ( pl.DataFrame( { &quot;DAY&quot;: [1,1,1,2,2,2,3,3,3], &quot;OS&quot; : [&quot;A&quot;,&quot;B&quot;,&qu...
<python><python-polars>
2024-09-26 15:37:24
1
1,195
Simon
79,027,972
477,311
Pandas rolling window operation inconsistent results based on the length of a series
<p>I stumbled upon a weird behaviour in the windowing functionality in pandas, it seems that a rolling sum operation gives different results depending on the length of the series itself.</p> <p>Given 2 series:</p> <pre class="lang-py prettyprint-override"><code>s1 = pd.Series(np.arange(5), index=range(5)) # s1 = 1, 2...
<python><pandas>
2024-09-26 15:12:19
1
886
lukstei
79,027,967
2,104,933
openpyxl.chart is creating a new series for each row
<p>I have a simple python script to create an excel spreadsheet with a line chart and single series of data. The data in the spreadsheet is as desired. When opened in MS Excel, the chart contains a separate series for each row in the table. The chart looks fine when opened with Numbers app.</p> <pre><code> from open...
<python><openpyxl>
2024-09-26 15:08:35
0
2,259
lilbiscuit
79,027,896
461,212
How to reroute stdout and stderr to a Frame element (i.e. not to a Multiline element)
<p>This <code>Multiline</code> rerouting below works, but this is not matching what I exactly want:</p> <pre><code>output_layout = [ [sg.Text(&quot;OUTPUT&quot;)], [sg.Multiline(size=(0,5), font='Courier 8', text_color=&quot;#DBFF33&quot;, expand_x=True, expand_y=True, write_only=True, border...
<python><user-interface><pysimplegui>
2024-09-26 14:50:44
2
9,395
hornetbzz
79,027,767
5,868,293
Time series classification, using lagged data, and exogenous time series variables for exploratory features
<p>I have the following pandas dataframe</p> <pre><code>import pandas as pd pd.DataFrame({ 'region': [1,1,1,1,2,2,2,2,3,3,3,3], 'week': [1,2,3,4,1,2,3,4,1,2,3,4], 'rain': [1,1,0,1,1,1,1,1,1,0,0,0], 'clouds': [1,1,0,0,0,0,1,0,1,0,0,0] }) region week rain clouds 0 1 1 1 1 1 1 2 1 1...
<python><time-series>
2024-09-26 14:17:48
0
4,512
quant
79,027,616
16,869,946
Pandas groupby transform mean with date before current row for huge huge dataframe
<p>I have a Pandas dataframe that looks like</p> <pre><code>df = pd.DataFrame([['John', '1/1/2017','10'], ['John', '2/2/2017','15'], ['John', '2/2/2017','20'], ['John', '3/3/2017','30'], ['Sue', '1/1/2017','10'], ['Sue', '2/2...
<python><pandas><dataframe><group-by>
2024-09-26 13:41:17
3
592
Ishigami
79,027,535
2,774,589
Rotate view for cartopy
<p>I am creating the following map.</p> <pre class="lang-py prettyprint-override"><code>import matplotlib.pyplot as plt import cartopy.crs as ccrs import cartopy.feature as cfeature # Create a plot using the PlateCarree projection fig, ax = plt.subplots(figsize=(10, 6), subplot_kw={'projection': ccrs.PlateCarree()}) ...
<python><matplotlib><cartopy>
2024-09-26 13:24:19
1
1,660
iury simoes-sousa
79,027,337
14,202,481
Polars not using all available CPU
<p>I'm running code that performs vectorized calculations using the lazy Polars approach. The code loops approximately 4,000 times and takes about 4 seconds to execute. However, when I check my CPU usage, I see that only 25% of the CPU is being utilized. I would like to increase CPU usage to 80%–100%.</p> <p>I'm runnin...
<python><python-polars>
2024-09-26 12:39:06
0
557
mr_robot
79,027,200
21,049,944
How to change a list element by index in a list column
<p>I have a column of lists in my polars dataframe. I would like to access and change a value by list index.</p> <p><strong>Example input</strong></p> <pre class="lang-py prettyprint-override"><code>df = pl.DataFrame({ &quot;values&quot;: [ [10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110...
<python><list><python-polars>
2024-09-26 12:03:50
2
388
Galedon
79,027,048
4,984,633
Do something different on last row of a tuple
<p>I'm manually constructing a JSON so I want the last element to not have a <code>,</code> seperator before the <code>]</code>.</p> <p>This my code and the documentation says len() works for tuples but I can't get it to work. The <code>data</code> is a tuple constructed from a SQLite.fetchall() and it has been validat...
<python><sqlite><tuples>
2024-09-26 11:22:55
2
525
Ben Jones
79,027,016
2,546,099
Disable python package imports depending on available libraries
<p>In my python-based project I am using several functions from <code>PySide6</code>. These functions require libraries such as <code>libGl.so</code> and <code>libglib.so</code>. This is not a problem when using the package as a standalone-package.</p> <p>When packaging it into a docker-image and using <code>python:3.1...
<python><docker>
2024-09-26 11:12:43
1
4,156
arc_lupus
79,026,988
13,858,293
np.zeros and np.arange results different dtype
<p><a href="https://i.sstatic.net/lHbWqx9F.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lHbWqx9F.png" alt="enter image description here" /></a> <a href="https://i.sstatic.net/XIllkPlc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/XIllkPlc.png" alt=", " /></a></p> <p>Why a = np.arange(...
<python><numpy>
2024-09-26 11:05:33
1
326
Elizabeth S
79,026,948
2,728,074
Using Clarabel as a backend of CVXPY
<p>Is this a bug, or is there something fundamental I'm missing with how to use cvxpy?</p> <p>Consider this code for a least squares optimisation for a 3 variable vector with 3 measurements:</p> <pre><code>import scipy import numpy as np import cvxpy as cvx import clarabel A = np.array([[-43.83695965, 0.34990409, -...
<python><optimization><mathematical-optimization><least-squares><cvxpy>
2024-09-26 10:58:13
0
469
Charlie
79,026,867
9,998,989
Highlight certain points in Plotly through dropbown bar
<p>I am trying to make an interactive PCA plot with Plotly. I am having some troubles in highlighting a certain marker that a user wants to see in the plot.</p> <p>Instead of highlighting a marker there is a square around it.</p> <p>My attempt at the code:</p> <pre><code>from sklearn.datasets import make_blobs import ...
<python><plotly>
2024-09-26 10:42:58
1
752
Noob Programmer
79,026,693
258,414
Numpy Error : Implicit conversion to a NumPy array is not allowed. Please use `.get()` to construct a NumPy array explicitly
<p>I 'am trying to find similar vector with spacy and numpy. I found the code following url : <a href="https://stackoverflow.com/questions/54717449/mapping-word-vector-to-the-most-similar-closest-word-using-spacy">Mapping word vector to the most similar/closest word using spaCy</a></p> <p>But I'm getting type error</p>...
<python><numpy><gpu><spacy>
2024-09-26 10:03:53
1
857
onder
79,026,491
2,685,189
generic gdb python helpers to traverse c++ STL container and invoke callback for the elements
<p>I want to debug c++ application core and gcore files.<br> This includes creating reports for relevant data in data repositories of the binary.<br> Those repositories are based on STL containers (std::map&lt;&gt;, std::set&lt;&gt;, std::vector&lt;&gt;, ...)<br> For this I use my own &quot;generic&quot; python helpers...
<python><c++><stl><gdb>
2024-09-26 09:20:43
1
363
Frank Bergemann
79,026,315
5,016,028
Using Langchain ChatOpenAI functionality with LiteLLM
<p>I have initially written two functions to provide me with a model and function calling directly from OpenAI. Here is the complete code:</p> <pre><code>from langchain_openai import ChatOpenAI def get_open_ai(temperature=0, model='gpt-4'): llm = ChatOpenAI( model=model, temperature = temperature, ) r...
<python><machine-learning><openai-api><large-language-model><py-langchain>
2024-09-26 08:44:39
1
4,373
Qubix
79,026,305
1,406,168
Managed Identity on Databricks - DefaultAzureCredential failed to retrieve a token from the included credentials
<p>I am trying to send a message to a service bus in azure.</p> <p>But I get following error:</p> <pre><code> ServiceBusError: Handler failed: DefaultAzureCredential failed to retrieve a token from the included credentials. </code></pre> <p>This is the line that fails:</p> <pre><code>credential = DefaultAzureCredentia...
<python><databricks><azure-databricks><azureservicebus>
2024-09-26 08:42:41
1
5,363
Thomas Segato
79,026,303
5,682,416
How to use Python argparse to have lazily loaded subcommands
<p>I have a python package with a lot of sub commands and sub-sub commands. It is organized somewhat like this:</p> <p>main.py</p> <pre><code>import argparse from sum import prepare_arg_parser as prepare_sum_parser from sub import prepare_arg_parser as prepare_sub_parser parser = argparse.ArgumentParser() sub_parsers...
<python><lazy-loading><argparse>
2024-09-26 08:41:46
1
1,828
Hugal31
79,026,269
17,580,381
An apparent contradiction between pylance and mypy
<p>Consider the following class:</p> <pre><code>class CM: def __init__(self): ... def __enter__(self) -&gt; CM: return self def __exit__(self, *_): ... </code></pre> <p>mypy reports no issues with this. However, pylance highlights the type hint and indicates &quot;CM&quot; is not def...
<python>
2024-09-26 08:34:20
1
28,997
Ramrab
79,026,175
1,443,630
autoreload python without master in uwsgi + flask
<p>I have a Flask server, and for several reasons I need to set <code>master = false</code> in my uwsgi configuration. But due to this, I'm not able to auto reload on file changes anymore.</p> <p>This is my uwsgi ini</p> <pre class="lang-ini prettyprint-override"><code>[uwsgi] master = false enable-threads = true wsgi-...
<python><flask><uwsgi>
2024-09-26 08:09:53
1
2,075
Mahesh Bansod
79,026,122
9,209,203
how to run pySpark
<p>I am new in Python and trying to run the <a href="https://github.com/krishnaik06/Pyspark-With-Python/blob/main/Tutorial%202-%20PySpark%20DataFrames-%20Part%201.ipynb" rel="nofollow noreferrer">code</a> below in VS. But I am keep getting <code>SyntaxError: invalid syntax</code>. How to get around with this ?</p> <pre...
<python><pyspark>
2024-09-26 07:58:18
0
3,031
symkly
79,025,937
565,635
Why does converting an old datetime to EST on Windows offset time by an additional ~18 minutes?
<p>Consider the following:</p> <pre class="lang-py prettyprint-override"><code>from datetime import datetime, timezone from zoneinfo import ZoneInfo dt = datetime(1677, 9, 22, 5, 0, tzinfo=timezone.utc) print(dt.astimezone(ZoneInfo(&quot;EST&quot;))) </code></pre> <p>On my MacOS machine this prints <code>1677-09-22 00...
<python><datetime><timezone>
2024-09-26 07:09:10
0
119,106
orlp
79,025,822
10,451,021
Recursively check each test case project/CR Id field value for consistency
<p>In Azure DevOps, I am trying to get project/CR Id field's value recursively from each user story and all its child items -&gt; test cases at any level and match each test case's project/CR Id field's value for consistency, if they are present and same. I am getting the below error using SDK.</p> <pre><code>import os...
<python><azure-devops>
2024-09-26 06:38:34
1
1,999
Salman
79,025,728
1,522,776
Issue with publishing python function as ontology function
<p>Now that palantir workshop supports using python repository as well along with typescript repository, I'm trying to create a python function which makes some api call and return a string value. The code works as expected in the live preview, but when I try to deploy to the ontology function and run it, it starts thr...
<python><palantir-foundry><palantir-foundry-api><palantir-foundry-security>
2024-09-26 06:05:31
0
301
Arvind
79,025,626
3,404,377
In Sphinx, how can I generate a page with information about all items in a domain?
<p>I've written a custom domain in Sphinx. It has directives that register items (which all end up in the <code>data</code> member) then parallel builds get merged together with <code>merge_domaindata</code>.</p> <p>I want to create an index-like page that lists every item registered in the domain. I want more control ...
<python><documentation><python-sphinx><docutils>
2024-09-26 05:27:34
1
1,131
ddulaney
79,025,556
2,210,825
Clustering longitudinal data with labels?
<p>I have longitudinal data as follows:</p> <pre><code>import pandas as pd # Define the updated data with samples only in 'sample_A' or 'sample_B' data = { 'gene_id': ['gene_1', 'gene_1', 'gene_1', 'gene_1', 'gene_1', 'gene_1', 'gene_1', 'gene_1', 'gene_1', 'gene_1', 'gene_2', 'gene...
<python><scipy><cluster-analysis><longitudinal>
2024-09-26 04:54:57
2
1,458
donkey
79,025,526
16,382,765
Escaping quotes in Python subprocesses for Windows
<p>I'm trying to terminate a Python program that uses many threads on its own.</p> <p>If I'm not mistaken, just <code>sys.exit()</code> works fine.</p> <p>However, to guard against my many mistakes, including losing references to threads, I tried the following:</p> <pre><code>subprocess.Popen(['start', 'cmd.exe', '/c',...
<python><windows><batch-file><subprocess>
2024-09-26 04:43:24
1
523
enoeht
79,025,496
4,984,633
SQLite3 DB to front end in flask just creates empty tags for each row
<p>I've read the docs and looked at 2 different tutorials all do it the same way but my front end renders with empty tags but it creates a tag for the expect items in the database.</p> <p>The desired behaviour is that there is a p tag for each row in the feedback column of the database.</p> <p>I have a SQLite3 db, that...
<python><sqlite><flask>
2024-09-26 04:23:08
1
525
Ben Jones
79,025,343
5,105,207
Read 16 bit color depth image with Wand
<p>I want to process a 24-bit image in 16-bit mode with Wand. This is how I read the image</p> <pre class="lang-py prettyprint-override"><code>from wand.image import Image as WandImage source_file='img/in.tif' with WandImage(filename=source_file, depth=16) as img: print(img.depth) print(max(img.export_pixels(...
<python><wand>
2024-09-26 02:48:41
0
1,413
Page David
79,025,263
1,573,761
Using TypeGuard on class method
<h2>Problem</h2> <p>I am trying to get something as follows to work:</p> <pre class="lang-py prettyprint-override"><code>from abc import ABC class Foo(ABC): @property @abstractmethod def value(self) -&gt; str | None: ... def has_value(self) -&gt; TypeGuard[FooWithValue]: return self.value is n...
<python><python-typing><typeguards>
2024-09-26 02:02:58
1
457
JP-Ellis
79,025,212
96,588
Treating a specific argument value format as deprecated in argparse
<p>I'm changing some <code>argparse</code> code to no longer require a unit for a numeric value, since the unit is always the same (&quot;m&quot;). I'd like the code to emit a deprecation warning only when called with the &quot;m&quot; suffix on the parameter value. That is, <code>./foo.py --bar=1m</code> should emit a...
<python>
2024-09-26 01:23:36
1
59,558
l0b0
79,025,180
9,090,039
Why does read block after select in Python?
<p>It is understood that in exceptional circumstances, a read may block after select(2) declares that data is available for reading for something like a network socket, where checksum failures or other buffer manipulations may cause data to be discarded between <code>select</code> and <code>read</code>.</p> <p>However,...
<python><python-3.x>
2024-09-26 01:03:52
1
950
Benjamin Crawford Ctrl-Alt-Tut
79,025,101
6,449,740
which is the best way to convert json into a dataframe?
<p>I have a question about the best way to convert this JSON to a Dataframe:</p> <p>JSON data:</p> <pre class="lang-json prettyprint-override"><code>{ &quot;myschema&quot;: { &quot;accounts&quot;: { &quot;load_type&quot;: &quot;daily&quot;, &quot;fields&quot;: { &quot...
<python><json><dataframe><apache-spark><pyspark>
2024-09-26 00:00:19
1
545
Julio
79,025,002
5,231,990
Improving speed and robustnes for opencv HoughCircles for only single circle
<p>There are many threads on how to detect multiple circles via OpenCV's <code>HoughCircles</code> function, and I understand that this is a complex task with no single good answer. However, maybe someone can give some hints for parameters for the specific problem of only finding a single circle. I also want to only ge...
<python><opencv><computer-vision><data-fitting><hough-transform>
2024-09-25 22:52:34
0
360
Swift
79,024,937
6,618,225
Applying function to filtered columns in Pandas
<p>I have a Pandas Dataframe with 4 different columns: an ID, country, team and a color that is assigned to each player following a specific order.</p> <p>I want to create a new column that contains a number based on the team and the country that simply counts up following the color order, however colors may appear mor...
<python><pandas><dataframe>
2024-09-25 22:11:55
2
357
Kai
79,024,518
1,954,677
how to make jinja2 remove newlines/spaces generated by tags but preserve newlines/spaces generated by static text
<p>When using a jinja2 template such as this</p> <pre><code>A {%- if flag == &quot;0&quot; %} X {%- elif flag == &quot;1&quot; %} Y {%- endif %} B </code></pre> <p>my intuitive goal would be, whatever <code>A,B,X,Y</code> are, to simply &quot;insert the contents <code>X,Y</code> between <code>A,B</code>&quot;.</p> <p>T...
<python><jinja2>
2024-09-25 19:33:37
1
3,916
flonk
79,024,508
1,641,112
How can I change the color of the file name and line number in pytest output?
<p><a href="https://i.sstatic.net/8rDrNSTK.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8rDrNSTK.png" alt="enter image description here" /></a></p> <p>I have the above output from pytest to make it easier to find info of interest. One thing I'd like to do is make he file name and line number pop out i...
<python><pytest>
2024-09-25 19:27:56
1
7,553
StevieD
79,024,431
228,014
Subclass of pathlib.Path doesn't support "/" operator
<p>I'm attempting to create a subclass of <code>pathlib.Path</code> that will do some manipulation to the passed string path value before passing it along to the base class.</p> <pre><code>class MyPath(Path): def __init__(self, str_path): str_path = str_path.upper() # just representative, not what I'm actua...
<python><python-3.x><oop><subclassing><pathlib>
2024-09-25 19:02:32
1
4,396
Kyle
79,024,371
4,449,954
Persisting token/auth record cache for DeviceCodeCredentials
<p>I have a Python program that submits pipelines to Azure ML. This code typically runs on headless Linux VMs, and authenticates with Azure using the <code>DeviceCodeCredentials</code> flow. I want to cache these credentials so that I can run this script many times and only have to re-authenticate every so often (e.g. ...
<python><azure><azure-identity>
2024-09-25 18:44:32
1
1,080
stuart
79,024,206
6,449,740
How convert json file into dataframe with spark?
<p>One of my task today is read a simpe json file convert into dataframe and do a loop over the dataframe and do some validations, etc...</p> <p>This is part of my code:</p> <pre><code>bucket_name = 'julio-s3' json_source = 'source/' file_2 = &quot;tmp.json&quot; json_s3_path = f&quot;s3://{bucket_...
<python><dataframe><apache-spark><pyspark><aws-glue>
2024-09-25 17:49:27
1
545
Julio
79,024,195
785,404
Is there an inline way to assert that a value is not None?
<p>I have this code</p> <pre class="lang-py prettyprint-override"><code>if foo: bar = 1 else: bar = maybe_return_int(baz) </code></pre> <p>The return type of <code>maybe_return_int</code> is <code>Optional[int]</code>, so mypy complains</p> <pre><code>error: Incompatible types in assignment (expression has type...
<python><python-typing><mypy>
2024-09-25 17:47:30
2
2,085
Kerrick Staley
79,024,193
4,181,335
How to get the pandas version in Python with numpy >= 2.0.0 installed
<p>One usually gets the pandas version in Python as follows:</p> <pre><code>import pandas print(pandas.__version__) </code></pre> <p>However if numpy version 2.0.0 or higher is installed, and the pandas version is &lt; 2.2.2 it typically crashes as follows on the import statement:</p> <p><a href="https://i.sstatic.net/...
<python><pandas><numpy>
2024-09-25 17:47:14
1
343
Aendie
79,024,143
18,769,241
How to turn a tuple of lists into a list?
<p>I am using Python 2.7 to turn a tuple of lists (of 2 elements) of float into a list of floats (<code>([1.0],[2.0])</code> =&gt; <code>[1.0,2.0]</code>) like the following:</p> <pre><code>[tuple_lists[0][0],tuple_lists[1][0]] </code></pre> <p>Is there a pythonic 2.7 way to do so in a more elegant way?</p>
<python><python-2.7>
2024-09-25 17:29:42
2
571
Sam
79,024,070
4,875,641
Python Multiprocessing seems to require a seemingly wrong combination of imports
<p>I have the following code using the multiprocessor package</p> <pre><code>print ('cpu count=',multiprocessing.cpu_count()) event = multiprocessing.Event() # Assign an event object lock = multiprocessing.Lock() with Pool(processes=2) as pool: for serverNum in range (2): pool.apply_async(funcCall, (event...
<python><import><multiprocessing><nameerror>
2024-09-25 17:06:35
2
377
Jay Mosk
79,024,010
2,893,712
Pandas Return Corresponding Column Based on Date Being Between Two Values
<p>I have a Pandas dataframe that is setup like so:</p> <pre><code>Code StartDate EndDate A 2024-07-01 2024-08-03 B 2024-08-06 2024-08-10 C 2024-08-11 2024-08-31 </code></pre> <p>I have a part of my code that iterates through each day (starting from 2024-07-01) and I am trying to return the...
<python><pandas>
2024-09-25 16:50:29
1
8,806
Bijan
79,024,006
6,163,621
Determine or indicate if Linux process is started by web user (apache) or cronjob?
<p>On my server, python scripts can be started either through a cronjob, or through our website (via apache). Sometimes I want to kill processes started by one, but not the other. When I run <code>htop</code>, it looks like the user is &quot;ubuntu&quot; for both. Is there a way to determine natively which process s...
<python><linux><apache><cron>
2024-09-25 16:49:36
0
9,134
elPastor
79,023,989
2,127,650
Implementing image drag-and-drop functionality with DearPyGui framework challenged me too much
<p>A few days ago I started learning the <strong>DearPyGui</strong> framework, got excited with speed and results. However, I encountered challenges when I tried to implement drag-and-drop functionality for images. The usage seems straightforward as the methods <code>add_image</code> and <code>add_image_button</code> h...
<python><drag-and-drop><dearpygui>
2024-09-25 16:43:41
1
658
zviad
79,023,929
550,235
type specific autocomplete in vscode python
<p>Assuming I'm properly typing my python code, is there a way or extension to get vscode to only offer autocomplete options that are appropriate for that parameter?</p> <p>For example:</p> <pre><code>from enum import IntEnum class MyEnum(IntEnum): OneThing = 1 Another = 2 EvenMore = 3 def my_function(pa...
<python><visual-studio-code><autocomplete>
2024-09-25 16:29:33
1
2,730
Russ Schultz
79,023,865
17,721,722
How to Handle Multiple Date Formats in a Single Column with PySpark?
<p>I am working with a DataFrame in PySpark that contains a column named <code>datdoc</code>, which has multiple date formats as shown below:</p> <pre><code>datdoc 07-SEP-24 07-SEP-2024 07-SEP-2024 07-SEP-2024 07-SEP-24 07-SEP-24 07-SEP-2024 07-SEP-2024 07-SEP-2024 07-SEP-2024 07-SEP-2024 </code></pre> <p>I need to par...
<python><apache-spark><date><pyspark><apache-spark-sql>
2024-09-25 16:05:45
2
501
Purushottam Nawale
79,023,711
16,869,946
Python list with NumPy arrays as elements
<p>I have a list with NumPy arrays as elements that looks like this:</p> <pre><code>[array([ 0.2, -2.3, 5.3]), array([-1.6, -1.7, 0.3]), array([ 2.4, -0.2, -3.0]), array([-4.1, -2.3, -2.7])] </code></pre> <p>and I want to convert it into 3 lists, each with elements from the columns of the above list. So the desire...
<python><arrays><list><numpy>
2024-09-25 15:25:34
5
592
Ishigami
79,023,648
8,543,025
Setting Axis Range for Subplot in Plotly-Python
<p>I am trying to manually set the range of one (shared) y-axis in a plotly multi-plot figure, but for some reason, it also affects the range of the other y-axes.<br /> Take a look at this example. I'll start by creating a 3x2 figure, with a shared y-axis per row.</p> <pre><code>import numpy as np import plotly.graph_o...
<python><python-3.x><plotly>
2024-09-25 15:08:58
1
593
Jon Nir
79,023,570
4,211,279
Vertically scroll multiple plots in Tkinter
<p>I would like to draw multiple plots with Matplotlib, add them to a Tkinter frame (stack them one below the other), and be able to scroll vertically between the plots. Each plot shold fill the x-direction, and have a minimum y-height, so that if the total height of the multiple plots is above the height of the window...
<python><matplotlib><tkinter>
2024-09-25 14:54:56
1
930
Pier Paolo
79,023,460
11,450,166
Handling Circular Imports in Pydantic models with FastAPI
<p>I'm developing a <strong>FastAPI</strong> application organized with the following module structure.</p> <pre><code>... β”‚ β”œβ”€β”€ modules β”‚ β”‚ β”œβ”€β”€ box β”‚ β”‚ β”‚ β”œβ”€β”€ routes.py β”‚ β”‚ β”‚ β”œβ”€β”€ services.py β”‚ β”‚ β”‚ β”œβ”€β”€ models.py # the sqlalchemy classes β”‚ β”‚ β”‚ β”œβ”€β”€ schemas.py # the pydantic schemas β”‚ β”‚ β”œβ”€...
<python><sqlalchemy><fastapi><pydantic><circular-dependency>
2024-09-25 14:33:18
2
311
Biowav
79,023,426
7,971,750
Older versions of lxml and pandas on WIndows 10 in 2024
<p>I've recently ran into an issue where I have to install an older (4.6.2) version of lxml to use an older version of pandas, however, when installing via <code>pip install lxml==4.6.2</code>, the wheel simply won't build due to missing libxml2.</p> <p><a href="https://www.zlatkovic.com/projects/libxml/index.html" rel...
<python><pandas><lxml><libxml2>
2024-09-25 14:26:45
0
322
bqback