Skip to content

fix(xferfcn): support complex dtypes in zpk and safe polynomial stringification - #1244

Open
marko1olo wants to merge 6 commits into
python-control:mainfrom
marko1olo:fix-zpk-complex-dtypes
Open

fix(xferfcn): support complex dtypes in zpk and safe polynomial stringification#1244
marko1olo wants to merge 6 commits into
python-control:mainfrom
marko1olo:fix-zpk-complex-dtypes

Conversation

@marko1olo

@marko1olo marko1olo commented Aug 14, 2026

Copy link
Copy Markdown

Problem

Fixes #1188.

  1. When zeros and poles are passed as NumPy arrays with complex64 or complex128 dtypes (e.g. from rss(5).zeros().astype(np.complex128)), zpk2tf computes polynomial roots using np.poly(). Residual imaginary parts or complex dtypes with negligible imaginary components (abs(imag) < 1e-10) triggered TypeError: unsupported data type: <class 'numpy.complex128'>.
  2. In _tf_polynomial_to_string, eval(repr(coeffs)) raised NameError: name 'float32' is not defined on NumPy arrays with float32 dtypes.

Solution

  1. In _clean_part, check if out[i, j] is complex: if all imaginary components are within numerical tolerance of zero (np.allclose(np.imag(out[i, j]), 0.0, atol=1e-10)), cast to real float array (np.real(out[i, j]).astype(float)). If true non-zero imaginary parts exist, raise the clear TypeError.
  2. In _tf_polynomial_to_string, convert coeffs via np.asarray(coeffs).tolist(), eliminating brittle eval(repr(...)) and supporting all NumPy numeric dtypes (float32, float64, etc.).
  3. Added unit test test_zpk_complex_dtypes in control/tests/xferfcn_test.py.

AI Disclosure (per NumPy AI Policy): Claude (Anthropic) used as a coding assistant via IDE chat. All code is reviewed, understood, tested, and submitted by me. The fix logic and test design are my own.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 94.75% (-0.007%) from 94.757% — marko1olo:fix-zpk-complex-dtypes into python-control:main

@slivingston

Copy link
Copy Markdown
Member

@marko1olo Please do not submit any more PRs until your other open PRs are handled (closed or merged).

@slivingston

Copy link
Copy Markdown
Member

@marko1olo Also, you opened another PR that claims to fix #1188: #1226

What is the relationship between that PR and this one?

@marko1olo

Copy link
Copy Markdown
Author

@slivingston Sorry about the confusion. #1226 was my original attempt at fixing #1188, but #1244 takes a different (and cleaner) approach — it addresses the root cause in the ZPK conversion rather than rejecting complex coefficients at the TF constructor level. I'd suggest closing #1226 in favor of this one. I'll close #1226 myself. Apologies for the PR noise.

@slivingston

slivingston commented Aug 16, 2026

Copy link
Copy Markdown
Member

@murrayrm @bnavigator @sawyerbfuller

There is evidence that this user is an AI agent:

  • posting comments across multiple pull requests within 1 - 2 seconds of each other, a feat that overwhelmingly implies automation;
  • opening multiple pull requests to fix the same issue, and not offering a good reason how it happened;
  • dodging questions about impersonation with vague answers.

The above already violates the NumPy AI Policy (https://numpy.org/doc/stable/dev/ai_policy.html#communication).

While some PRs have been merged and fix small issues, there are repeatedly quality problems that would not happen if a human was involved (e.g., modifying LICENSE in multiple PRs) or was familiar with control systems.

In summary, I think this is just an agent using Claude, Codex, etc., that reads our issue tracker and then automatically generates PRs. Because

  1. it is a review burden;
  2. there is probably little or no human in the loop for their user account;
  3. we can use code generation tools on our own;

therefore I blocked the user. I can unblock them if you disagree.

To add to this, other repos where this user has tried to contribute have already identified the problem, e.g.,
"spamming this project with lazy AI slop code is bad enough..." terrazzoapp/terrazzo#801 (comment)

@murrayrm

Copy link
Copy Markdown
Member

I'm OK with the block. Even if the user wasn't an AI agent, they have done a lot of things that have caused a lot of extra work.

We should probably close out any PR that requires additional modifications, since the user won't be able address them if they are blocked. Someone else can pick up the issue, see the proposed change, the submit a new PR at a future point.

We can let things sit for a day or two, to see if others have comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsupported NumPy datatype complex128

4 participants