Repository navigation
BUG: Preserve NumPy complex scalars in object data - #982
Merged
Merged
Conversation
Object arrays and the object columns of a Series or DataFrame are converted by _object_values. The values are cast to complex128 in one step, which accepts every real and complex number and rejects elements that are not numbers, and the real parts are returned as float64 if every imaginary part is 0. Complex data are complex128 if allowed and rejected otherwise. This replaces the element-by-element searches for complex scalars, and NumPy no longer issues a ComplexWarning. None is still rejected in an ndarray and is NaN in pandas data. It is found before the cast, since NumPy casts None to a complex NaN. Co-Authored-By: Claude Opus 5.5 <[email protected]>
bashtage
marked this pull request as ready for review
October 29, 2026 14:54
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #982 +/- ##
=======================================
Coverage 98.95% 98.96%
=======================================
Files 138 138
Lines 30148 30221 +73
Branches 2339 2345 +6
=======================================
+ Hits 29834 29907 +73
- Misses 256 257 +1
+ Partials 58 57 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jngod2011
pushed a commit
to jngod2011/arch
that referenced
this pull request
Oct 31, 2026
- Highlights and new features: NGARCH (bashtage#966), the VaR backtests (bashtage#965), the local block bootstrap (bashtage#967) and bandwidth_method (bashtage#964, and phillips_ouliaris here). - Changes that alter results: the automatic bandwidth entry of bashtage#983 now also describes the bandwidth of the kernels with bounded support, the fractional bandwidths and the Tukey-Parzen constant of bashtage#964, its S&P 500 bandwidths are those of the bandwidth attribute (30.96 and 34.50, where it said the 31.96 and 35.50 of opt_bandwidth), and it links phillips_ouliaris in arch.unitroot.cointegration. The ADF-Z tables of bashtage#972, bashtage#973 and bashtage#980. - Backward-incompatible changes: strings in object data. - Bug fixes: bashtage#954, bashtage#970, bashtage#974, bashtage#975, bashtage#977, bashtage#978, bashtage#982, and the constant data of the Newey-West bandwidth and mackinnonp at -inf and inf. - Maintenance: the CI changes and the version file. - Contributors: galafis, jackiectl2, mkzung and wavebyrd.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #976
Takes over #976 by @galafis, whose commit is kept unchanged, and implements the review comments on it.
The bug (from #976).
as_float64converted object data withastype(float64)first. NumPy complex scalars (np.complex128(1 + 2j),np.complex64) in object data were cast to their real parts with aComplexWarning. The imaginary parts were therefore lost withallow_complex=True, and complex data were accepted withallow_complex=False. Pythoncomplexelements were already handled, since casting them to float64 raises.The change (review). All object data now go through one helper,
_object_values. It is used for object ndarrays (as_float64,check_array) and for the object columns of a Series or DataFrame (ensure1d,ensure2d).TypeError.allow_complex, and aTypeErrorif not.isinstancescans in BUG: Preserve NumPy complex scalars in object data #976 are gone), and noComplexWarning.Noneis still rejected in an ndarray and still becomes NaN in pandas data, since pandas treats it as missing. It is found before the cast, since NumPy castsNonetonan+nanj, which would look like complex data.Behaviour changes against main.
allow_complex=True; on main they became float64 with aComplexWarning. Withoutallow_complexthey now raise aTypeError; on main they were accepted.2 + 0j,np.complex128(1)) are real data: float64 for both values ofallow_complex. On main, such Python complex values were rejected withoutallow_complexand became complex128 with it, and the NumPy ones became float64 with aComplexWarning.Everything else is unchanged on 21 kinds of object data (ndarray, Series and DataFrame, both values of
allow_complex): numeric strings,Decimal/Fraction, large ints, longdouble and float32 scalars, empty arrays, NaN andNone.Tests.
arch/tests/utility/test_dtype_policy.pyadds:Nonein pandas object data;The new tests fail on main, and the zero-imaginary ones also fail on the head of #976.
test_dtype_policy.py: 519 passed with-W error, and also on Python 3.10 with NumPy 1.23.5 and pandas 1.5.3.arch/tests/utilityandtest_dtype_inputs.py, 1,487 passed.🤖 Generated with Claude Code