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,166,062
495,769
Is python's CFFI an adequate tool to parse C definitions from a header file
<p>From python, I want to fetch the details of structures/arrays/enums defined in C headers: the list of defined types, the list and types of struct members, the names and values defined in enums, the size of arrays, etc.</p> <p>I don't plan to link a C lib in python, but I wanted to use a battle-tested tool to &quot;p...
<python><c><python-cffi>
2024-11-07 10:42:30
1
2,260
yota
79,166,016
14,720,380
error: cannot repair to "manylinux_2_28_x86_64" ABI because of the presence of too-recent versioned symbols
<p>I am trying to build my python package inside a manylinux_2_28 container but I am getting the error:</p> <pre><code>error: cannot repair &quot;pynemo-0.0.0.dev0-cp311-cp311-linux_x86_64.whl&quot; to &quot;manylinux_2_28_x86_64&quot; ABI because of the presence of too-recent versioned symbols. </code></pre> <p>Using...
<python><linux><python-manylinux>
2024-11-07 10:26:47
0
6,623
Tom McLean
79,165,925
3,906,713
How to interpolate pandas time series using different timestamps
<p>I am looking for a function</p> <pre><code>pandas_interpolate(df: pd.DataFrame, newTime: pd.DatetimeIndex, method: str = 'linear') -&gt; pd.DataFrame </code></pre> <p>that would take an existing dataframe with a <code>DatetimeIndex</code> index, and return a new dataframe with index given by <code>newTime</code>. Fo...
<python><pandas><dataframe><numpy><interpolation>
2024-11-07 10:09:55
1
908
Aleksejs Fomins
79,165,811
19,356,117
Named symbol not found when use cupy to invoke cuda kernel
<p>This is my cuda kernel: <a href="https://pastebin.com/ti95Qy2p" rel="nofollow noreferrer">https://pastebin.com/ti95Qy2p</a>, and I want to invoke <code>compute_linear_recurrence</code> method in this kernel. But when I use code:</p> <pre><code>import cupy as cp # code_str is code in https://pastebin.com/ti95Qy2p cal...
<python><python-3.x><cuda><cupy>
2024-11-07 09:39:01
1
1,115
forestbat
79,165,506
1,826,066
Expand list of struct column in `polars`
<p>I have a <code>pl.DataFrame</code> with a column that is a <code>list</code> of <code>struct</code> entries. The lengths of the lists might differ:</p> <pre class="lang-py prettyprint-override"><code>pl.DataFrame( { &quot;id&quot;: [1, 2, 3], &quot;s&quot;: [ [ {&quot;...
<python><dataframe><python-polars>
2024-11-07 08:06:02
1
1,351
Thomas
79,165,357
1,537,366
update on pandas join/merge performance in python
<p>(I post this self-answered question to share my own tests.) There are a huge number of ways to join two DataFrames together in Python/Pandas. Previous performance analyses indicated that <code>DataFrame.join</code> is faster than <code>DataFrame.merge</code> and that it is best that one table has an index on the col...
<python><pandas><dataframe><join><left-join>
2024-11-07 07:08:16
1
1,217
user1537366
79,165,299
219,153
Why grid is not shown in this matplotlib script?
<p>Using Python 3.12 and Matplotlib 3.8.4 on Ubuntu 22.04. I would like to see a uniform grid with 0.25 spacing. This snippet:</p> <pre><code>import matplotlib.pyplot as plt from matplotlib.ticker import MultipleLocator gridSpacing = MultipleLocator(0.25) plt.clf() plt.gca().set_aspect('equal') plt.gca().xaxis.set_min...
<python><matplotlib><grid>
2024-11-07 06:48:17
0
8,585
Paul Jurczak
79,165,267
16,525,263
How to explode arraytype columns in pyspark dataframe
<p>I have a pyspark dataframe as below.</p> <p>I need to explode the <code>Items</code> and <code>Value1</code> columns. This is my code at present:</p> <pre class="lang-py prettyprint-override"><code>df_ob_exploded = df.withColumn('op_it.objects', F.explode(F.array(*[F.array(F.col('op_it.objects')[...
<python><apache-spark><pyspark>
2024-11-07 06:38:21
2
434
user175025
79,165,110
19,356,117
CompileException occurs when compile .cu file with cupy
<p>I have a .cu file with these heads:</p> <pre><code>#include &lt;/usr/include/features.h&gt; #include &lt;/usr/include/assert.h&gt; #include &lt;/usr/include/stdio.h&gt; </code></pre> <p>When I use <code>nvcc</code> command to compile this file, it passed, but when I use <code>cupy.RawKernel()</code> to execute code ...
<python><c++><python-3.x><cuda><cupy>
2024-11-07 05:24:23
1
1,115
forestbat
79,164,899
4,971,515
In PyQT 5, always show a QCombobox using QStyledItemDelegate in QTableView (Not just when a cell is being edited)
<p>I'm subclassing <code>QStyledItemDelegate</code> to show a dropdown <code>QCombobox</code> in a <code>QTableView</code>. The delegate detects the dataType from the table's model, and if the <code>dataType == EnumMeta</code>, shows a dropdown list of options.</p> <p>With my current implementation, the dropdown is onl...
<python><pyqt><pyqt5>
2024-11-07 03:04:05
0
326
Jesse Reilly
79,164,771
901,827
Extract multiple sparsely packed responses to yes/no identifiers while preserving row information
<p>I have some data from Google Sheets that has a multi-response question, like so:</p> <pre><code> Q1 Q2 ... Multi-Response 0 ... ... ... &quot;A; B&quot; 1 ... ... ... &quot;B; C&quot; 2 ... ... ... &quot;D; F&quot; 3 ... ... ... &quot;A; B; F&quot; </code></pre> <p>(Note the whitespace, the separator is <co...
<python><pandas><google-sheets>
2024-11-07 01:36:15
2
22,476
Linear
79,164,770
9,251,158
How to run doc-tests without printing output
<p>I want to run doc-tests and get the number of failures, but not print any output. For example, I tried this:</p> <pre class="lang-py prettyprint-override"><code> with open(os.devnull, 'w') as sys.stdout: tests_failed, tests_run = doctest.testmod(some_module, ...
<python><stdout><doctest>
2024-11-07 01:36:06
1
4,642
ginjaemocoes
79,164,756
8,800,836
Remove specific indices in each row of a numpy ndarray
<p>I have integer arrays of the type:</p> <pre class="lang-py prettyprint-override"><code>import numpy as np seed_idx = np.asarray([[0, 1], [1, 2], [2, 3], [3, 4]], dtype=np.int_) target_idx = np.asarray([[2,9,4,1,8], [9,7,6...
<python><numpy><numpy-ndarray><numpy-slicing>
2024-11-07 01:27:03
2
539
Ben
79,164,737
22,407,544
How to make a Django `url` case insensitive?
<p>For example, if I visit <code>http://localhost:8000/detail/PayPal</code> I get a Page not found error 404 with the following message:</p> <pre><code>Using the URLconf ... Django tried these URL patterns, in this order: ... detail/&lt;slug:slug&gt; [name='processor_detail'] The current path, detail/PayPal, matched t...
<python><django><django-urls>
2024-11-07 01:09:03
4
359
tthheemmaannii
79,164,713
4,755,229
How to check if packages are as in "micromamba list" after pip broke it?
<p>I tried to install a package (<code>hyperfit</code>) which is only availabe via PyPI. Given that I have my whole environment set up with <code>micromamba</code>, I installed all the dependency, and tried to install the package. Well, the thing is, <code>pip</code> broke my environment, silently, without asking me. S...
<python><pip><mamba><micromamba>
2024-11-07 00:48:53
1
498
Hojin Cho
79,164,666
1,991,502
Mypy type complaint not tracking if-branch logic. How should I fix?
<p>I have the following code:</p> <pre><code>array: list[list[str | None]] = [] # ... item_text: str = &quot;&quot; if array[0][col] is not None: item_text = array[0][col] </code></pre> <p>In VSCode, mypy throws the following complaint</p> <pre><code>Incompatible types in assignment (expression has type &quot;str |...
<python><python-typing><mypy>
2024-11-07 00:12:08
0
749
DJames
79,164,381
2,528,063
HTTP 404 on flask server when just returning provided parameter
<p>I have a simple flask-app like this:</p> <pre><code>from flask import Flask app = Flask(__name__) @app.route(&quot;/getExposeIds/&lt;cookie&gt;&quot;) def getExposeIds(cookie): return cookie </code></pre> <p>I'm running the app as follows:</p> <pre><code>flask --app myscript run </code></pre> <p>When I ca...
<python><flask>
2024-11-06 21:38:02
1
37,422
MakePeaceGreatAgain
79,164,358
219,153
Python f-string equivalent of iterable unpacking by print instruction
<p><code>print</code> can nicely unpack a tuple removing brackets and commas, e.g.</p> <pre><code>a = (0, -1, 1) print(*a) </code></pre> <p>produces <code>0 -1 1</code>. Trying the same with f-strings fails:</p> <pre><code>print(f'{*a}') </code></pre> <p>The closest f-string option I found is:</p> <pre><code>print(f'{*...
<python><f-string><iterable-unpacking>
2024-11-06 21:29:09
3
8,585
Paul Jurczak
79,164,305
2,925,767
how to turn cli based argument function into function that takes parameters python
<p>I'm using an example function from the google-api-python-client library that takes command line arguments and parses them using <code>argparser</code>. Here's the code this is based on (converted to python3) <a href="https://developers.google.com/youtube/v3/guides/uploading_a_video" rel="nofollow noreferrer">https:/...
<python><parameters><arguments><command-line-interface>
2024-11-06 21:06:35
1
1,085
icicleking
79,164,165
6,447,123
FSDP in Accelerate for Large-Context LLaMA Training
<p>I'm trying to train a LLaMA model with large contexts using Hugging Face's Trainer, Fully Sharded Data Parallel (FSDP), and the accelerate library to handle memory limits. My context size is very large, with max token sizes over 70k. While my setup works fine for smaller context sizes, I'm hitting a roadblock with l...
<python><pytorch><huggingface-transformers><llama><accelerate>
2024-11-06 20:26:37
0
4,309
A.A
79,164,083
2,015,614
Type importing in dynamically loaded modules
<p>I want to dynamically load a module from within a package and to import objects from the package into this module. However, I am getting an inconsistency in the name spaces what the types is concerned.</p> <p>My package files are in directory <code>pkg</code>:</p> <pre><code>pkg: __init__.py, main.py, commands.py, q...
<python><python-import>
2024-11-06 19:56:19
2
1,205
Dmitry K.
79,163,896
1,803,648
How to detect task cancellation by Task Group
<p>Given a <code>taskgroup</code> and number of running tasks, per <a href="https://docs.python.org/3/library/asyncio-task.html#terminating-a-task-group" rel="nofollow noreferrer">taskgroup docs</a> if any of the tasks raises an error, rest of the tasks in group will be cancelled.</p> <p>If some of these tasks need to ...
<python><task><python-asyncio>
2024-11-06 18:48:31
1
598
laur
79,163,792
2,879,529
Iterate through large XML data while multiprocessing using Python
<p>I have to periodically check a big XML file with millions of records.</p> <pre><code>context = iter(etree.iterparse(product_file_path, tag=&quot;Record&quot;, events=(&quot;start&quot;, &quot;end&quot;))) _, root = next(context) start_tag = None xml_dict = None for event, elem in context: if event == &qu...
<python><memory><lxml><python-multithreading>
2024-11-06 18:13:26
0
373
Mærcos
79,163,625
22,407,544
Django `The current path, detail/PayPal, matched the last one` error
<p>I'm using Django's <code>DetailView</code> to display detailed information in my web app. I've set up a <code>Processor</code> model with a <code>name</code> and a <code>slug</code> field, and I'm using the <code>slug</code> field in the URL pattern and the DetailView. However, I'm running into an issue where the De...
<python><django>
2024-11-06 17:19:19
1
359
tthheemmaannii
79,163,581
23,626,926
algorithm for undoing Bresenham lines
<p>I have a blob of points on a grid that I want to create a sensible polygon outline for. The points will be selected by the user so I can't expect them to be <em>perfectly</em> following Bresenham's algorithm for lines with weird slopes. However, I am still struggling to even get something working for an obvious &quo...
<python><graphics><vectorization>
2024-11-06 17:06:37
0
360
dragoncoder047
79,163,487
9,591,312
How to generate a sample with a given spearman coefficient
<p>In order to create a dataset to test a statistical calculation package, I want to be able to generate a sample that is correlated to a reference sample with a given searman coefficient.</p> <p>I managed to do it for the Pearson coefficient, but the fact that Spearman works on the rank makes it quite tricky, to say t...
<python><statistics><correlation><sampling><pearson-correlation>
2024-11-06 16:40:30
2
647
BayesianMonk
79,163,417
2,067,492
How can I get a keras layer to learn an AND operation
<p>To get keras to learn to detect corners from a binary image of a rectangle I reduced the problem down to classifying a 3x3 array of pixels. The top left corner, the pixels would need to look like this.</p> <pre><code>[ [0, 0, 0], [0, 1, 1], [0, 1, 1] ] </code></pre> <p>This generates the full set of all the pos...
<python><keras>
2024-11-06 16:18:39
1
12,395
matt
79,163,372
967,621
Python equivalent of the Perl ".." flip-flop operator
<p>What is the Python equivalent of the Perl &quot;<code>..</code>&quot; (range, or flip-flop) <a href="https://perldoc.perl.org/perlop#Range-Operators" rel="nofollow noreferrer">operator</a>?</p> <pre class="lang-perl prettyprint-override"><code>for ( qw( foo bar barbar baz bazbaz bletch ) ) { print &quot;$_\n&qu...
<python><regex><range><slice>
2024-11-06 16:06:36
3
12,712
Timur Shtatland
79,163,215
1,283,836
Why PrintOptions.page_height of Selenium is ignored by some websites?
<p>Selenium has <code>print_page</code> <a href="https://www.selenium.dev/documentation/webdriver/interactions/print_page/" rel="nofollow noreferrer">method</a> that can return base64 encoded PDF representation of whatever is loaded by Selenium. That method, accepts <code>PrintOptions</code> object which as the name su...
<python><selenium-webdriver><roundcube>
2024-11-06 15:17:41
1
2,093
wiki
79,163,025
2,359,027
Sort QTreeWidget alphabetically, except one item
<p>I have a QTreeWidget with items. One of the items I use it to provide a &quot;Select All&quot; option.</p> <p>I would like to keep that &quot;Select All&quot; item pinned on top, and then sort all other items below alphabetically. I tried creating a ROLE for the &quot;Select All&quot; item to indicate that this one ...
<python><qt><sorting><pyside6><qtreewidget>
2024-11-06 14:24:13
2
1,133
laurapons
79,163,001
626,804
SQLAlchemy: is it safe to add a new column to a view, not mentioned in the model?
<p>Suppose I have a view, for example</p> <pre><code>create view MyView as select 1 as A, 2 as B </code></pre> <p>(The above SQL is Microsoft dialect but the details of the view itself are not important.)</p> <p>I wrap this view in my SQLAlchemy model definition:</p> <pre><code>class MyView(Base): __tablename__ = '...
<python><view><sqlalchemy>
2024-11-06 14:17:47
1
1,602
Ed Avis
79,162,993
12,466,687
How to select column range based on partial column names in Pandas?
<p>I have pandas dataframe and I am trying to <strong>select multiple columns</strong> (<strong>column range</strong> starting from <code>Test</code> to <code>Bio Ref</code>). Selection has to <strong>start</strong> from column <code>Test</code> to any column whose name starts with <code>Bio</code>. Below is the sample...
<python><pandas><dataframe>
2024-11-06 14:16:00
2
2,357
ViSa
79,162,974
774,575
How to align 2D artists with 3D points (what is the correct coordinate transform)?
<p>In this figure:</p> <p><a href="https://i.sstatic.net/65vnI3wBm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/65vnI3wBm.png" alt="image" /></a></p> <p>Red circles are 3D points plotted with <code>Axes3D.scatter()</code>. They have a 3D position. Numbers in their bbox are plotted with <code>Axes3D.ad...
<python><matplotlib><3d><transform>
2024-11-06 14:12:49
0
7,768
mins
79,162,915
534,298
How to write a function for numpy array input whose action depends on the input's numerical value
<p>The function has this mathematical form</p> <pre><code>f(x) = 1, if x&lt;1 = g(x), for 1&lt;=x&lt;10 = 0, for x &gt;=10 </code></pre> <p>where <code>g(x)</code> is a simple function.</p> <p>It is straightforward to write such a function if the input is a <code>float</code> using <code>if/else</code>. If th...
<python><numpy><numpy-ndarray>
2024-11-06 13:58:03
2
21,060
nos
79,162,743
4,529,546
scikit-learn classifiers and regressors caching training data?
<p>I have some 22,000 rows of training data. I use train_test_split to get training and testing data. I run fitting and then get some idea of how well fitting went using various methods or estimation.</p> <p>I want to have the fitted model go back over the 22,000 rows and predict against them as if it had never seen th...
<python><scikit-learn><model-fitting>
2024-11-06 13:12:45
1
1,128
Richard
79,162,721
753,376
winotify notification keeps on showing on callback
<p>I'm trying to show windows notification using winotify. My problem is it keeps on showing when I click the button that has a callback to open a web browser. Also is there a way to not show the command prompt when clicking the button?</p> <pre><code>from winotify import Notification, audio, Notifier, Registry import ...
<python>
2024-11-06 13:05:05
0
2,852
unice
79,162,666
11,863,823
How to type Polars' Altair plots in Python?
<p>I use <code>polars</code> dataframes (new to this module) and I'm using some static typing, to keep my code tidy and clean for debugging purposes, and to allow auto-completion of methods and attributes on my editor. Everything goes well.</p> <p>However, when plotting things from dataframes with the <code>altair</cod...
<python><python-typing><python-polars><altair>
2024-11-06 12:52:20
1
628
globglogabgalab
79,162,665
4,197,386
Restoring flax model checkpoints using orbax throws ValueError
<p>The following code blocks are being utlized to save the train state of the model during training and to restore the state back into memory.</p> <pre><code> from flax.training import orbax_utils import orbax.checkpoint directory_gen_path = &quot;checkpoints_loc&quot; orbax_checkpointer_gen = orbax.checkpoint.PyTreeC...
<python><jax><flax>
2024-11-06 12:52:03
1
380
yash
79,162,500
11,751,799
Gaps in a `matplotlib` plot of categorical data
<p>When I have numerical data, say index by some kind of time, it is straightforward to plot gaps in the data. For instance, if I have values at times 1, 2, 3, 5, 6, 7, I can set an <code>np.nan</code> at time 4 to break up the plot.</p> <pre class="lang-py prettyprint-override"><code>import numpy as np import matplotl...
<python><numpy><matplotlib><plot>
2024-11-06 12:00:39
2
500
Dave
79,162,394
520,556
Neither `xarray.ufuncs.exp()` nor `xr.apply_ufunc.exp()` work: `AttributeError: 'function' object has no attribute 'exp'`
<p>I am trying to make some old code run, but running in circles with exponentiation an array. Neither <code>xarray.ufuncs.exp()</code> nor <code>xr.apply_ufunc.exp()</code> work.</p> <p>Some suggested there is a bug in dask, which should be solved by <code>pip install dask==2.4.0</code>, but that did not help either.<...
<python><python-xarray>
2024-11-06 11:29:09
0
1,598
striatum
79,162,377
1,440,764
AWS Sagemaker ClientError: train channel is not specified (Manifest file error)
<p>As a test, I'm running a train_manifest and a validation_manifest that are identical and contain only one file...</p> <pre><code>{&quot;source-ref&quot;: &quot;s3://&lt;bucketname&gt;/bad_ofs/Images_final/Crushing/iO/A_2208040CA2_1430_220804-205516.jpg&quot;, &quot;bounding-box&quot;: {&quot;annotations&quot;: [{&qu...
<python><machine-learning><artificial-intelligence><amazon-sagemaker>
2024-11-06 11:22:30
0
2,512
RightmireM
79,162,319
11,561,121
How to correctly use and parse an XCom list of dicts in Airflow
<p>I am writing an Airflow dag which generates a dict list based on run parameters that I pass in json format using UI and then parses and uses its elements inside a <code>KubernetesPodOperator</code>. In the below code I simplified my use case to simple <code>echo</code>.</p> <p><strong>This is my code</strong></p> <p...
<python><airflow>
2024-11-06 11:03:15
0
1,019
Haha
79,162,282
2,473,382
Access destination property from a Glue S3 DataSink
<p>With Glue 4.0, so Python 3.10.</p> <p>Assuming I am creating a datasink this way:</p> <pre class="lang-py prettyprint-override"><code>sink = gluecontext.getSink(path=&quot;s3://bucket/key&quot;, connection_type=&quot;s3&quot;) </code></pre> <p>How can I access the path property (or equivalent if it is split in <code...
<python><amazon-s3><aws-glue>
2024-11-06 10:53:20
0
3,081
Guillaume
79,162,280
978,781
Python 3.13 generic classes with type parameters and inheritance
<p>I'm exploring types in Python 3.13 and can't get the generic typing hints as strict as I would like.</p> <p>The code below defines a generic Predicate class, two concrete subclasses, and a generic negation predicate.</p> <pre class="lang-py prettyprint-override"><code>class Predicate[T](Callable[[T], bool]): &qu...
<python><generics><python-typing><python-3.12>
2024-11-06 10:53:00
1
12,605
Arie
79,162,161
14,550,855
How to get a summary of a PyTorch model that uses dictionary as an input
<p>My model takes a dictionary as input, e.g. x = {'image': torch.tensor, 'number': torch.tensor}, the model looks like this:</p> <pre><code>class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() self.imgmodule = ImgModule() self.nummodule = NumModule() self.pr...
<python><machine-learning><deep-learning><pytorch>
2024-11-06 10:22:03
0
401
arr10
79,162,109
5,816,253
Geopandas fails reading geojson
<p>I'm trying to read a geojson I created using these steps</p> <pre class="lang-py prettyprint-override"><code>import geopandas as gpd vec_data = gpd.read_file(&quot;map.shp&quot;) vec_data.head() vec_data['LPIS_name'].unique() sel_crop = vec_data[vec_data.LPIS_name == 'Permanent Grassland'] sel_crop.to_file(&quot;P...
<python><geopandas><shapefile>
2024-11-06 10:03:26
1
375
sylar_80
79,162,094
3,909,896
Using Databricks asset bundles with typer instead of argparse
<p>I want to use Databricks asset bundles - I'd like to use <code>typer</code> as a CLI tool, but I have only been able to set it up with <code>argparse</code>. Argparse seems to be able to retrieve the arguments from the databricks task, but not typer.</p> <p>I specified two entrypoints in my pyproject.toml</p> <pre><...
<python><databricks><typer><databricks-asset-bundle>
2024-11-06 09:57:39
0
3,013
Cribber
79,162,038
4,451,315
Iterate over groups of PyArrow table
<p>In pandas I can iterate over groups in <code>groupby</code>:</p> <pre class="lang-py prettyprint-override"><code>In [3]: import pandas as pd In [4]: data = {'a': [1, 1, 1, 2, 2], 'b': [2, 4, 3, 5, 6]} In [5]: df = pd.DataFrame(data) In [6]: for _, sub_df in df.groupby('a'): ...: print(sub_df) ...: a ...
<python><pyarrow>
2024-11-06 09:41:18
1
11,062
ignoring_gravity
79,161,932
3,668,129
Can't iterate over dataset (AttributeError: module 'numpy' has no attribute 'complex'.)
<p>I'm using:</p> <pre><code>windows python version 3.10.0 datasets==2.21.0 numpy==1.24.4 </code></pre> <p>I tried to iterate over dataset I just downloaded:</p> <pre><code>from datasets import load_dataset dataset = load_dataset(&quot;jacktol/atc-dataset&quot;, download_mode='force_redownload') dataset['train'][0] <...
<python><numpy><dataset><huggingface-datasets>
2024-11-06 09:07:20
1
4,880
user3668129
79,161,931
2,219,080
In pytest set up databases mirroring and test
<p>I have a Django app that reads a read_only replica from a model in the DB. So in the <code>pytest</code> conftest fixtures, I have this <code>settings.DATABASES[&quot;read_only&quot;][&quot;TEST&quot;] = {&quot;MIRROR&quot;: &quot;default&quot;}</code> but when I instantiate fixtures, the <code>read_only</code> data...
<python><django><pytest-django><factory-boy>
2024-11-06 09:07:13
0
1,267
iMitwe
79,161,843
4,036,004
How to go about linking external data to every word in a paragraph and access the external data even when the words are moved around?
<p>Apologies there is no code yet as I'm not sure where to begin. I'm using python.</p> <p>I am using <a href="https://github.com/linto-ai/whisper-timestamped" rel="nofollow noreferrer">whisper-timestamped</a> to transcribe an audio file and create a json file that contains the timecode (start &amp; end) of every word ...
<python><interactive><transcription>
2024-11-06 08:38:46
0
1,309
JulianJ
79,161,804
10,200,497
What is the best way to filter the groups that have at least N rows that meets the conditions of a mask?
<p>This is my DataFrame:</p> <pre><code>import pandas as pd df = pd.DataFrame({ 'a': [10, 20, 30, 50, 50, 50, 4, 100], 'b': [30, 3, 200, 25, 24, 31, 29, 2], 'd': list('aaabbbcc') }) </code></pre> <p>Expected output:</p> <pre><code> a b d 0 10 30 a 1 20 3 a 2 30 200 a </code></pre> <p>The ...
<python><pandas><dataframe>
2024-11-06 08:20:38
3
2,679
AmirX
79,161,751
16,815,358
Problems with updating colorbar with matplotlib.Slider listener in Jupyter
<p>The problem that I am having is during updating the colorbar of an <code>plt.imshow</code> plot. Here's the code I will try to break it down and to explain some stuff in it afterwards.</p> <ul> <li>For the first cell in Jupyter, I have the functions, the imports and the input parameters:</li> </ul> <pre><code># Impo...
<python><matplotlib><widget><colorbar>
2024-11-06 07:57:30
1
2,784
Tino D
79,161,739
1,184,652
Show product name in template django
<p>I want to show all of the user orders in its panel so, I have following models: this is my product model in django and in my order model I have productfk field that is id of user product.</p> <pre><code>class Product(models.Model): id= models.IntegerField(primary_key=True) activedate = models.DateField() ...
<python><django><django-views><django-templates>
2024-11-06 07:52:55
1
644
franchesco totti
79,161,450
10,855,529
Conditional join_where using string starts_with predicate in Polars
<p>I have two DataFrames,</p> <pre class="lang-py prettyprint-override"><code>import polars as pl df = pl.DataFrame({ &quot;url&quot;: [&quot;https//abc.com&quot;, &quot;https//abcd.com&quot;, &quot;https//abcd.com/aaa&quot;, &quot;https//abc.com/abcd&quot;] }) conditions_df = pl.DataFrame({ &quot;url&quot;: ...
<python><dataframe><python-polars>
2024-11-06 05:47:43
2
3,833
apostofes
79,161,325
558,639
asyncio.run() vs asyncio.get_event_loop().run_until_complete()
<p>I need to call an async function from within a synchronous function.</p> <p>Can someone educate me on the following: What are the salient differences between <code>sync_fn_a</code> and <code>sync_fn_b</code>, and when would I choose one over the other?</p> <pre class="lang-py prettyprint-override"><code>async def my...
<python><python-asyncio>
2024-11-06 04:23:19
2
35,607
fearless_fool
79,161,167
2,870,357
Unsuccesfully adding font in pyside6
<p>I try to add font <a href="https://freefontsfamily.org/gotham-narrow-font-free-download/" rel="nofollow noreferrer">Gotham Narrow</a> into my pyqt apps. Below is my simple script.</p> <pre><code>app = QApplication(sys.argv) fontpath = &quot;GothamNarrow-Bold.otf&quot; _id = QFontDatabase.addApplicationFont(fontpath)...
<python><pyside6>
2024-11-06 01:57:35
0
451
slawalata
79,161,150
58,347
How to publish an update to pip *just* for older Python versions?
<p>I have a library published on pip which previously had a minimum Python version of 3.7, and now has a minimum Python version of 3.9.</p> <p>This means that, when a user with Python 3.7 or 3.8 does <code>pip install my-package</code>, they silently get the last version that was published with 3.7 support, rather than...
<python><python-packaging>
2024-11-06 01:45:09
1
18,453
Tab Atkins-Bittner
79,161,133
170,005
Getting a strange error while importing pycaret in Airflow
<p>Getting this strange error while importing pycaret in a Airflow Kubernetes pod. This was working fine since deployment and there have been no changes in environment. Anyone know what this is about ? Error occurs when running this line:</p> <p><code>from pycaret.classification import predict_model, load_model</code><...
<python><airflow><python-3.8><pycaret>
2024-11-06 01:31:53
0
16,244
fixxxer
79,161,068
19,429,024
How to listen for hotkeys in a separate thread using Python with Win32 API and PySide6?
<p>I’m setting up a hotkey system for Windows in Python, using the Win32 API and PySide6. I want to register hotkeys in a HotkeyManager class and listen for them in a separate thread, so the GUI remains responsive. However, when I move the listening logic to a thread, the hotkey events are not detected correctly.</p> <...
<python><python-multithreading><pywin32><pywinauto>
2024-11-06 00:36:44
1
587
Collaxd
79,161,015
13,350,341
What would be the best option to render typing_extension.Self output type-hint as the class name via mkdocstrings?
<p>I'm looking for advice on how to best render <code>typing_extensions.Self</code> output type-hints, while keeping <code>show_signature_annotations: true</code> option enabled.</p> <p><code>mkdocstrings</code> config follows:</p> <pre><code>plugins: - mkdocstrings: handlers: python: import: ...
<python><python-typing><mkdocs-material><mkdocstrings>
2024-11-05 23:55:49
0
3,157
amiola
79,160,988
417,896
Plotly graph loading in PySide6
<p>I am trying to render a plotly html file in pyside6, but I am getting a blank component where the plotly graph should be. If I try to load the generated file in a web browser it works.</p> <pre><code>import os import sys import signal from PySide6.QtWidgets import QApplication, QMainWindow, QTabWidget, QWidget, QVB...
<python><plotly><pyside6>
2024-11-05 23:33:24
0
17,480
BAR
79,160,962
6,457,407
Creating __await__() from another awaitable object
<p>I was experimenting with creating my own awaitable object. I understand that the precise details of what <code>__await__</code> returns are async-library dependent, but I was hoping I could just copy the values from another asynchronous function.</p> <pre><code>import asyncio class MyObject: async def ten(self...
<python><async-await>
2024-11-05 23:14:33
1
11,605
Frank Yellin
79,160,940
11,505,680
pandas bar chart with paired columns
<p>I have a <code>DataFrame</code> with paired columns. I want to plot it such that each <em>pair</em> of columns has a unique color, and one column of each pair has an empty fill.</p> <p>I tried this:</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd df = pd.DataFrame({ ('A', '1'): [1, 2, 3]...
<python><pandas><matplotlib><plot>
2024-11-05 23:04:17
1
645
Ilya
79,160,935
2,603,579
Python urldecode urlencoded bytecode data
<p>Payload contains an HMAC tag as well as a nonce for AES. Client-side printing the tag and nonce result in (for example):</p> <pre><code>#tag: b'=x\x9d{_0\xf9;c8\x94inc]\xb1' #nonce: b'\x1f\xf4\xbe\xcc\xf2\x84f\xf2*\x8dP\x16\xc8\x02\xfe\xbe' requests.post(url, data=payload, headers={&quot;Content-Type&quot;: &quot...
<python><python-requests><urlencode>
2024-11-05 23:03:05
2
402
Ryan Farber
79,160,913
6,635,590
Python using requests get html data after page has been altered by JS
<p>I've tried searching for something like this online but haven't actually found any solutions for my problem.</p> <p>I'm trying to make a website to be a price tracker for the products they sell, since I've just started making this website I need to input all the products into my database for them to be tracked in th...
<javascript><python><beautifulsoup><python-requests>
2024-11-05 22:51:43
0
734
tygzy
79,160,811
2,036,464
Python: Compare html tags in RO folder with their corresponding tags in EN folder and displays in Output the unique tags from both files
<p>In short, I have two files, one in Romanian, the other has been translated into English. In the RO file there are some tags that have not been translated into EN. So I want to display in an html output all the tags in EN that have corresponding tags in RO, but also those tags in RO that do not appear in EN.</p> <p><...
<python><python-3.x><openai-api><claude>
2024-11-05 22:01:59
2
1,065
Just Me
79,160,774
11,281,707
How to disable the caret (^) characters in the Python stacktrace?
<p>I have a script for doing test readouts that worked fine with Python 3.9 but now we upgraded to Python 3.12 we have those carets that break the script. So the easiest way would be disabling it.</p> <p>Is there a way to disable the carets (^^^^^^^^^^^^^^^^^^^^) in the Python stacktrace?</p> <pre><code>ERROR: test_ema...
<python><traceback>
2024-11-05 21:43:41
4
1,015
claudius
79,160,696
10,193,760
Converting python logic to sql query (Pairing two status from one column)
<p>I need help with converting my python code to SQL:</p> <pre><code>req_id_mem = &quot;&quot; req_workflow_mem = &quot;&quot; collect_state_main = [] collect_state_temp = [] for req_id, req_datetime, req_workflow in zip(df[&quot;TICKET_ID&quot;], df[&quot;DATETIMESTANDARD&quot;], df[&quot;STATUS&quot;]): if req_...
<python><sql><pandas><snowflake-cloud-data-platform>
2024-11-05 21:10:47
2
1,610
Maku
79,160,614
34,747
How to deploy Django app in docker with UV
<p>I am writing a Dockerfile Configuration for a Django app. I am usin uv to manage my dependencies in a virtualenv. The app runs normally outside the container, but when I try to run it from the container, it can't find the django package:</p> <pre class="lang-py prettyprint-override"><code>from django.core.wsgi impor...
<python><django><docker><docker-compose><uv>
2024-11-05 20:42:10
1
6,262
fccoelho
79,160,324
922,128
How to change a Todoist task's duration with the update_task Python and REST API?
<p>I've tried Todoist APIs' update_task and I get error code 400:</p> <blockquote> <p>&quot;Client Error: bad request for url <a href="https://api.todoist.com/rest/v2/tasks/%5B...%5D%22" rel="nofollow noreferrer">https://api.todoist.com/rest/v2/tasks/[...]&quot;</a> with</p> </blockquote> <pre><code># Define the task I...
<python><rest><todoist>
2024-11-05 18:35:13
1
476
TudorT
79,160,196
1,275,942
Maximally broad PEP-508 dependency specifier
<p>I have the following <code>pyproject.toml</code>:</p> <pre class="lang-ini prettyprint-override"><code>dependencies = [ &quot;first-example==*&quot;, &quot;second-example&quot;, ] </code></pre> <p>The first dependency gives:</p> <pre><code>configuration error: `project.dependencies[0]` must be pep508 </code>...
<python><pyproject.toml>
2024-11-05 17:49:16
0
899
Kaia
79,160,162
243,031
Milvus database is not able to load collection
<p>I am running milvusdb in docker, and it has 18K+ records in that database. VM's storage was full, I stopped docker and did <code>system prune</code> to remove unused resources. I remove temp log files.</p> <p>Docker setup is as below.</p> <pre><code>Skn@Skn:~/milvusDB$ sudo docker-compose ps Name ...
<python><vector-database><milvus>
2024-11-05 17:40:08
2
21,411
NPatel
79,160,097
16,773,063
How can I redact or remove entire line from pdf using either pymuPDF or other python libraries
<p>I am currently working on formatting PDFs using pyMuPDF library in python. I have several tasks that involves formatting the PDF file as follows:</p> <ol> <li>I need to remove empty lines so that the PDF file does not look dis-oriented. Now, I have tried the following code:</li> </ol> <pre><code>def remove_extra_lin...
<python><pymupdf>
2024-11-05 17:17:47
0
565
MURTUZA BORIWALA
79,160,084
1,442,731
setting default values in Python Protobuf fields
<p>I am writing some python test routines with protobuf acting as the communication medium with a firmware module. I keep tripping over an issue. I receive a response from a module expecting a value in a protobuf field and it's empty. I know that protobuf skips over fields that have the default value in the message,...
<python><protocol-buffers>
2024-11-05 17:15:18
0
6,227
wdtj
79,159,768
2,171,348
performance using python3/pandas to read .ods (opendocument spreadsheet)file
<p>Environment:</p> <pre> inside docker container in WSL2/Ubuntu22.04 python 3.12 pandas 2.2.2 odfpy 1.4.1 openpyxl 3.1.3 </pre> <p>The .ods file I have on disk is 6.8MB (two sheets, one sheet has 16,000 rows, the other has 74,000 rows). I can open this file in MS excel in no time.</p> <p>I have the follo...
<python><pandas><performance><odf>
2024-11-05 15:34:10
0
481
H.Sheng
79,159,747
4,119,291
Is there a way to render gt tables as PNGs with (a) no browser and (b) without wkhtmltopdf/wkhtmltoimage? (R/Python)
<p>I have a really pretty gt table that we'd like to automate production of. Running this on our remote server has some limitations: enterprise policy is that no browsers, headless or otherwise, may be installed on the server; the admin has been unwilling to install wkhtmltopdf.</p> <p>So I can either run this locally,...
<python><r><wkhtmltopdf><gt><wkhtmltoimage>
2024-11-05 15:29:35
1
331
Rich Ard
79,159,314
2,726,900
Can i tell devpi to cache a list of packages?
<p>I want to use <code>devpi</code> as an extra package cache because our main JFrog Artifactory sometimes goes down and I my airflow with PythonVirtualenvOperators should work even in these cases.</p> <p>I want to do the following:</p> <ul> <li>set <code>--index-url</code> to our main Artifactory and <code>--extra-ind...
<python><pip><devpi>
2024-11-05 13:33:18
0
3,669
Felix
79,159,200
7,462,275
How to fill spaces between subplots with a color in Matplotlib?
<p>With the following code :</p> <pre><code>nb_vars=4 fig, axs = plt.subplots(4,4,figsize=(8,8), gridspec_kw = {'wspace':0.20, 'hspace':0.20}, dpi= 100) for i_ax in axs: for ii_ax in i_ax: ii_ax.set_yticklabels([]) for i_ax in axs: for ii_ax in i_ax: ii_ax.set_xticklabels([]) </code></pre> <p>T...
<python><matplotlib>
2024-11-05 12:55:05
1
2,515
Stef1611
79,159,186
4,508,605
How to read from csv and generate excel file with same name python
<p>Currently i am reading sql queries from column in csv file, executing them in Snowflake and then generating sql query result in separate excel file for every query. The code is working fine.</p> <p>The excel files are generating with filename as <code>result_1.xlsx</code>, <code>result_2.xlsx</code>. But now i want ...
<python><excel><csv>
2024-11-05 12:49:18
1
4,021
Marcus
79,159,178
7,334,912
Diffuser pipeline embedings not enough values to unpack
<p>I wanted to generate a image using text embedding instead of text as input using clip to tokenizes &amp; embeds.</p> <p>The code so far :</p> <pre><code>from transformers import AutoTokenizer, CLIPTextModelWithProjection model = CLIPTextModelWithProjection.from_pretrained(&quot;openai/clip-vit-base-patch32&quot;) t...
<python><pytorch><huggingface-transformers><huggingface><stable-diffusion>
2024-11-05 12:45:33
0
502
Felox
79,159,168
5,594,008
Ruff and E203 rule
<p>I'm having some issue with string slicing, ruff is formatting such code:</p> <pre><code>result: str custom_index = 5 result = ( result[:custom_index] + f&quot;new_value&quot; + result[custom_index + 7:] ) </code></pre> <p>and makes last line having extra whitespace <code>result[custom_index +...
<python><ruff>
2024-11-05 12:43:13
0
2,352
Headmaster
79,158,863
2,915,050
Call Google API within Cloud Function with Authentication
<p>I'm trying to call the Dataform API from within a Cloud Function, however the identity token I am providing is returning with a <code>'Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.'</code></p> <p>According to the <a href="https:/...
<python><google-api><google-cloud-functions><google-oauth>
2024-11-05 11:17:52
0
1,583
RoyalSwish
79,158,826
18,344,512
Printing nested HTML tables in PyQt6
<p>I have an issue when trying to print the contents of a QTableWidget in a PyQt6 application.</p> <p>It actually works, but there is a small problem: I have tables embedded in the main table and I'd like those tables to completely fill the parent cells (100% of their widths), but the child tables don't expand as expec...
<python><html><printing><pyqt6><qtextdocument>
2024-11-05 11:07:48
2
1,499
SergFSM
79,158,791
11,575,738
Tracking test/val loss when training a model with JAX
<p>JAX when being used for training a machine learning model, we only try to minimize the training loss.</p> <p>Whereas in my requirement, in order to assess the number of epochs or to avoid over-training, I need to know the test loss as well at every parameter update step. But the callback or debug option available in...
<python><machine-learning><logging><jax>
2024-11-05 10:58:38
2
331
Sup
79,158,548
8,254,743
How to control plot size whith different legend size matplotlib
<p>I want to have 2 plots of the same size. The size of the figure is not as important. The only change I am making is to the length of the labels. (In reallity I have 2 related data sets )</p> <p>A long label causes the plot to deform. How can I avoid this? I need 2 coherent plots.</p> <pre><code> import numpy as np f...
<python><numpy><matplotlib><plot><figure>
2024-11-05 09:53:31
2
667
Frank Musterman
79,158,535
10,200,497
How can I check previous values of a column to find the value that is greater than the selected row in another column?
<p>This is my DataFrame:</p> <pre><code>import pandas as pd df = pd.DataFrame({ 'a': [10, 20, 30, 1, 20, 3, 4, 0], 'b': [30, 3, 11, 25, 24, 31, 29, 2], 'c': [True, True, True, False, False, True, True, True] }) </code></pre> <p>Expected output is creating column <code>d</code>:</p> <pre><code> a b ...
<python><pandas><dataframe>
2024-11-05 09:50:36
1
2,679
AmirX
79,158,528
3,967,146
Wrapping class method with correct type hint
<p>I am implementing <code>run</code> in subclasses of <code>ParentClass</code>, which will call <code>run</code> from its <code>__call__</code> method.</p> <p>I want the type hints from <code>Subclass.run</code> to apply to call sites of its <code>__call__</code> method.</p> <p>I would like to define the child classes...
<python><python-typing><mypy><metaclass>
2024-11-05 09:48:28
1
428
gkrupp
79,158,209
8,040,369
Groupby a df column based on 2 other columns
<p>I have an df which has 3 columns lets say Region, Country and AREA_CODE.</p> <pre><code>Region Country AREA_CODE =================================== AMER US A1 AMER CANADA A1 AMER US B1 AMER US A1 </code></pre> <p>I want to get the output l...
<python><python-3.x><pandas>
2024-11-05 08:27:59
2
787
SM079
79,157,907
10,970,202
Jupyter notebook kernel is not connecting to correct python environment
<p>Version: jupyter_client : 8.6.2 jupyter_core : 5.7.2 jupyter_server : 2.14.2 jupyterlab : 4.2.3</p> <p>Here are steps I've took to create kernel in my jupyter notebook.</p> <ol> <li><p>Create conda env: <code>conda create --name firstEnv</code> <br> <code>conda env list</code> correctly show firstEnv a...
<python><jupyter-notebook><anaconda>
2024-11-05 06:37:31
0
5,008
haneulkim
79,157,864
12,466,687
How to correctly extract Numbers from String using regex in Python?
<p>I am trying to extract Numbers from the string only where it <strong>ends with Numbers or Decimals</strong></p> <pre><code>df = pd.DataFrame({'Names': [&quot;Absolute Neutrophil Count&quot;,&quot;Absolute Lymphocyte Count 2.9&quot;, &quot;Absolute Neutrophil Count 10.2&quot;,&quot;ESR (Modifie...
<python><pandas><regex>
2024-11-05 06:15:12
3
2,357
ViSa
79,157,812
6,457,407
Writing asynchronous code without asyncio
<p>I'm trying to write code that is the equivalent of the busy loop</p> <pre><code>async def wait_for_callback(): while True: &lt;do some work&gt; if &lt;callback has occurred&gt; return &lt;result&gt; await asyncio.sleep(0) </code></pre> <p>However this is intended to be a ...
<python><asynchronous><python-asyncio>
2024-11-05 05:55:44
1
11,605
Frank Yellin
79,157,734
2,825,403
Poetry version solving is confusing
<p>I'm getting quite confused with Poetry version solving and I have no idea why what I'm doing isn't working.</p> <p>I have a project and I'm adding as a dependency another package from an internal company repository, but I'm constantly getting python version conflicts. Let's say the name of the package I'm trying to ...
<python><python-poetry>
2024-11-05 05:16:57
0
4,474
NotAName
79,157,437
5,527,374
How to change timezone of datetime object using timezone abbreviation
<p>I bet this is easy, but darned if I can figure it out. Standard disclaimer that honestly, I've tried to figure this out.</p> <p>How do you change the time zone of a datetime.datetime object by using the abbreviation of the time zone? For example, if I have an object that has a timezone of EST, how do I get that same...
<python><datetime>
2024-11-05 01:30:37
1
925
tscheingeld
79,157,290
9,108,781
How to interact with Transcend consent manager shadow DOM using Selenium?
<p>I'm trying to automate interaction with a GoFundMe page's privacy consent dialog managed by Transcend. URL: <a href="https://www.gofundme.com/f/10yr-old-pitt-baby-who-needs-emergency-surgery" rel="nofollow noreferrer">https://www.gofundme.com/f/10yr-old-pitt-baby-who-needs-emergency-surgery</a></p> <p>Specifically, ...
<python><selenium-webdriver><selenium-chromedriver><transcend-consent-management>
2024-11-04 23:34:32
1
943
Victor Wang
79,157,273
825,227
How to create a datetimeindex from integer date and time columns in Pandas
<p>I have a dataframe with columns corresponding to days since 1/1/1900 (<code>date</code>) and seconds as part of a 24h day (<code>time</code>).</p> <pre><code> date time 0 40603 34222 1 40603 34223 2 40603 34224 3 40603 34225 4 40603 34226 5 40603 34227 6 40603 34228 7 40603 3422...
<python><pandas><dataframe><datetime>
2024-11-04 23:22:36
2
1,702
Chris
79,157,219
12,152,992
Use Bayesian PyMC linear model on out-of-sample data
<p>I am trying to fit a linear model to data using Bayesian inference technique. For this, I thought of using PyMC. Naturally, after training a model, I want to test its performance on new data and that's where the problem occurs. I don't seem to be able to set a new dataset. Anybody with experience?</p> <p>Example scr...
<python><bayesian><pymc3><pymc>
2024-11-04 22:56:32
1
1,267
Matthi9000
79,157,183
3,247,471
Base class properties and methods from a library class are not being inherited into my subclass
<p>I can't seem to properly inherit a base class into my custom class, in this case, the <a href="https://github.com/python-zeroconf/python-zeroconf/blob/master/src/zeroconf/_services/info.py" rel="nofollow noreferrer">ServiceInfo</a> class from the <a href="https://github.com/python-zeroconf/python-zeroconf" rel="nofo...
<python><inheritance>
2024-11-04 22:32:10
0
1,126
Raul Marquez
79,157,168
16,611,809
Does polars not distinguish between tuple and list?
<p>For Pandas I sometimes cast nested lists to tuples e.g. to be able to drop duplicates (being aware that order of the elements would matter). For Polars there does not seem to be a difference between lists and tuples. I can't find anymore info on this. Could someone elaborate this a little?</p> <pre><code>import pola...
<python><tuples><python-polars>
2024-11-04 22:20:53
1
627
gernophil
79,157,113
1,931,605
Faster RCNN with Pytorch Lightning not showing better results mAP
<p>I've tried to fine-tune the model for binary class object detection Following is the code</p> <p>There are only single class in COCO dataset with label 1 to classify that as object.</p> <p>Tensorboard showing poor results. Can someone help me understand why its not getting better results. Even YOLO shows better than...
<python><deep-learning><pytorch><pytorch-lightning>
2024-11-04 21:54:53
0
10,425
Shan Khan