Repository: SETI/rms-cspyce (language: python)

Issue:
`ekgd` does not give the correct `ddata` value
The function `ekgd` returns an element of an entry in a column of floating-point type in a specified row of a SPICE Events Kernel (EK). Here are the inputs and returns:

```
    Inputs:
      int   selidx = Index of parent column in SELECT clause.
      int   row    = Row to fetch from.
      int   elment = Index of element, within column entry, to fetch.
    
    Returns:
      float ddata  = Double precision element of column entry.
      bool  null   = Flag indicating whether column entry was null.
    
    Note: Raise IndexError(INDEXOUTOFRANGE) if the column is not present
    in the row.
```

The unit test for this function is currently failing:

```
import cspyce as cs
import os
from gettestkernels import TEST_FILE_DIR


def cleanup_kernel(path):
    cs.kclear()
    cs.reset()
    if os.path.isfile(path):
        os.remove(path)  # pragma: no cover
    pass
    
ekpath = os.path.join(TEST_FILE_DIR, "example_ekgd.ek")
cleanup_kernel(ekpath)
handle = cs.ekopn(ekpath, ekpath, 0)
segno, rcptrs = cs.ekifld(
    handle,
    "test_table_ekgd",
    2,
    ["c1"],
    ["DATATYPE = DOUBLE PRECISION, NULLS_OK = TRUE"],
)
cs.ekacld(
    handle, segno, "c1", [1.0, 2.0], [1, 1], [False, False], rcptrs
)
cs.ekffld(handle, segno, rcptrs)
cs.ekcls(handle)
cs.kclear()
cs.furnsh(ekpath)
nmrows = cs.ekfind("SELECT C1 FROM TEST_TABLE_EKGD")
d, null = cs.ekgd(0, 0, 0)
assert not null
assert d == 1.0
d, null = cs.ekgd(0, 1, 0)
assert not null
assert d == 2.0
cs.kclear()
cleanup_kernel(ekpath)
assert not os.path.exists(ekpath)
```

The failure occurs on the first assert for the `ddata` value (represented here as `d`). `d` should pass this assert, but it is instead giving a value of `4.2439915824e-314`. This value has the correct data type, but is otherwise incorrect.



Discussion / hints:
I see a call to ekifld.  Has that been fixed already?

On Mon, Jun 12, 2023 at 1:41 PM esimpsons3ti ***@***.***>
wrote:

> Assigned #88 <https://github.com/SETI/pds-cspyce/issues/88> to @fyellin
> <https://github.com/fyellin>.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/SETI/pds-cspyce/issues/88#event-9507635723>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABC2LIN5E65N2NHQMOLIFV3XK55F3ANCNFSM6AAAAAAZD4XSOI>
> .
> You are receiving this because you were assigned.Message ID:
> ***@***.***>
>

Frank,

I have an open pull request that is awaiting review from Rob. This pull request contains the fix.



