Skip to content

Rm networkx.algorithms.threshold.swap_d. - #8213

Merged
MridulS merged 1 commit into
networkx:mainfrom
rossbar:rm-threshold-swap_d
Aug 31, 2025
Merged

MridulS merged 1 commit into
networkx:mainfrom
rossbar:rm-threshold-swap_d

Conversation

@rossbar

@rossbar rossbar commented Aug 30, 2025

Copy link
Copy Markdown
Contributor

A proposal to remove the swap_d function from the threshold module.

I originally came across this via test coverage - according to coverage metrics, this function is "covered" by the test_all_random_functions test, but that just tests that it runs with a single set of parameters. While trying to design more tests for this function, I found some (IMO) bugs. For example:

>>> from networkx.algorithms import threshold as nxt
>>> cs = ['d', 'd', 'd', 'i', 'i', 'd']
>>> nxt.swap_d(cs)
Traceback (most recent call last)
   ...
IndexError: Cannot choose from an empty sequence

This error originates from this section in the code - in particular, the dlist leaves off the first and last element of the list, but doesn't account for this truncation in the enumeration. Therefore it's possible for choice to end up being 0, which then causes the IndexError in L1012 when you try to seed.choice(range(0))


Ultimately, I suspect that this function is neither very reliable nor widely used. Given that the swap_d function is not tested (aside from smoke tests - see the test removals in this PR which cover all instances in the test suite) nor used internally anywhere else in the library, that proposing to remove it is justified. Given the fact that this is in a non-auto-imported module and there have been (to my knowledge) no issues raised related to it (despite the bugs, though they are stochastic) I'm proposing to remove it without a deprecation.

@dschult

dschult commented Aug 30, 2025

Copy link
Copy Markdown
Member

I agree that swap_d can/should be removed without deprecation.
It is not a public function, and is not discussed in relation to any other threshold graph manipulation functions.

Thanks @rossbar !

@MridulS
MridulS merged commit 6b57b27 into networkx:main Aug 31, 2025
@MridulS MridulS added this to the 3.6 milestone Aug 31, 2025
alfred-mikhael pushed a commit to alfred-mikhael/networkx that referenced this pull request Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants