GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Unsupported NumPy datatype complex128 · Issue #1188 · python-control/python-control

Unsupported NumPy datatype complex128 #1188

New issue
Copy link
New issue
Copy link
Open
Bug
Open
Unsupported NumPy datatype complex128#1188
Bug
Copy link

Description

@sachinumans
sachinumans
opened on Nov 24, 2025
Issue body actions

Dear developers,

I've encountered what could be an unintentional exception (TypeError). This MWE codesnippet:

import numpy as np
import control as cm

P = cm.rss(5)
q1 = cm.zpk(zeros=P.zeros().astype(np.complex64), 
            poles=P.poles().astype(np.complex64), 
            gain=1, dt=0)

q2 = cm.zpk(zeros=P.zeros().astype(np.complex128),
            poles=P.poles().astype(np.complex128),
            gain=1, dt=0)

outputs (sometimes only on the 2nd execution):

Traceback (most recent call last):
  File "...\scratch.py", line 9, in <module>
    q2 = cm.zpk(zeros=P.zeros().astype(np.complex128),
                poles=P.poles().astype(np.complex128),
                gain=1, dt=0)
  File "...\Local\Programs\Python\Python313\Lib\site-packages\control\xferfcn.py", line 1819, in zpk
    return TransferFunction(num, den, *args, **kwargs)
  File "...\Local\Programs\Python\Python313\Lib\site-packages\control\xferfcn.py", line 207, in __init__
    num = _clean_part(num, "numerator")
  File "...\Local\Programs\Python\Python313\Lib\site-packages\control\xferfcn.py", line 2005, in _clean_part
    raise TypeError(
        f"unsupported data type: {type(out[i, j][k])}")
TypeError: unsupported data type: <class 'numpy.complex128'>

From the top of my head, I can't think of a reason why 4 byte complex numbers are allowed, but 8 bytes aren't. If there is, please enlighten me!

However, I think there are more incompatibilities between NumPy and this xferfcn.py file, because executing
print(q1)
yields

File "...\scratch.py", line 13, in <module>
    print(q1)
    ~~~~~^^^^
  File "...\Local\Programs\Python\Python313\Lib\site-packages\control\xferfcn.py", line 447, in __str__
    denstr = _tf_polynomial_to_string(
        self.den_array[no, ni], var=var)
  File "...\Local\Programs\Python\Python313\Lib\site-packages\control\xferfcn.py", line 1366, in _tf_polynomial_to_string
    coeffs = eval(repr(coeffs))
  File "<string>", line 2, in <module>
NameError: name 'float32' is not defined. Did you mean: 'float64'?

Package versions:
numpy==2.2.6
control==0.10.2

Kind regards,
Sachin

Activity

  1. murrayrm commented on Nov 29, 2025

    @murrayrm
    murrayrm
    on Nov 29, 2025
    Member
    More actions

    Thanks for pointing out these issues. The python-control toolbox doesn't support complex numbers are coefficients for transfer functions (see #484, among others), but the code should catch those cases earlier.

  2. murrayrm
    added the
    Bug
    issue type on Nov 29, 2025
  3. marko1olo commented on Aug 14, 2026

    @marko1olo
    marko1olo
    on Aug 14, 2026
    More actions

    Opened PR #1244 to fix both issues:

    1. _clean_part now casts complex coefficient arrays to real floats when imaginary parts are within zero tolerance (np.allclose(imag, 0)), preventing TypeError on complex64/complex128 arrays from zpk.
    2. _tf_polynomial_to_string now uses np.asarray(coeffs).tolist(), eliminating the brittle eval(repr(coeffs)) that failed with NameError: name 'float32' is not defined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.