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,121,611
9,363,181
Unable to get the postgres data in the right format via Kafka, JDBC source connector and pyspark
<p>I have created a table in <code>Postgres</code>:</p> <pre><code>CREATE TABLE IF NOT EXISTS public.sample_a ( id text COLLATE pg_catalog.&quot;default&quot; NOT NULL, is_active boolean NOT NULL, is_deleted boolean NOT NULL, created_by integer NOT NULL, created_at timestamp with time zone NOT NULL,...
<python><apache-spark><pyspark><apache-kafka><jdbc>
2024-10-24 11:06:25
2
645
RushHour
79,121,591
109,525
Equivalent of pandas.Series.dt.ceil in polars
<p>I'm trying to round timestamp to the next minutes in polars.</p> <p>For example:</p> <ul> <li><code>2023-01-01 10:05:00</code> should stay <code>2023-01-01 10:05:00</code></li> <li><code>2023-01-01 10:05:01</code> should be <code>2023-01-01 10:06:00</code></li> </ul> <p>This works in pandas with ceil:</p> <pre class...
<python><timestamp><python-polars>
2024-10-24 11:01:38
1
14,153
0x26res
79,121,361
9,593,060
delta-rs writing with Pandas gets stuck for big dataset
<p>I am using <a href="https://github.com/delta-io/delta-rs" rel="nofollow noreferrer">delta-rs</a> to read and process some delta tables with Pandas.</p> <p>I made several experiments with the following pretty simple code:</p> <pre><code>from deltalake import write_deltalake, DeltaTable df = DeltaTable(s3_table_URI, ...
<python><pandas><python-polars><delta-lake><delta-rs>
2024-10-24 09:51:37
0
1,618
Mattia Surricchio
79,121,307
1,479,670
How to port a PyCharm project from linux to windowsp
<p>I have a python application for the command line which i built using PyCharm. To run it, i call <code>source venv\bin\activate</code> and then start my application with <code>python my_app.py</code>.</p> <p>Now to port this to windows i copied the whole project directory (python files and venv) to my PyCharmProject...
<python><pycharm>
2024-10-24 09:37:45
1
1,355
user1479670
79,121,185
11,826,257
pip install pyspectra does not find existing numpy installation
<p>I want to analyze near-infrared (NIR) spectra in Python. My spectra are stored in the <a href="https://en.wikipedia.org/wiki/SPC_file_format" rel="nofollow noreferrer">spc file format</a>. So I need a tool that lets me import such files. &quot;Pyspectra&quot; seems to be a good module for this. However, I am unable ...
<python><import><modulenotfounderror>
2024-10-24 09:09:39
1
407
Staehlo
79,121,019
9,356,136
Regex negative lookahead with variable text before and after keywords
<p>I have a string which contains two keywords, keyword_1 and keyword_2, and an integer which follows on keyword_2.</p> <p>I want to extract the integer, but only if a particular keyword, keyword_neg, does not occur between keyword_1 and keyword_2.</p> <p>Additionally (and I believe this is where the problem is coming ...
<python><regex>
2024-10-24 08:28:25
0
367
Spaniel
79,120,999
2,971,574
Use IOUtils.setByteArrayMaxOverride in pyspark
<p>I'm facing the error</p> <p>&quot;org.apache.poi.util.RecordFormatException: Tried to allocate an array of length 100,335,238, but the maximum length for this record type is 100,000,000.&quot;</p> <p>when trying to read an excel file using pyspark in databricks. That's my syntax:</p> <pre><code>spark.read.format(&qu...
<python><pyspark><databricks>
2024-10-24 08:20:55
1
555
the_economist
79,120,980
4,614,404
Roboflow device management. In which GPU is the model loaded?
<p>I am experimenting with the SDK of Roboflow, I haven't found documentation on device management. I have three questions:</p> <ol> <li>Is the model loaded to GPU by default?</li> <li>What happens when multiple GPUs are available?</li> <li>And how do I define in which GPU I want the model allocated?</li> </ol> <p><str...
<python><pytorch><gpu><roboflow>
2024-10-24 08:15:48
1
2,024
Victor Zuanazzi
79,120,656
32,043
Pipenv installation fails in one directory but not in the other
<p>I have a strange problem with Python. I'm using pipenv to manage my virtual environment. I upgraded an environment from 3.9 to 3.11 and now <code>pipenv install</code> fails. Error is that the hashes do not match.</p> <p>As soon as I copy the <code>Pipfile</code> to another direcotry and try it there, it works smoot...
<python><linux><pipenv><debian-bookworm>
2024-10-24 06:40:57
1
24,231
guerda
79,120,587
270,043
Optimization of PySpark code to do comparisons of rows
<p>I want to iteratively compare 2 sets of rows in a PySpark dataframe, and find the common values in another column. For example, I have the dataframe (<code>df</code>) below.</p> <pre><code>Column1 Column2 abc 111 def 666 def 111 tyu 777 abc 777 def 222 tyu 333 ewq 888 </code>...
<python><dataframe><pyspark><optimization>
2024-10-24 06:17:59
2
15,187
Rayne
79,120,579
6,783,666
How can a duration scalar from Django models be implemented for Strawberry GQL?
<p>How can Django duration model fields be exposed in a Strawberry GraphQL API? Is there a standard implementation for the ISO8601 duration format or does a custom scalar field need to be implemented?</p> <pre><code>from django.db import models class MyModel(models.Model): name = models.CharField(max_length=255) ...
<python><strawberry-graphql>
2024-10-24 06:14:27
1
3,849
Moritz
79,120,568
698,182
Restrict CPU core usage on linux in python program using Piper TTS library
<p>For some reason when I'm using <strong>PiperTTS</strong> to generate speech using <code>taskset -c 2,3 python myprogram.py</code> the system does not restrict processing to the cores I specify.</p> <p>When I use another library, such as <code>llama-cpp-python</code>, <code>taskset</code> is able to restrict the core...
<python><linux><task>
2024-10-24 06:11:05
2
1,931
ekcrisp
79,120,446
461,212
Get a sum value from nested attributes, in Python
<p>I need to code a SEARCH class, so that accessing its attributes by their nested representation(s).</p> <p><strong>Attributes and their relationship</strong>: the goal of the 'SEARCH' class is to obtain a serie of consecutive integer numbers 'n', selecting 1 or summing 2 of the predefined A, B, C, D constants, as fol...
<python><python-3.x><nested-attributes>
2024-10-24 05:19:46
2
9,395
hornetbzz
79,120,040
1,277,239
Concatenate a few row vectors into a matrix
<p>Four 1X3 row vectors, trying to concatenate them into a 4X3 martrix. Here is my code that is not working:</p> <pre><code>ul = np.array([-320, 240, 1]) ur = np.array([320, 240, 1]) br = np.array([320, -240, 1]) bl = np.array([-320, -240, 1]) corners =np.concatenate( (ul,ur, br, bl), axis=1) </cod...
<python><arrays><matrix>
2024-10-24 00:02:20
1
2,912
Nick X Tsui
79,120,026
2,476,977
Removing whitespace within matplotlib plot with subplots
<h2>Problem</h2> <p>When generating the following plot, I am not able to remove the white frame that appears around each graph (note: colors were changed to make the problem more obviously visible).</p> <p><a href="https://i.sstatic.net/QsVgfFhn.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QsVgfFhn.pn...
<python><matplotlib><plot><seaborn>
2024-10-23 23:55:27
0
5,027
Ben Grossmann
79,119,670
480,118
postgres: select and return results before dropping table
<p>I have the following sql, where i want to return the selected data</p> <pre><code>insert into test(id,name) select * from tmp_tbl on conflict(id) do update set name = EXCLUDED.name; with selected_data as (select * from tmp_tbl) select * from selected_data; drop table if exists tmp_tbl; </code></pre> <p>THis is the p...
<python><sql><postgresql><psycopg2><psycopg3>
2024-10-23 20:47:49
1
6,184
mike01010
79,119,637
219,153
What is the equivalent of np.polyval in the new np.polynomial API?
<p>I can't find a direct answer in NumPy documentation. This snippet will populate <code>y</code> with polynomial <code>p</code> values on domain <code>x</code>:</p> <pre><code>p = [1, 2, 3] x = np.linspace(0, 1, 10) y = [np.polyval(p, i) for i in x] </code></pre> <p>What is the new API equivalent when <code>p = Polyno...
<python><numpy><polynomials>
2024-10-23 20:36:00
1
8,585
Paul Jurczak
79,119,610
1,488,821
Getting the module and class of currently executing classmethod in Python
<p>For code that exists in a module named <code>some.module</code> and looks like this:</p> <pre class="lang-py prettyprint-override"><code>class MyClass: @classmethod def method(cls): # do something pass </code></pre> <p>I'd like to know in the block marked as &quot;do something&quot; what the module name, the ...
<python><introspection>
2024-10-23 20:25:18
1
2,030
Ivan Voras
79,119,492
3,486,684
Bar chart with multiple bars using xOffset, when the x-axis is temporal?
<p>Here's a small example:</p> <pre class="lang-py prettyprint-override"><code>import altair as alt import polars as pl source = pl.DataFrame( { &quot;Category&quot;: list(&quot;AAABBBCCC&quot;), &quot;Value&quot;: [0.1, 0.6, 0.9, 0.7, 0.2, 1.1, 0.6, 0.1, 0.2], &quot;Date&quot;: [f&quot;202...
<python><vega-lite><altair>
2024-10-23 19:42:53
1
4,654
bzm3r
79,119,386
7,346,633
Unsupported platform tag manylinux_2_31_riscv64
<p>When trying to upload a wheel distribution to PyPI, all other architectures were accepted, except for <code>manylinux_2_31_riscv64</code>. I could not find any documentation on how to submit packages targeting the riscv64 platform. Does anyone know what the tag name should be? <a href="https://i.sstatic.net/jde7TuFd...
<python><pypi><python-wheel>
2024-10-23 19:06:46
0
2,231
Hykilpikonna
79,119,356
2,971,574
Create a path structure that can be navigated like classes
<p>Assume there is the following path structure in a storage account that I've created myself:</p> <pre><code>basepath (e.g. /mount/basefolder/) ├── folder_a ├── folder_b ├── folder_c | ├── folder_c1 | ├── folder_c2 | └── a_file.txt | └── folder_d | ├── another_file.csv | ├── folder_d1 └── folder_d2...
<python>
2024-10-23 18:58:23
1
555
the_economist
79,119,271
19,549,205
How to Execute Parameterized Queries in GridDB Using the Python Client?
<p>I'm using the GridDB Python client to interact with my time-series data. I want to execute a parameterized query to prevent SQL injection and handle dynamic values efficiently. When I run the code I get this error:</p> <pre><code>[0] -1: Parameter index out of range </code></pre> <p>Here's the code I'm working with:...
<python><database><prepared-statement><griddb>
2024-10-23 18:35:36
1
314
PhantomPhreak1995
79,119,238
1,145,760
How to approach: csv objects specified on command line or in a file
<p>I would like to accept 2d points provided on the command line or read from a file. Example command line positional parameter input:</p> <pre><code>( 4,-1),(0, 0) , (3,3) </code></pre> <p>example CSV file</p> <pre><code>4, -1 0,0 3 ,3 </code></pre> <p>I.e. &quot;...
<python><csv>
2024-10-23 18:26:26
2
9,246
Vorac
79,119,214
2,554,349
How can i understand what is running IronPython or Python?
<p>With what command inside code can I understand that IronPython or Python is running?</p>
<python><ironpython>
2024-10-23 18:21:53
2
392
Dmitry Dronov
79,118,920
184,379
How to test urllib3 retry adapter for connection errors
<p>my Retry class is</p> <pre><code>class RetryRequest: &quot;&quot;&quot; Module for Retry logic on requests API requests &quot;&quot;&quot; def __init__(self): # Retry Logic retry_server_errors = requests.adapters.Retry( total=20, connect=10, status...
<python><python-requests><urllib3>
2024-10-23 16:47:24
1
17,352
Tjorriemorrie
79,118,853
12,076,197
Create new dataframe rows when column has comma delimited values
<p>Example dataframe:</p> <pre><code>name col1 col2 col3 bob bird 78 1000 alice cat 55 500,600,700 rob dog 333 20,30 </code></pre> <p>Desired Dataframe that adds rows when col3 has comma delimited string values:</p> <pre><code>name col1 col2 col3 b...
<python><pandas><dataframe>
2024-10-23 16:32:50
2
641
dmd7
79,118,841
1,368,534
How can I migrate from Poetry to UV package manager?
<p>I'm planning to switch from poetry to the uv Python package manager, but I can't find any migration guides. Currently, I'm using <a href="https://python-poetry.org/" rel="noreferrer">Poetry</a> and already have a <em>pyproject.toml</em> file.</p> <p>What key(s) should be modified or added to migrate properly to uv?<...
<python><python-poetry><uv>
2024-10-23 16:29:39
4
2,886
mdegis
79,118,795
7,800,760
Ollama python library not closing socket
<p>In my python code I am doing the following:</p> <pre><code>ollama_client = ollama.Client(host='http://localhost:11434') </code></pre> <p>and then with this I am calling my embedder function:</p> <pre><code>def get_embedding(text: str, ollama_client: ollama.Client) -&gt; List[float]: &quot;&quot;&quot; G...
<python><ollama>
2024-10-23 16:16:19
0
1,231
Robert Alexander
79,118,703
3,225,420
How to format Graph API call to update Excel cell?
<p>I want to update an Excel cell value (hosted in SharePoint) using the Microsoft Graph API. Documentation is <a href="https://learn.microsoft.com/en-us/graph/api/range-update?view=graph-rest-1.0&amp;tabs=http" rel="nofollow noreferrer">here</a>.</p> <p>I have had success with other API calls (format updates, clearin...
<python><excel><azure><microsoft-graph-api><microsoft-graph-files>
2024-10-23 15:50:14
1
1,689
Python_Learner
79,118,646
12,415,855
OpenAI Assistant - working for one API_Key but not for another one?
<p>i have the following simple assistant using the gpt-4o model -</p> <pre><code>import os import sys from dotenv import load_dotenv from openai import OpenAI path = os.path.abspath(os.path.dirname(sys.argv[0])) fn = os.path.join(path, &quot;.env&quot;) load_dotenv(fn) CHATGPT_API_KEY = os.environ.get(&quot;CHATGPT_A...
<python><openai-api>
2024-10-23 15:32:36
2
1,515
Rapid1898
79,118,250
4,752,874
Python Unable to Map Dataframe Columns by Name to List of Objects
<p>I have a dataframe like the table shown below.</p> <div class="s-table-container"><table class="s-table"> <thead> <tr> <th>id</th> <th>shop</th> <th>var1</th> <th>var2</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>a</td> <td>a</td> <td>b</td> </tr> <tr> <td>2</td> <td>b</td> <td>b</td> <td>c</td> </tr> </tbody> </...
<python><dataframe><list><object>
2024-10-23 13:57:34
1
349
CGarden
79,118,142
10,069,064
How to upgrade NumPy in Ubuntu?
<p>My OS is Ubuntu 22.04.4 LTS. The &quot;pip list&quot; command tells that I have the NumPy 1.21.5. But I need a newer version of the NumPy.</p> <p>I am trying to install the NumPy package whith next command:</p> <pre><code>pip install --upgrade numpy==2.1.2 </code></pre> <p>But here is an error:</p> <pre><code>&lt;.....
<python><numpy><ubuntu><meson-build>
2024-10-23 13:31:53
4
304
Arseniy
79,118,016
8,249,257
How to preserve data types when working with pandas and sklearn transformers?
<p>While working with a large sklearn <code>Pipeline</code> (fit using a <code>DataFrame</code>) I ran into an error that lead back to a wrong data type of my input. The problem occurred on an a single observation coming from an API that is supposed to interface the model in production. Missing information in a single ...
<python><pandas><scikit-learn>
2024-10-23 13:01:28
2
478
Woodly0
79,117,556
8,832,008
multiprocessing queues losing reference when passed to worker process
<p>I am creating a multiprocessing Manager as a global variable in the main process and then create a Queue with this manager for each task I want to process. These Queue objects are then passed into a pool of workers, one queue per task.</p> <p>When these queues are accesses, something is losing its reference, and I c...
<python><multiprocessing><joblib>
2024-10-23 10:38:17
0
1,334
cmosig
79,117,267
2,785,041
Show most recent python logging messages in case of an error
<p>I'm using python <a href="https://docs.python.org/3/library/logging.html" rel="nofollow noreferrer"><code>logging</code></a> to log messages. One module (let's call it <code>checker</code>) produces a lot of tracing information, which is usually omitted (by setting the log level to <code>ERROR</code>) as it otherwis...
<python><logging>
2024-10-23 09:25:13
1
3,434
morxa
79,117,238
9,653,275
Problem installing rgee in R studio on windows machine
<p>I am trying to install <code>rgee</code> in Rstudio and I'm hitting a problem at start. I install <code>rgee</code> and run <code>ee_install (py_env = &quot;rgee&quot;)</code> and I get the following errors. I follow the instructions and run <code>ee_clean_pyenv()</code>. It doesn't seem to do anything but I restart...
<python><r><windows><error-handling><rgee>
2024-10-23 09:17:41
0
541
mikejwilliamson
79,117,121
1,744,834
Polars get all possible categories as physical representation
<p>Given a DataFrame with categorical column:</p> <pre class="lang-py prettyprint-override"><code>import polars as pl df = pl.DataFrame({ &quot;id&quot;: [&quot;a&quot;, &quot;a&quot;, &quot;a&quot;, &quot;b&quot;, &quot;b&quot;, &quot;b&quot;, &quot;b&quot;], &quot;value&quot;: [1,1,1,6,6,6,6], }) res = df.w...
<python><python-polars><categorical>
2024-10-23 08:46:30
1
118,326
roman
79,117,088
17,473,587
Discrepancy in Record Count Between Django ORM and Raw SQL Query
<p>I'm encountering an issue where the count of records returned by a Django ORM query does not match the count returned by a raw SQL query. Here is the relevant part of my Django view:</p> <pre><code>start_date = datetime(2024, 10, 19, 0, 0, 0) end_date = datetime(2024, 10, 19, 23, 59, 59) dbug = Reservations.objects....
<python><sql><django><postgresql><psql>
2024-10-23 08:35:50
0
360
parmer_110
79,116,936
4,483,043
how to add images in the markdown html gradio
<p>i am adding images in my Gradio header, I explored the documentation and found that, it is allowed to keep markdown or html and load images and apply CSS on it to make it stylized, however I have tried and it doesn't load the images properly.</p> <pre><code>import gradio as gr gr.HTML(&quot;&lt;img src='image.png' ...
<python><html><user-interface><chatbot><gradio>
2024-10-23 07:49:29
1
437
Farooq Zaman
79,116,922
1,587,132
why does fun.__code__.co_names not include all global variables?
<p>Here's some python code:</p> <pre><code>dict_de_en = {'we':'wir', 'love':'lieben', 'cake':'kuchen'} def fun1(sentence): return &quot; &quot;.join([dict_de_en[w] for w in sentence.split()]) def fun2(sentence): dd = dict_de_en return &quot; &quot;.join([dd[w] for w in sentence.split()]) print(&quot;f1:&q...
<python>
2024-10-23 07:44:43
2
1,556
Berry Boessenkool
79,116,803
13,641,358
os.system multiple return values
<p>Is it possible to get multiple return values for a <code>os.system()</code> call?</p> <p>The following example always returns 0 even though the python call returns an error code</p> <pre class="lang-py prettyprint-override"><code>ret_val = os.system(f&quot;python3 -c 'import sys; sys.exit(1)' | tee test.log&quot;) <...
<python><python-3.x>
2024-10-23 07:23:31
1
663
ucczs
79,116,088
2,449,857
Handling the presence or absence of a token in EBNF / Lark
<p>I'm making early steps with the Lark library in Python and am really looking forward to replacing a lot of awful <code>if</code> statements with an EBNF parser..!</p> <p>The task here is interpreting the times written in railway timetables. <code>12:34</code> means the train will stop, <code>12/34</code> means the t...
<python><ebnf><lark-parser>
2024-10-23 00:27:17
1
3,489
Jack Deeth
79,116,021
8,737,211
Python Package Optional Sub-package if Optional Extras Specified
<p>Say I have created a python project <code>foobar</code> with the following layout:</p> <pre><code>foobar ├── __init__.py ├── core/ ├── network/ └── plotting/ </code></pre> <ol> <li>I would like to have <code>pip install foobar</code> to install only the core part of the package, along with core dependencies:</li> </...
<python><pyproject.toml>
2024-10-22 23:26:46
0
494
Campbell McDiarmid
79,116,000
10,203,572
Querying class members variables with DuckDB
<p>I have a codebase with an API to pass a SQL query to run for execution, but that same API does not provide a way to pass a variable. Meaning I do not get to pass a variable in the same scope as where the query runs:</p> <pre><code>class SampleClientClass(BaseExecutionAPI): def __init__(self): self.conn =...
<python><pandas><duckdb>
2024-10-22 23:10:14
1
1,066
Layman
79,115,743
15,008,906
sqlalchemy self referential 1 to many declarative relationship
<p>I'm still pretty new to sqlalchemy so any guidance is appreciated. I have the following class that does a 1 to 1 relationship with itself and works just fine:</p> <pre><code>class Unit(Base): __tablename__ = 'unit' uic: Mapped[str] = mapped_column(String(10), primary_key=True) parent = relationship(&quot;Unit...
<python><postgresql><sqlalchemy>
2024-10-22 21:11:27
1
413
Jon Hayden
79,115,566
6,564,826
How to reenter to the container script execution?
<p>I have container and python script that need to be run forever, for example:</p> <pre><code>import time if __name__ == &quot;__main__&quot;: n = 0 while True: print(f&quot;Script is running! I want to see this string ! N is {n}&quot;) n += 1 time.sleep(200) </code></pre> <p>So I</...
<python><docker><cmd><scripting><containers>
2024-10-22 19:58:36
1
361
ooolllooo
79,115,559
8,028,053
requests.get consistent "IncompleteRead" for url
<p>When using requests.get as follows, I'm consistently getting an IncompleteRead error:</p> <p><code>response = requests.get(&quot;https://files.rcsb.org/header/6TAV.pdb&quot;)</code></p> <p>Tried, but did not work:</p> <ul> <li>changing from https to http based on (<a href="https://stackoverflow.com/questions/1444222...
<python><python-requests>
2024-10-22 19:52:58
1
1,341
fileyfood500
79,115,545
3,078,502
Unexpected output in Python REPL using VS Code on Windows
<p>I have VS Code set up with Python extension, but <em><strong>without</strong></em> Jupyter extension.</p> <p>VS Code lets you send Python code from the editor to what it calls the &quot;Native REPL&quot; (a Jupyter-type interface without full notebook capabilities) or the &quot;Terminal REPL&quot; (the good old Pyth...
<python><visual-studio-code>
2024-10-22 19:46:21
1
609
Lee Hachadoorian
79,115,254
189,418
Raise exception in .map_elements()
<p><strong>Update:</strong> This was fixed by <a href="https://github.com/pola-rs/polars/pull/20417" rel="nofollow noreferrer">pull/20417</a> in Polars <a href="https://github.com/pola-rs/polars/releases/tag/py-1.18.0" rel="nofollow noreferrer">1.18.0</a></p> <hr /> <p>I'm using <code>.map_elements</code> to apply a co...
<python><python-polars>
2024-10-22 17:45:26
2
8,426
foglerit
79,115,170
4,212,870
Operation on all columns of a type in modern Polars
<p>I have a piece of code that works in Polars 0.20.19, but I don't know how to make it work in Polars 1.10.</p> <p>The working code (in Polars 0.20.19) is very similar to the following:</p> <pre><code>def format_all_string_fields_polars() -&gt; pl.Expr: return ( pl.when( (pl.col(pl.Utf8).str.strip()....
<python><dataframe><python-polars>
2024-10-22 17:17:04
2
1,298
Vinícius Queiroz
79,115,080
2,619,429
How to use ruff as fixer in vim with ALE
<p>I'm using ale in vim, and I want to add ruff as fixer for python.</p> <p>So, in .vimrc, I added:</p> <pre><code>let g:ale_fixers = { \ 'python': ['ruff'], \ 'javascript': ['eslint'], ...
<python><ruff><vim-ale>
2024-10-22 16:47:19
1
518
Raoul Debaze
79,114,976
3,641,004
How to call the ctypes function from bytes in Python?
<p>I have the disassamble bytes of a simple function</p> <pre><code>89 4C 24 08 mov dword ptr [sum],ecx while (sum&gt;=1) { 83 7C 24 08 01 cmp dword ptr [sum],1 7C 0C jl doNothing+17h (07FF636C61017h) sum--; 8B 44 24 08 mov eax,dw...
<python><cross-platform><ctypes><exploit>
2024-10-22 16:11:19
1
392
wanyancan
79,114,927
9,094,379
How can I replace direct references "@ file" on requirements file?
<p>I want to run some Python scripts from <a href="https://github.com/thuiar/MIntRec2.0/" rel="nofollow noreferrer">this repository</a>. The repository contains the instructions to run the scripts, including a <code>requirements.txt</code> file. However, the versions for some modules are not specified, but include dire...
<python><python-3.x><pip><requirements.txt>
2024-10-22 15:55:41
1
352
Galo Castillo
79,114,550
2,449,857
Is `mydict.get(x, x)` eqivalent to `mydict.get(x) or x`?
<p>When using a dictionary to occasionally replace values, are <code>.get(x, x)</code> and <code>.get(x) or x</code> equivalent?</p> <p>For example:</p> <pre class="lang-py prettyprint-override"><code>def current_brand(brand_name): rebrands = { &quot;Marathon&quot;: &quot;Snickers&quot;, &quot;Op...
<python><python-3.x><dictionary>
2024-10-22 14:27:44
2
3,489
Jack Deeth
79,114,448
17,289,097
How to integrate and enable Pipeline in Open Web UI
<p>I want to integrate and enable the pipeline text_to_sql_pipeline.py in Open Web UI. The code for text_to_sql_pipeline.py is available in <code>https://github.com/open-webui/pipelines/blob/main/examples/pipelines/rag/text_to_sql_pipeline.py</code></p> <p>Could you please guide me through step by step procedure to ena...
<python><ollama><py-postgresql>
2024-10-22 14:04:46
0
465
Urvesh
79,114,445
15,913,281
Filter the Earliest and Latest Date in Each Month
<p>Given a dataframe like the one below, how do I filter for the earlest and latest date in each month? Note the actual data runs to tens of thousands of rows.</p> <p>Input:</p> <div class="s-table-container"><table class="s-table"> <thead> <tr> <th>Date</th> <th>Deg</th> </tr> </thead> <tbody> <tr> <td>02/01/1990</td>...
<python><pandas><numpy>
2024-10-22 14:04:29
1
471
Robsmith
79,114,312
9,134,545
Airflow Mark as success/failure callback
<p>I'm playing a bit with Airflow alerting mechanism, but I can't find anything on how to do use a callback for when tasks/dags state is set manually.</p> <p>I'm primarly using the DockerOperator.</p> <p>I've tried the on_failure_callback and on_success_callback but they only get triggered when the task state is set by...
<python><airflow>
2024-10-22 13:31:24
0
892
Fragan
79,114,216
1,082,349
PyArrow Dataset filtering not working with partitioned parquet files
<p>I save a pandas dataframe as follows:</p> <pre><code>import pyarrow as pa import pyarrow.parquet as pq table = pa.Table.from_pandas(my_df) pq.write_to_dataset(table, root_path=&quot;data/bfl&quot;, partition_cols=['pnr_group']) </code></pre> <p>I can find it stored in a partitioned directory structure like this:</p>...
<python><pandas><parquet><pyarrow>
2024-10-22 13:08:46
1
16,698
FooBar
79,114,033
8,547,986
what's the advantage of `NewType` over `TypeAlias`?
<p>Consider the following example:</p> <pre class="lang-py prettyprint-override"><code> UserId = NewType('UserId', int) ProductId = NewType('ProductId', int) </code></pre> <p>But I can also do, the following:</p> <pre class="lang-py prettyprint-override"><code>UserId: TypeAlias = int ProductId: TypeAlias = int </code><...
<python><python-typing>
2024-10-22 12:21:54
1
1,923
monte
79,113,894
1,152,500
Application logging in Executor/Worker using Azure Databricks python notebooks
<p>I am using <code>Azure Databricks</code> for building and running ETL pipelines. For development, using <code>Databricks notebooks (Python)</code>. My goal is to view the application logs via Spark UI for both codes running on driver and executors.</p> <p>Initially, I was facing issue to view executor logs but as de...
<python><apache-spark><logging><azure-databricks><databricks-notebook>
2024-10-22 11:45:53
1
21,478
Anand
79,113,889
1,455,474
Identify the full path to xxx/library/bin in python
<p>I have an application that depends on intel-fortran-rt</p> <p>When installed via <code>pip install intel-fortran-rt==2021.3.0</code>, the intel fortran runtime dlls are copied into <code>xxx\Library\bin</code></p> <p>The problem is to identify <code>xxx</code> across different python versions, distributions and pla...
<python><python-wheel>
2024-10-22 11:43:23
1
623
Mads M Pedersen
79,113,866
1,028,133
Example of a name clash between enum names and mixin-class methods/attributes?
<p>The <a href="https://docs.python.org/3/howto/enum.html#enum-basic-tutorial" rel="nofollow noreferrer">Python Enum tutorial</a> recommends using upper case names for Enum members &quot;to help avoid issues with name clashes between mixin-class methods/attributes and enum names&quot;.</p> <p>What would be an example o...
<python><enums>
2024-10-22 11:37:00
2
744
the.real.gruycho
79,113,846
7,924,573
sphinx.ext.autodoc: ModuleNotFoundError for external packages
<p>I want to start documenting my flask-based application with Sphinx. Currently, I am trying to figure how to use the autodoc extension. My local modules are all found, but the imports of external libraries does not work in sphinx.</p> <p>I have all my requirements in a <code>requirements.txt</code> file, so I hope th...
<python><flask><python-sphinx><python-venv><autodoc>
2024-10-22 11:33:23
1
843
tschomacker
79,113,663
3,555,685
Getting request_before_redirect.url is None for POSTS requests in Locust Python
<p>Trying to use locust following the documentation, <a href="https://docs.locust.io/en/stable/quickstart.html" rel="noreferrer">https://docs.locust.io/en/stable/quickstart.html</a></p> <pre><code>from locust import HttpUser, task class TestUser(HttpUser): # @task(1) # def health(self): # self.client....
<python><fastapi><load-testing><locust>
2024-10-22 10:44:22
2
362
Dinesh Babu Rengasamy
79,113,523
6,597,296
How to send messages to an XMPP server using only Twisted?
<p>I need to send messages to an XMPP server. Only send - I don't need to process replies, make a bot, or anything like that. When using the <code>xmpppy</code> module, it goes something like this:</p> <pre class="lang-py prettyprint-override"><code>from xmpp import Client from xmpp.protocol import JID, Message jabbe...
<python><xmpp><twisted>
2024-10-22 10:11:33
2
578
bontchev
79,113,520
3,572,950
Is it safe and ok to divide mp3 file like that?
<p>I have an <code>mp3</code> file and want to divide it into several files (&quot;chunks&quot;). I came up with this code (I stole the idea from <a href="https://github.com/django/django/blob/main/django/core/files/base.py#L48" rel="nofollow noreferrer">django</a>):</p> <pre><code>from pathlib import Path class File...
<python><mp3>
2024-10-22 10:10:59
1
1,438
Alexey
79,113,456
5,595,282
Pandas - FutureWarning in concat - how to fix or opt into new behavior
<p>I have code like the following where I split up a dataframe into different groups. The &quot;treatment&quot; group is where I might want to delete rows and/or modify rows; and for performance reasons I split it into away from a group of rows that should survive unchanged.</p> <p>It is guaranteed that all DFs have th...
<python><pandas><dataframe><future-warning>
2024-10-22 09:52:37
1
372
Raubtier
79,113,437
11,714,087
Airflow dag, wait for certain period if triggered at a certain time
<p>I have an airflow DAG dag-A that is triggered from another DAG, sometimes, this dag-A is triggered at 4 pm UTC (midnight EST), and when it gets triggered at midnight EST (4PM UTC), I want it to wait for 30 minutes and then start running at 16:30 UTC.</p> <p>Generally it should run when it is triggered, but if trigge...
<python><airflow>
2024-10-22 09:48:44
1
377
palamuGuy
79,113,288
4,505,998
Strange behaviour with ax.get_xlim and date axis with matplotlib
<p>I worked with temporal data and matplotlib before, so I know that in matplotlib, dates are represented as the number of <em>days</em> since epoch as a float, and that I can use <code>matplotlib.dates</code> to convert dates back and forth to floats.</p> <p>Nevertheless, I encountered a pretty strange problem when us...
<python><pandas><matplotlib>
2024-10-22 09:16:12
1
813
David Davó
79,113,170
948,655
Python Pydantic `TypeAdapter` validate with default for missing attribute
<p>Suppose I have:</p> <pre class="lang-py prettyprint-override"><code>class Thing(pydantic.BaseModel): one: int two: str three: bool adapter = pydantic.TypeAdapter(dict[str, Thing]) raw_data = {&quot;this&quot;: {&quot;one&quot;: 1, &quot;two&quot;: &quot;zwei&quot;}, &quot;that&quot;: {&quot;one&quo...
<python><pydantic>
2024-10-22 08:47:15
1
8,813
Ray
79,113,126
955,273
Is it possible to continue an EWM after appending a row?
<p>I have some quant finance code which does some analysis of stock prices.</p> <p>One thing I need to calculate is an EWMA.</p> <p>When doing research (ie: the historical &quot;batch&quot; world), I have a long list of stock prices, and I can use pandas <code>ewm(...).mean()</code> to calculate my EWMA over that list ...
<python><pandas><dataframe>
2024-10-22 08:37:03
1
28,956
Steve Lorimer
79,112,916
732,546
Why the polyfit second coefficient is not zero?
<p>I have this class exercice and I have a question regarding the second coefficient given by the polyfit function.</p> <p>Python code:</p> <pre><code>import numpy X = [1,2,3,4,5] Y = [1,2,3,4,5] function = numpy.polyfit(X, Y, 1) display(function) </code></pre> <p>Image with the execution of the code below: <a href="ht...
<python>
2024-10-22 07:38:33
0
1,388
Álvaro
79,112,841
20,765,573
AZ CLI runs very slow after a while
<p>I'm experiencing inconsistent slow speeds with the Azure CLI (<code>az-cli</code>). Sometimes commands execute in less than 10 seconds, but at other times, the CLI seems to lock into a state of slowness (80+ seconds for a simple query).</p> <p>This usually occurs after I've been using it for a while or when I have m...
<python><azure><azure-cli>
2024-10-22 07:13:53
1
305
Daniel M.
79,112,805
10,451,021
Unable to trigger Power Automate flow using python script
<p>I am trying to send message on teams using a python script using Power Automate.</p> <pre><code>import requests # Import requests library import datetime # Get current time. now = datetime.datetime.now().strftime(&quot;%Y-%m-%d %H:%M:%S&quot;) # Triggering Power Automate Flow flow_url='https://***/triggers/manual...
<python><microsoft-teams><power-automate>
2024-10-22 07:04:22
1
1,999
Salman
79,112,453
1,447,953
Pandas complex groupby using match criteria in another table
<p>I am having a hard time describing this issue in a general way that would make the question title useful. But here it is. I am trying to merge or group rows in a table based on ids in a column that are declared to belong to certain groups according to a different table. It is complicated further by the ids being com...
<python><pandas><dataframe><group-by><pandas-merge>
2024-10-22 04:36:11
1
2,974
Ben Farmer
79,112,373
9,136,850
PYSAT How to apply Clausify on Equals object when using Equals Object on a CNF?
<p>I am using PySat library.</p> <p>I need to show a cardinality constraint has the same truth value as another literal. Here is my code,</p> <pre class="lang-py prettyprint-override"><code>from pysat.card import CardEnc, ITotalizer from pysat.formula import * cnf2 = ITotalizer(lits=[1,2,3], ubound=1, top_id=100).cnf ...
<python><sat>
2024-10-22 03:43:18
0
354
samarendra chandan bindu Dash
79,112,170
908,390
replit run button installs unwanted python packages that break my project
<p>Public replit:</p> <p><a href="https://replit.com/@mblakele/BugImportDecoupleHumps" rel="nofollow noreferrer">https://replit.com/@mblakele/BugImportDecoupleHumps</a></p> <p>When I run this replit, I see a poetry command that I haven't requested:</p> <pre><code>--&gt; poetry add decouple humps Using version ^0.0.7 fo...
<python><python-poetry><replit>
2024-10-22 01:24:08
3
7,863
mblakele
79,112,091
20,591,261
How to highlight values per column in Polars
<p>I have a Polars DataFrame, and I want to highlight the top 3 values for each column using the <code>style</code> and loc features in Polars. I can achieve this for individual columns, but my current approach involves a lot of repetition, which is not scalable to many variables.</p> <pre><code>import polars as pl imp...
<python><dataframe><python-polars><great-tables>
2024-10-22 00:33:03
2
1,195
Simon
79,111,984
1,937,514
Properly add type annotations to a services container
<p>I am trying to add type annotations to a &quot;service container&quot; with relatively strict typing, but am struggling to define the type hints correctly.</p> <p>Basically, the services container is a glorified dictionary, where the key should be an ABC type, or a Protocol (i.e. the &quot;abstract class&quot;). The...
<python><python-typing>
2024-10-21 23:05:22
0
370
NixonInnes
79,111,951
3,049,987
Python Protocol using keyword-only arguments requires implementation to have different signature
<p>I'm on python 3.10. I'm using PyCharm's default type checker and MyPy. Here is the protocol I defined:</p> <pre class="lang-py prettyprint-override"><code>class OnSubscribeFunc(Protocol): def __call__(self, instrument: str, *, x: int) -&gt; AsyncGenerator: ... </code></pre> <p>When create a method that i...
<python><pycharm><python-typing>
2024-10-21 22:48:34
1
2,046
Tim Woocker
79,111,762
7,657,180
Equivalent vba for python requests
<p>I have the following python code</p> <pre><code>import requests url = 'https://moe-register.emis.gov.eg/account/authenticate' data = {'EmailAddress': '471666845@minia4.moe.edu.eg'} response = requests.post(url, data=data) print('Final URL After Redirection:', response.url) </code></pre> <p>I need the vba equivalen...
<python><vba><python-requests>
2024-10-21 21:07:22
1
9,608
YasserKhalil
79,111,414
11,277,108
scrapy spider using seleniumbase middleware scraping 'chrome-extension' URLs that weren't requested
<p>I'm currently running a scrapy spider using a seleniumbase middleware and for some reason it is scraping <code>chrome-extension</code> URLs. I'm scraping the <code>https://www.atptour.com</code> website and at no point does my scraper request anything other than pages from that website.</p> <p>I've attached below my...
<python><scrapy><seleniumbase>
2024-10-21 19:00:01
1
1,121
Jossy
79,111,113
1,038,501
Which Shapely predicate should be used to distinquish between these LinearRings
<p>In my project there are two use-cases. The red and blue shapes are not overlapping in the first case, but they do in the second.</p> <p><a href="https://i.sstatic.net/eA45LnMv.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eA45LnMv.png" alt="case 1" /></a><br /> <strong>case #1</strong></p> <p><a hre...
<python><geometry><shapely>
2024-10-21 17:18:09
1
716
snow6oy
79,111,112
594,925
Executing code on class (metaclass instance) destruction in python
<p>We have some API that should be shut down (e.g. <code>api.shutdown()</code>) just once per python process and specific only to a particular class (e.g. <code>ControllerA</code>) from a hierarchy of controllers (e.g. <code>Controller</code> inherited by <code>ControllerA</code>, ..., <code>ControllerZ</code>). Can I ...
<python><garbage-collection><metaclass>
2024-10-21 17:17:26
2
628
pevogam
79,111,108
5,527,374
Drawing rectangle in PNG file
<p>TLDR: My goal is simple. I have a PNG file. I want to draw a rectangle in it using Python and save it to a new file.</p> <p>I have a PNG file (attached to this post). All I want to do is draw a rectangle in the image using Python and save the image to a new file. Here's code that doesn't work:</p> <pre><code>import ...
<python><png>
2024-10-21 17:15:32
2
925
tscheingeld
79,110,982
6,394,617
exported jupyter notebook has different syntax highlighting
<p>When I have this Python code in a Jupyter notebook:</p> <pre><code>df = pd.read_csv(&quot;data.csv&quot;, index_col=0) print(df.shape) </code></pre> <p>The <code>read_csv</code> and <code>shape</code> are blue, the <code>&quot;data.csv&quot;</code> is red, and the <code>0</code> and <code>print</code> are green.</p>...
<python><jupyter-notebook><syntax-highlighting>
2024-10-21 16:42:00
1
913
Joe
79,110,973
1,818,059
Can I tell in python if my class is used in context?
<p>I am working on a small hobby project using Python. I wish to &quot;do it right&quot;, and follow common guidelines.</p> <p>Following an example package using SQLite, I can make things work fine by using context.</p> <p>Example:</p> <pre><code>import mypackage as mp with mp.democlass() as dc: dc.dosomething('so...
<python>
2024-10-21 16:37:57
1
1,176
MyICQ
79,110,954
125,244
How to format printing an array in Python
<p>I have an array of 10 elements and I can each of the elements print on a new line formatted 6.2f with</p> <p><code>print(f'{myArray:6.2f}', sep=&quot;\n&quot;)</code></p> <p>But I would like to create string containing what needs to be printed, add a few things and print that string, like:</p> <pre><code> text = 'so...
<python><list><string-formatting>
2024-10-21 16:32:00
3
1,110
SoftwareTester
79,110,939
2,437,514
Break up a sparse 2D array or table into multiple subarrays or subtables
<p>I want to find a way to &quot;lasso around&quot; a bunch of contiguous/touching values in a sparse table, and output a set of new tables. If any values are &quot;touching&quot;, they should be part of a subarray together.</p> <p>For example: if I have the following sparse table/array:</p> <pre><code>[[0 0 0 1 1 0 0 ...
<python><pandas><numpy><scipy>
2024-10-21 16:28:00
1
45,611
Rick
79,110,884
5,218,153
Python Poetry - Pointing to envs.TOML Which is Invalid, Rather Than pyproject.TOML
<p>I've recently come back to a project which I'd left for a while. I am now attempting to add a new package via <code>poetry add xxx</code> but I receive an error -</p> <blockquote> <p>Invalid TOML file C:/Users/username/AppData/Local/pypoetry/Cache/virtualenvs/envs.toml: Unexpected character: ']' at line 5 col 1</p>...
<python><python-poetry>
2024-10-21 16:13:02
1
642
Jamsandwich
79,110,878
5,094,589
I want to match 6 or fewer digits in a string, if there are "/" or "-" between them
<p>It should match:</p> <ul> <li>&quot;abc 12-34 def&quot; precisely &quot;12-34&quot;</li> <li>&quot;Phone number: 123/45&quot;, precisely &quot;123/45&quot;</li> <li>&quot;sequence: 12//-34&quot;, precisely &quot;12//-34&quot;</li> <li>&quot;My code is 1-2-3-4&quot;, precisely &quot;1-2-3-4&quot;</li> </ul> <p>It sho...
<python><regex>
2024-10-21 16:10:24
1
1,106
Daniil Yefimov
79,110,798
865,169
Can I implement a custom insert method in a SQLAlchemy ORM-mapped class?
<p>I have an ORM-mapped class <code>Data</code> which includes a 'valid_until' (datetime) attribute I use for versioning of rows. This means that rows in the table can be duplicates with respect to some attributes, but the 'valid_until' attribute sets them apart, allowing me to identify which one is the most recent. Th...
<python><sqlalchemy>
2024-10-21 15:47:56
0
1,372
Thomas Arildsen
79,110,759
4,451,315
Replace all values in array according to mapping
<p>Say I have:</p> <pre class="lang-py prettyprint-override"><code>import pyarrow as pa arr = pa.array([1, 3, 2, 2, 1, 3]) </code></pre> <p>I'd like to replace values according to <code>{1: 'one', 2: 'two', 3: 'three'}</code> and to end up with:</p> <pre><code>&lt;pyarrow.lib.LargeStringArray object at 0x7f8dd0b3c820&...
<python><pyarrow>
2024-10-21 15:38:33
1
11,062
ignoring_gravity
79,110,748
7,123,033
How to incrementally train a Face Recognition Model without retraining from scratch?
<p>I'm building a face recognition model. I've already trained a model using the images of two people (Cristiano Ronaldo and Lionel Messi). Now, I want to add more people (e.g., Maria Sharapova) to the model without retraining everything from scratch.</p> <p>Is there a way to train a model a new model using the new dat...
<python><machine-learning><pytorch>
2024-10-21 15:34:20
0
321
Sammy
79,110,735
18,203,140
Filling outside a PolyLine in Leaflet
<p>I have a set of coordinates that gives a closed polygon. Using the <code>folium.PolyLine()</code> function in Python I can easily fill &quot;inside&quot; but not &quot;outside&quot;. The actual output is left, the desired one right in figure.</p> <p><a href="https://i.sstatic.net/LpM2NBdr.png" rel="nofollow noreferr...
<python><python-3.x><geopandas><folium>
2024-10-21 15:31:43
1
309
Stefø
79,110,663
11,233,365
Python: Package installed with meson cannot be found by pip
<p>I have been trying to solve an issue compiling a Python package for Windows, and part of that involves building <code>contourpy</code> in the UCRT64 environment on MSYS2. I have been able to successfully build the package in <code>virtualenv</code> using the following commands:</p> <pre class="lang-bash prettyprint-...
<python><pip><meson-build>
2024-10-21 15:08:44
1
301
TheEponymousProgrammer
79,110,285
3,224,483
Why doesn't dropdown appear when I attach DataValidation to the column?
<p>I want to create a spreadsheet that only allows two values in column A. Here is my attempt:</p> <pre><code>import openpyxl from openpyxl.worksheet.datavalidation import DataValidation book = openpyxl.Workbook() sheet = book.active for i in range(1, 11): sheet.cell(row=i, column=1).value = 'Acceptable' she...
<python><openpyxl>
2024-10-21 13:32:45
1
3,659
Rainbolt
79,110,150
5,775,358
enum as option in function, also add string option
<p>When defining a function, there are several ways to limit input to a set of predefined options. I thought it would make sense to use <code>Enum</code> objects to achieve this. For example:</p> <pre class="lang-py prettyprint-override"><code>from enum import Enum, auto class ColorOptions(Enum): RED = auto() ...
<python><function><enums>
2024-10-21 13:00:24
1
2,406
3dSpatialUser
79,109,962
1,821,692
asyncio server does not cancels request even if aiohttp.ClientSession exceeds its timeout
<p>The final goal is to cancel request on server side if client exceeds its timeout.</p> <p>The code related to start the server:</p> <pre class="lang-py prettyprint-override"><code>def run_server_loop( routes: web.RouteTableDef, shutdown_state: ShutdownState, logger: Logger, *, port: int, perio...
<python><asynchronous><python-asyncio><aiohttp>
2024-10-21 12:04:10
1
3,047
feeeper
79,109,569
4,738,644
How to do composite from PIL using only OpenCV?
<p>Hello I want to combine a green image mask (3 channels with a squared figure only with the green channel as 255) with a 3 channels image using opencv in python. I cannot use PIL.Image.composite since I don't have privileges to install it (not administrator).</p> <p>OpenCV has a function called addweighted, which doe...
<python><opencv><image-processing><transparency><mask>
2024-10-21 10:12:33
0
421
Diego Alejandro Gómez Pardo