-
Notifications
You must be signed in to change notification settings - Fork 36
Description
Description
The jyotishganit library fails to calculate sunrise/sunset times for certain date/location combinations, returning None values. This causes a TypeError when the library attempts to compare None with float in the compute_nathonnatabala function during shadbala calculations.
Error Details
Error Type
TypeError: '<=' not supported between instances of 'NoneType' and 'float'
Error Location
File "/opt/venv/lib/python3.11/site-packages/jyotishganit/components/strengths.py", line 498, in compute_nathonnatabala
is_day_birth = sunrise <= birth_hour < sunset
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<=' not supported between instances of 'NoneType' and 'float'
Full Traceback
Traceback (most recent call last):
File "/app/src/services/shadbala_services.py", line 200, in calculate_shadbala
chart = await to_thread_with_context(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/jyotishganit/main.py", line 86, in calculate_birth_chart
strengths.calculate_all_strengths(d1_chart, person)
File "/opt/venv/lib/python3.11/site-packages/jyotishganit/components/strengths.py", line 176, in calculate_all_strengths
compute_shadbala(chart, person)
File "/opt/venv/lib/python3.11/site-packages/jyotishganit/components/strengths.py", line 187, in compute_shadbala
compute_kaalabala(chart, person)
File "/opt/venv/lib/python3.11/site-packages/jyotishganit/components/strengths.py", line 479, in compute_kaalabala
compute_nathonnatabala(chart, person)
File "/opt/venv/lib/python3.11/site-packages/jyotishganit/components/strengths.py", line 498, in compute_nathonnatabala
is_day_birth = sunrise <= birth_hour < sunset
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<=' not supported between instances of 'NoneType' and 'float'
Steps to Reproduce
- Install jyotishganit library (tested with version >=0.1.2)
- Call
calculate_birth_chartwith the following parameters:
from datetime import datetime
from jyotishganit import calculate_birth_chart
birth_date = datetime(2006, 7, 8, 22, 30, 0)
latitude = 28.643364
longitude = 77.115472
timezone_offset = 5.5
name = "Test Person"
chart = calculate_birth_chart(
birth_date=birth_date,
latitude=latitude,
longitude=longitude,
timezone_offset=timezone_offset,
name=name,
)- The error occurs during the shadbala calculation phase
Expected Behavior
The library should:
- Successfully calculate sunrise/sunset times for the given date/location
- If calculation fails, handle the
Nonevalues gracefully instead of crashing - Provide a meaningful error message if sunrise/sunset cannot be calculated
Actual Behavior
- Sunrise/sunset calculation returns
Nonefor this specific date/location combination - The library crashes with
TypeErrorwhen trying to compareNonewithfloat - No graceful error handling for this edge case
Environment
- Python Version: 3.11
- jyotishganit Version: >=0.1.2
- Operating System: Linux (tested in Docker container)
- Location: Delhi, India (28.643364°N, 77.115472°E)
- Date: July 8, 2006
- Timezone: UTC+5.5 (IST)
Additional Context
Observations
- Date-Specific Issue: The same location works fine for July 9, 2006, suggesting this is a date-specific calculation issue
- Location: Delhi, India is not a polar region, so this shouldn't be a polar day/night issue
- Library Dependency: The library appears to use skyfield/ephemeris data (de421.bsp file is downloaded)
- Impact: This affects all calculations that require shadbala (kaalabala component specifically)
Workaround
Currently, we're handling this by:
- Catching the
TypeErrorand providing a user-friendly error message - Pre-validating sunrise/sunset calculation using the
astrallibrary before calling jyotishganit - Suggesting users try a different date if the exact date is not critical
However, this is not ideal as:
- Users cannot get calculations for their actual birth date
- The library should handle this gracefully internally
Suggested Fix
-
Immediate Fix: Add null checks in
compute_nathonnatabalabefore comparing sunrise/sunset values:if sunrise is None or sunset is None: # Handle gracefully - either skip nathonnatabala calculation # or use a fallback method to determine day/night logger.warning("Sunrise/sunset calculation failed, skipping nathonnatabala") return is_day_birth = sunrise <= birth_hour < sunset
-
Long-term Fix: Investigate why sunrise/sunset calculation returns
Nonefor certain dates and fix the underlying calculation -
Better Error Handling: Provide meaningful error messages when astronomical calculations fail
Related Information
- The issue occurs specifically when calculating shadbala, which requires kaalabala
- Kaalabala includes nathonnatabala, which needs sunrise/sunset times
- Other calculations (like panchanga, ashtakavarga) may also be affected if they trigger shadbala calculation
Verification
We've verified that:
- ✅ The same location works for July 9, 2006 (next day)
- ✅ The coordinates are valid (Delhi, India)
- ✅ The timezone offset is correct (5.5 for IST)
- ✅ The date is valid (July 8, 2006 exists)
- ✅ Using alternative libraries (astral) can calculate sunrise/sunset for this date
This suggests the issue is in jyotishganit's internal sunrise/sunset calculation logic, not in the input parameters.
Note: This issue prevents users from getting accurate astrological calculations for their actual birth dates when the library encounters this bug. A fix would greatly improve the library's reliability and user experience.