This repository was archived by the owner on Aug 1, 2026. It is now read-only.
Commit e966111
committed
Fix: Replace module-level numpy calls with pure Python for Colab/pytest compatibility
PROBLEM: 'NameError: name np is not defined' in Google Colab and pytest
ROOT CAUSE: Module-level numpy calls (PHI = (1 + np.sqrt(5)) / 2) can fail
in pytest collection phase or Colab import ordering.
SOLUTION: Replace np.sqrt(5) with pure Python 5**0.5
Mathematically identical but no numpy dependency at module level.
AFFECTED FILES (10):
===================================
Test Files (2):
- scripts/tests/test_hawking_spectrum_continuum.py (Line 44)
- scripts/tests/test_horizon_hawking_predictions.py (Lines 31 + 48 duplicate!)
Analysis Scripts (3):
- perfect_paired_test.py (Line 42)
- perfect_seg_analysis.py (Line 26)
- perfect_equilibrium_analysis.py (Line 36)
Data Tools (2):
- scripts/data_generators/complete_data_quality_analysis.py (Line 31)
- scripts/data_generators/fill_missing_columns.py (Line 31)
Visualization (1):
- scripts/visualization/create_readme_plots.py (Line 26)
Utilities (2):
- tune_phi_for_87_percent.py (Line 21)
- optimal_regime_validation.py (Line 24)
CHANGE MADE:
===================================
OLD: PHI = (1 + np.sqrt(5)) / 2
NEW: PHI = (1 + 5**0.5) / 2 # Golden ratio (pure Python)
BENEFITS:
- ✅ No numpy dependency at module level
- ✅ No pytest collection race conditions
- ✅ Works in Colab import ordering
- ✅ Mathematically identical (φ = 1.618...)
- ✅ Pure Python - faster module load
TESTING:
Verified: 5**0.5 == np.sqrt(5) → True (within float precision)
Result: PHI = 1.618033988749895 (exact same value)
This fixes the Colab error shown in screenshot:
NameError: name 'np' is not defined at Line 44 in test_hawking_spectrum_continuum.py1 parent f967380 commit e966111
10 files changed
Lines changed: 10 additions & 13 deletions
File tree
- scripts
- data_generators
- tests
- visualization
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | 47 | | |
51 | 48 | | |
52 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
0 commit comments