Get Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: fyellin ***@***.***>
Sent: Monday, June 12, 2023 2:41:36 PM
To: SETI/pds-cspyce ***@***.***>
Cc: Emilie Simpson ***@***.***>; Author ***@***.***>
Subject: Re: [SETI/pds-cspyce] `ekgd` does not give the correct `ddata` value (Issue #88)

I see a call to ekifld. Has that been fixed already?

On Mon, Jun 12, 2023 at 1:41 PM esimpsons3ti ***@***.***>
wrote:

> Assigned #88 <https://github.com/SETI/pds-cspyce/issues/88> to @fyellin
> <https://github.com/fyellin>.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/SETI/pds-cspyce/issues/88#event-9507635723>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABC2LIN5E65N2NHQMOLIFV3XK55F3ANCNFSM6AAAAAAZD4XSOI>
> .
> You are receiving this because you were assigned.Message ID:
> ***@***.***>
>

—
Reply to this email directly, view it on GitHub<https://github.com/SETI/pds-cspyce/issues/88#issuecomment-1588145595>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A2JGO3TI7PUOMYYYZZKAEULXK6EJBANCNFSM6AAAAAAZD4XSOI>.
You are receiving this because you authored the thread.Message ID: ***@***.***>

Bug is in ekacld.  cspyce0_part2.i,  4433ff.  

```
%apply (ConstSpiceInt  IN_ARRAY1[]) {ConstSpiceDouble  dvals[]};
```

should be 

```
%apply (ConstSpiceDouble  IN_ARRAY1[]) {ConstSpiceDouble  dvals[]};
```



The pull referenced above is not passing the test suite.
Yes, but it’s now due to test_kernels.py, a file that predates my work.

Get Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: Robert French ***@***.***>
Sent: Monday, June 12, 2023 6:33:52 PM
To: SETI/pds-cspyce ***@***.***>
Cc: Emilie Simpson ***@***.***>; Assign ***@***.***>
Subject: Re: [SETI/pds-cspyce] `ekgd` does not give the correct `ddata` value (Issue #88)


The pull referenced above is not passing the test suite.

—
Reply to this email directly, view it on GitHub<https://github.com/SETI/pds-cspyce/issues/88#issuecomment-1588375174>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A2JGO3WVS3ZCA2DKZGBOSHLXK67QBANCNFSM6AAAAAAZD4XSOI>.
You are receiving this because you were assigned.Message ID: ***@***.***>

True, but doesn't matter. I can't merge a pull with failing tests. You need to fix `test_kernels.py` now that the function is returning the correct value.
The pull request is now passing.

From: Robert French ***@***.***>
Date: Monday, June 12, 2023 at 6:39 PM
To: SETI/pds-cspyce ***@***.***>
Cc: Emilie Simpson ***@***.***>, Assign ***@***.***>
Subject: Re: [SETI/pds-cspyce] `ekgd` does not give the correct `ddata` value (Issue #88)

True, but doesn't matter. I can't merge a pull with failing tests. You need to fix test_kernels.py now that the function is returning the correct value.

—
Reply to this email directly, view it on GitHub<https://github.com/SETI/pds-cspyce/issues/88#issuecomment-1588380528>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A2JGO3UPWHEKCAM7RCRHNCLXK7AF3ANCNFSM6AAAAAAZD4XSOI>.
You are receiving this because you were assigned.Message ID: ***@***.***>


Fix patch:
diff --git a/swig/cspyce0_part2.i b/swig/cspyce0_part2.i
index 2948f983..7d31966f 100644
--- a/swig/cspyce0_part2.i
+++ b/swig/cspyce0_part2.i
@@ -4433,7 +4433,7 @@ extern void ekacei_c(
 %rename (ekacld) my_ekacld_c;
 %apply (void RETURN_VOID) {void my_ekacld_c};
 %apply (ConstSpiceChar *CONST_STRING) {ConstSpiceChar *column};
-%apply (ConstSpiceInt     IN_ARRAY1[]) {ConstSpiceDouble  dvals[]};
+%apply (ConstSpiceDouble  IN_ARRAY1[]) {ConstSpiceDouble  dvals[]};
 %apply (ConstSpiceInt     IN_ARRAY1[]) {ConstSpiceInt     entszs[]};
 %apply (ConstSpiceBoolean IN_ARRAY1[]) {ConstSpiceBoolean nlflgs[]};
 %apply (ConstSpiceInt     IN_ARRAY1[]) {ConstSpiceInt     rcptrs[]};


Test patch:
diff --git a/unittests/test_d.py b/unittests/test_d.py
index 4bb044dd..e484e91e 100644
--- a/unittests/test_d.py
+++ b/unittests/test_d.py
@@ -645,10 +645,9 @@ def test_diags2():
 
 def test_dlabbs_dlafps():
     handle = cs.dasopr(ExtraKernels.phobosDsk)
-    cs.use_flags(cs.dlabbs)
     current = cs.dlabbs(handle)
     assert current is not None
-    assert current[0][5] == 1300
+    assert current[5] == 1300
     with pytest.raises(Exception):
         prev = cs.dlafps(handle, current)
     cs.dascls(handle)
@@ -664,7 +663,7 @@ def test_dlabfs_dlafns():
     cs.dascls(handle)
 
 
-def test_dlafns():
+def fail_dlafns():
     handle = cs.dasopr(ExtraKernels.phobosDsk)
     cs.use_flags(cs.dlafns)
     current = cs.dlabfs(handle)
@@ -1085,9 +1084,8 @@ def test_dskxsi():
 def test_dskxv():
     # load kernels
     cs.furnsh(ExtraKernels.phobosDsk)
-    cs.use_flags(cs.kdata)
     # get handle
-    dsk1, filtyp, source, handle, found = cs.kdata(0, "DSK")
+    dsk1, filtyp, source, handle = cs.kdata(0, "DSK")
     # get the dladsc from the file
     dladsc = cs.dlabfs(handle)
     # get dskdsc for target radius
@@ -1113,7 +1111,7 @@ def test_dskxv_2():
     # load kernels
     cs.furnsh(ExtraKernels.phobosDsk)
     # get handle
-    dsk1, filtyp, source, handle, found = cs.kdata(0, "DSK")
+    dsk1, filtyp, source, handle = cs.kdata(0, "DSK")
     # get the dladsc from the file
     dladsc = cs.dlabfs(handle)
     # get dskdsc for target radius
diff --git a/unittests/test_e.py b/unittests/test_e.py
index eb2f1e10..8cc34cb0 100644
--- a/unittests/test_e.py
+++ b/unittests/test_e.py
@@ -383,7 +383,6 @@ def test_ekffld():
 
 
 def test_ekfind():
-    cs.use_flags(cs.ekfind)
     ekpath = os.path.join(TEST_FILE_DIR, "example_ekfind.ek")
     cleanup_kernel(ekpath)
     handle = cs.ekopn(ekpath, ekpath, 0)
@@ -410,7 +409,6 @@ def test_ekfind():
 
 
 def test_ekgc():
-    cs.use_flags(cs.ekgc)
     ekpath = os.path.join(TEST_FILE_DIR, "example_ekgc.ek")
     cleanup_kernel(ekpath)
     handle = cs.ekopn(ekpath, ekpath, 0)
@@ -430,10 +428,10 @@ def test_ekgc():
     cs.kclear()
     cs.furnsh(ekpath)
     nmrows = cs.ekfind("SELECT C1 FROM TEST_TABLE_EKGC")
-    c, null, __ = cs.ekgc(0, 0, 0)
+    c, null = cs.ekgc(0, 0, 0)
     assert not null
     assert c == "1.0"
-    c, null, __ = cs.ekgc(0, 1, 0)
+    c, null = cs.ekgc(0, 1, 0)
     assert not null
     # assert c == "2.0" this fails, c is an empty string despite found being true.
     cs.kclear()
@@ -441,7 +439,7 @@ def test_ekgc():
     assert not os.path.exists(ekpath)
 
 
-def fail_ekgd():
+def test_ekgd():
     ekpath = os.path.join(TEST_FILE_DIR, "example_ekgd.ek")
     cleanup_kernel(ekpath)
     handle = cs.ekopn(ekpath, ekpath, 0)
@@ -525,7 +523,6 @@ def test_ekifld():
 
 # Fails due to reliance on ekfind
 def fail_ekinsr_eknelt_ekpsel_ekrcec_ekrced_ekrcei():
-    cs.use_flags(cs.ekpsel)
     ekpath = os.path.join(TEST_FILE_DIR, "example_ekmany.ek")
     tablename = "test_table_ekmany"
     cleanup_kernel(ekpath)
@@ -559,17 +556,15 @@ def fail_ekinsr_eknelt_ekpsel_ekrcec_ekrced_ekrcei():
     assert handle is not None
     # Test query using ekpsel
     query = "SELECT c1, d1, i1 from {}".format(tablename)
-    xbegs, xends, xtypes, xclass, tabs, cols, err, errmsg = cs.ekpsel(query)
+    xbegs, xends, xtypes, xclass, tabs, cols = cs.ekpsel(query)
     assert xtypes[0] == 0
     assert xtypes[1] == 1
     assert xtypes[2] == 2
     assert ([0] * 3) == list(xclass)
     assert ([["TEST_TABLE_EKMANY"] * 3]) == tabs
     assert ["C1 D1 I1".split()] == cols
-    assert not err
-    assert "" == errmsg
     # Run query to retrieve the row count
-    nmrows, error, errmsg = cs.ekfind(query)
+    nmrows = cs.ekfind(query)
     assert nmrows == 3
     # test fail case for eknelt
     with pytest.raises(Exception):
@@ -590,7 +585,7 @@ def fail_ekinsr_eknelt_ekpsel_ekrcec_ekrced_ekrcei():
             assert not d_null
             assert d_datum == d_data[r][e]
             # get row char data
-            c_datum, c_null, __ = cs.ekgc(0, r, e)
+            c_datum, c_null = cs.ekgc(0, r, e)
             assert not c_null
             assert c_datum == c_data[r][e]
     # Loop over rows, test .ekrcec/.ekrced/.ekrcei
@@ -698,7 +693,7 @@ def test_eknseg():
     assert not os.path.exists(ekpath)
 
 
-def test_ekntab():
+def fail_ekntab():
     assert cs.ekntab() == 0
 
 
@@ -769,7 +764,7 @@ def fail_ekssum():
     assert not os.path.exists(ekpath)
 
 
-def test_ektnam():
+def fail_ektnam():
     ekpath = os.path.join(TEST_FILE_DIR, "example_ektnam.ek")
     cleanup_kernel(ekpath)
     handle = cs.ekopn(ekpath, ekpath, 0)