Skip to content

Dataset derive from pandas data frame? #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PySimpleSQL opened this issue Apr 13, 2023 · 45 comments
Closed

Dataset derive from pandas data frame? #281

PySimpleSQL opened this issue Apr 13, 2023 · 45 comments

Comments

@PySimpleSQL
Copy link
Owner

I've been kicking this around for a while. ResultSets and therefore the dataset rows extend simple lists. Pandas would be a much more powerful option.

This is more of a long term goal, but I wanted to at least get it in the system

@ssweber
Copy link
Collaborator

ssweber commented Apr 13, 2023

That, and it would be nice to load/export a dict/json/etc as a dataset.

Some interesting google results:

https://github.com/petbox-dev/tafra

https://github.com/sfu-db/connector-x
https://github.com/pola-rs/polars

PySimpleSQL added a commit that referenced this issue Apr 15, 2023
Got it pretty close to working (at least for the sqlite driver).  More debugging and troubleshooting to go!
PySimpleSQL added a commit that referenced this issue Apr 15, 2023
Lots of cleanup to do yet!
PySimpleSQL added a commit that referenced this issue Apr 16, 2023
PySimpleSQL added a commit that referenced this issue Apr 16, 2023
More cleanup and experimentation.  There is an issue with saving where sometimes the dict gets an extra key "0" and the update query fails.  Also, even at times that the query goes through, the DataSet does not seem to update immediately to show the difference
PySimpleSQL added a commit that referenced this issue Apr 16, 2023
A little closer now.  New records insert and mark as virtual.  There was an issue with using .applymap on DataSet.rows, as .applymap returns a Dataset object directly, which was overwriting the ResultSet object.  This fixes that issue.

Still more to go, but another step closer
@PySimpleSQL
Copy link
Owner Author

I'm done for the night. Was going to look at delete behavior next. Have at it if you're up - I wont be back for 12 hours or so.

It looks pretty simple - the recursion constants returned don't play well with Pandas directly (ambiguous compares), so we need a slightly different solution (maybe even adding them as a status in the ResultSet?)

@ssweber
Copy link
Collaborator

ssweber commented Apr 17, 2023

Is it because black turned our constant int into a tuple?

I don’t have time to check, but fix this first:

DELETE_CASCADE_RECURSION_LIMIT = (
    15  # Mysql sets this as 15 when using foreign key CASCADE DELETE
)

Should be

# Mysql sets this as 15 when using foreign key CASCADE DELETE
DELETE_CASCADE_RECURSION_LIMIT = 15



@ssweber
Copy link
Collaborator

ssweber commented Apr 17, 2023

Or maybe that isn’t a tuple (remember, you’re working with a big newbie here)

either way, the way black handles trailing comments leaves something to be desired for sure.

@ssweber
Copy link
Collaborator

ssweber commented Apr 17, 2023

I’ll take a look at it tomorrow. I return None if the parent doesn’t have a dependent in delete_record_recursive… which probably isn’t right.

@ssweber
Copy link
Collaborator

ssweber commented Apr 17, 2023

Because then it’s comparing “if Result (None) == int”

@PySimpleSQL
Copy link
Owner Author

Just writing a few quick thoughts down

  • May need to consider getting rid of ResultSet completely and having SQLDrivers return raw dataframes instead. Even though ResultSet extends DataFrame, a lot of DataFrame methods return another DataFrame in the process, which makes working with ResultSets a little tricky. It's something that we can deal with in the pysimplesql codebase, but tacking on that complexity to an end user that just wants to use DataFrames isn't really desirable.

I might try using DataFrame.attrs to store the extra metadata that is normally associated with a ResultSet. This should make it much easier to use the DataFrame objects

@ssweber
Copy link
Collaborator

ssweber commented Apr 17, 2023

I was reading up on attrs. When I get to work I’ll check if this bug (pandas-dev/pandas#41572) is still unfixed. Apparently they arnt always persistent in all operations / don’t reattach on copy?

Also see this discussion: pandas-dev/pandas#52166

maybe it’s worth storing them separate eg

Dataset.rows_df (current rows)
Dataset.rows_attrs

@PySimpleSQL
Copy link
Owner Author

Yeah, though I think the bug revolves more around DataFrame attrs overwriting Series attrs, which shouldn't affect us. We will see I guess.

I already have huge progress on eliminating ResultSet and using DataFrames directly. I have sorting 90% working now also (I need to rewrite the part that sorts based on the fk relationship). So far there have been no issues in my testing. I'm hoping to push the changes soon, just getting sporadic chances to work on it so far today

@ssweber
Copy link
Collaborator

ssweber commented Apr 17, 2023

Awesome. I figured you would be the better judge on if that was a big deal or not.

PySimpleSQL added a commit that referenced this issue Apr 17, 2023
Worked towards getting rid of ResultSet entirely and having SQLDriver.execute() returning DataFrames directly with the appropriate attrs set
PySimpleSQL added a commit that referenced this issue Apr 17, 2023
Sorting code moved into DataSet.  Still some work to do, but very close to being functional again
PySimpleSQL added a commit that referenced this issue Apr 17, 2023
Sorting code working.  Still need to work out how to sort FK relationships by their description column
PySimpleSQL added a commit that referenced this issue Apr 17, 2023
Pretty big step backwards with this one. Working on cleaning up the sorting code had some unexpected consequences.  I'm out of time for a while, so checking this in for now
@ssweber
Copy link
Collaborator

ssweber commented Apr 18, 2023

@PySimpleSQL I think my most recent push fixes most stuff.

1 issue:

  1. 'Sort column is None. Resetting Sort' will allow me to relabel 'A Person' to 'Z Person' in the description column, and it stays in-place. I get why that happens (I think), but wanted to know if you thought that was the behavior you wanted. If you have any column sorted, then behavior works as I would expect 👍

what additional part of _SortCallbackWrapper do you want to integrate into def sort? (if any)

    def __call__(self, column):
        if len(self.frm[self.data_key].rows.index):
            # sort_cycle takes care of storing pk and calling set_by_pk()
            sort_order = self.frm[self.data_key].sort_cycle(column, self.data_key)

            self.frm.update_selectors(self.data_key)
            self.frm.update_elements(edit_protect_only=True)
            self.table_heading.update_headings(self.element, column, sort_order)

ssweber referenced this issue Apr 18, 2023
I think this gets us almost all the way there.

in insert_row, setting the idx is not implemented yet

Also, ruff is complaining about:
F405: 'ResultSet' may be undefined ... but I didn't know what to replace that with.
@ssweber
Copy link
Collaborator

ssweber commented Apr 18, 2023

Per above commit, things I didn’t know how to handle:

  1. in insert_row, setting the idx is not implemented yet
  2. Also, ruff is complaining about:
    F405: 'ResultSet' may be undefined ... but I didn't know what to replace that with. Result, or pd.Dataframe?

@ssweber
Copy link
Collaborator

ssweber commented Apr 18, 2023

  • Need to check if execute exceptions work.

thanks for letting me mop the new floors you put in 😄

@PySimpleSQL
Copy link
Owner Author

Thanks! Sorry for leaving things in such an unfinished state - i was supposed to have a nice block of time that fell to pieces on me unfortunately (i worked at 20 hour day yesterday).

I just pulled your changes in and going to give things a whirl to see where everything stands.

I know this has been a giant pain, but having pandas support will be a huge feature. It can be a pain to use for simple things, but it has so much power for manipulating and accessing data!

PySimpleSQL added a commit that referenced this issue Apr 18, 2023
Cleaned up a lot of the ResultSet references that are no longer valid now that we are working with DataFrames.

Changed the set_by_pk call to update_elements, otherwise the navigation buttons don't update after sorting
PySimpleSQL added a commit that referenced this issue Apr 18, 2023
Searching for records works as expected again
PySimpleSQL added a commit that referenced this issue Apr 18, 2023
Sorting for foreign keys works again.  A temporary column is added that maps the fk to the description column of the parent table, the dataset is sorted on this temporary column, then the temporary column is dropped in place.
PySimpleSQL added a commit that referenced this issue Apr 18, 2023
Duplicating records working once again
@PySimpleSQL
Copy link
Owner Author

Made some fairly decent progress today. There are still a few oddball issues floating yet (crash when navigating away from changed record and prompting "No" for example).

Just need to find the rest of these small issues and fix them, then the last remaining task will be to update all of the drivers to work properly, using the Sqlite driver as a reference as to what has changed

@PySimpleSQL
Copy link
Owner Author

PySimpleSQL commented Apr 20, 2023 via email

PySimpleSQL added a commit that referenced this issue Apr 21, 2023
resolved a small merge conflict
PySimpleSQL added a commit that referenced this issue Apr 21, 2023
override insert_record - Jackcess does not like columns set to None
PySimpleSQL added a commit that referenced this issue Apr 21, 2023
Duplicate now mostly working (selects wrong item after duplicate still).  Had to remove quote_table stuff from the driver, as the variable is used in other places that do not expect it to be quoted - it's not needed anyway, as this is specific driver code and not generalized for all SQLDrivers
@ssweber
Copy link
Collaborator

ssweber commented Apr 21, 2023

BTW - I just tested Mysql example on development, and duplicate didn't jump to the right record afterwords there either. So that's not a pandas-specific issue.

PySimpleSQL added a commit that referenced this issue Apr 21, 2023
Duplicate now working.  DROP TABLE IF EXISTS does not seem to work reliably through Jackcess, so added a workaround.  The lastrowid was not being returned due to the nature of the executing a list of queries, so grabbed the inserted id after all of the queries were finished.
@PySimpleSQL
Copy link
Owner Author

PySimpleSQL commented Apr 21, 2023 via email

PySimpleSQL added a commit that referenced this issue Apr 21, 2023
Small fixes / ruff fixes
ssweber added a commit that referenced this issue Apr 22, 2023
commit 35f8bf3
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 21 11:36:03 2023 -0400

    Fixes lastrowid not being returned correctly in duplicate

    Old code was trying to get the lastrowid after the entire list of queries ran, which would return None due to the insert being buried in the list of queries.  We now grab it after the insert runs by chacking if it has been set yet, and if the result has a lastrowid

commit 9628f65
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 21 11:29:31 2023 -0400

    refs #281 MSAccess fixes

    Small fixes / ruff fixes

commit 3f24c38
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 21 11:23:28 2023 -0400

    refs #281 MSAccess fixes

    Duplicate now working.  DROP TABLE IF EXISTS does not seem to work reliably through Jackcess, so added a workaround.  The lastrowid was not being returned due to the nature of the executing a list of queries, so grabbed the inserted id after all of the queries were finished.

commit f904950
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 21 10:26:48 2023 -0400

    refs #281 MSAccess fixes

    Duplicate now mostly working (selects wrong item after duplicate still).  Had to remove quote_table stuff from the driver, as the variable is used in other places that do not expect it to be quoted - it's not needed anyway, as this is specific driver code and not generalized for all SQLDrivers

commit c53caa7
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 21 09:39:31 2023 -0400

    refs #281 MSAccess fixes

    override insert_record - Jackcess does not like columns set to None

commit 2179061
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 21 09:26:28 2023 -0400

    refs #281 Pandas integration

    resolved a small merge conflict

commit 3ff3385
Author: PySimpleSQL <[email protected]>
Date:   Thu Apr 20 15:58:42 2023 -0400

    refs #281, Got a little bit of MSAccess working

    Duplicate still broken.  Out of time to look at it for now

commit fc134c3
Merge: 87e9fac 456c5a7
Author: PySimpleSQL <[email protected]>
Date:   Thu Apr 20 15:58:29 2023 -0400

    Merge remote-tracking branch 'origin/pandas' into pandas

    # Conflicts:
    #	pysimplesql/pysimplesql.py

commit 87e9fac
Author: PySimpleSQL <[email protected]>
Date:   Thu Apr 20 15:55:12 2023 -0400

    refs #281, Got a little bit of MSAccess working

    Duplicate still broken.  Out of time to look at it for now

commit 456c5a7
Author: ssweber <[email protected]>
Date:   Thu Apr 20 15:48:17 2023 -0400

    black

commit 3c78b07
Author: ssweber <[email protected]>
Date:   Thu Apr 20 15:47:51 2023 -0400

    Sqlserver conversions

    still need to do sqlserver pk_column... didn't have time to start up docker to test how that get returned

commit a465cd4
Author: ssweber <[email protected]>
Date:   Thu Apr 20 15:43:42 2023 -0400

    More Result.set conversions

    Access has issue with save and duplicate

commit 204842b
Author: PySimpleSQL <[email protected]>
Date:   Thu Apr 20 11:46:07 2023 -0400

    refs #281, Flatfile fixes

    Small fixes to Flatfile driver to work with pandas

commit 2030c32
Author: ssweber <[email protected]>
Date:   Wed Apr 19 16:15:07 2023 -0400

    Safeguard error if query somehow fails

commit e5e1918
Author: ssweber <[email protected]>
Date:   Wed Apr 19 15:39:32 2023 -0400

    Reverting line change

    I think both work correctly, so I'll just keep the one you wrote :)

commit 10427c8
Author: ssweber <[email protected]>
Date:   Wed Apr 19 15:16:26 2023 -0400

    Working mysql/postgres sql drivers

    Also fixed duplicate button always disabled
    Found other places where we needed to look at attrs instead of result.exception

commit 9d86d1b
Author: ssweber <[email protected]>
Date:   Wed Apr 19 13:54:40 2023 -0400

    Update pysimplesql.py

commit b7db10f
Author: ssweber <[email protected]>
Date:   Wed Apr 19 13:53:33 2023 -0400

    Fix for quick_editor, save_record

    Now with updated sqlite driver, this needed to update attrs

commit f26c5b4
Author: ssweber <[email protected]>
Date:   Tue Apr 18 16:47:03 2023 -0400

    Fixed checking for TableHeading

    I think this fixes the quick-editor

commit 6a256a3
Author: ssweber <[email protected]>
Date:   Tue Apr 18 16:23:23 2023 -0400

    Update pysimplesql.py

commit 454a766
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 15:25:14 2023 -0400

    refs #281, set_by_pk improvements

    There were certain situations where set_by_pk would fail if the primary key was not found (like after deleting a virtual record.).  This ensures that an index will be selected even if the pk value is not found

commit 7f159d8
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 15:18:35 2023 -0400

    refs #281, set_by_pk improvements

    There were certain situations where set_by_pk would fail if the primary key was not found (like after deleting a virtual record.).  This ensures that an index will be selected even if the pk value is not found

commit b84643d
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 14:34:25 2023 -0400

    refs #281, Purge virtual working

    DataSet.purge_virtual is now working.  Also added some pandas display options for easier debugging

commit 3ebcd20
Merge: 149bdc7 749c717
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 12:49:42 2023 -0400

    Merge pull request #288

    Moved things from _SortCallbackWrapper to sort

commit 149bdc7
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 12:47:36 2023 -0400

    refs #281, Duplicate record working

     oops, forgot something

commit 749c717
Author: ssweber <[email protected]>
Date:   Tue Apr 18 12:31:24 2023 -0400

    Update pysimplesql.py

commit db4030d
Author: ssweber <[email protected]>
Date:   Tue Apr 18 12:28:07 2023 -0400

    Update pysimplesql.py

commit aa7c8ac
Author: ssweber <[email protected]>
Date:   Tue Apr 18 12:27:04 2023 -0400

    Move from _SortCallbackWrapper to sort

commit 32266f1
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 12:20:38 2023 -0400

    refs #281, Duplicate record working

    Duplicating records working once again

commit 28118ed
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 12:04:34 2023 -0400

    refs #281, Sorting by foreign keys

    Sorting for foreign keys works again.  A temporary column is added that maps the fk to the description column of the parent table, the dataset is sorted on this temporary column, then the temporary column is dropped in place.

commit caa0754
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 11:03:10 2023 -0400

    refs #281, Record search working again

    Searching for records works as expected again

commit ccabe70
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 10:01:56 2023 -0400

    refs #281, Pandas more cleanup

    Cleaned up a lot of the ResultSet references that are no longer valid now that we are working with DataFrames.

    Changed the set_by_pk call to update_elements, otherwise the navigation buttons don't update after sorting

commit 25e5495
Author: ssweber <[email protected]>
Date:   Tue Apr 18 00:19:37 2023 -0400

    fixes navigation buttons being wrong

commit b7f7051
Author: ssweber <[email protected]>
Date:   Tue Apr 18 00:09:37 2023 -0400

    Lots of fixes

    I think this gets us almost all the way there.

    in insert_row, setting the idx is not implemented yet

    Also, ruff is complaining about:
    F405: 'ResultSet' may be undefined ... but I didn't know what to replace that with.

commit a9928e5
Author: ssweber <[email protected]>
Date:   Mon Apr 17 20:36:40 2023 -0400

    small fix

    you're right, somethings still borked with sorting.

    sorry, this at least gets it in a workable state.

commit 50e7430
Author: ssweber <[email protected]>
Date:   Mon Apr 17 17:08:48 2023 -0400

    fixes

commit 76b4835
Author: PySimpleSQL <[email protected]>
Date:   Mon Apr 17 15:48:42 2023 -0400

    refs #281, Pandas partially working

    Pretty big step backwards with this one. Working on cleaning up the sorting code had some unexpected consequences.  I'm out of time for a while, so checking this in for now

commit 0a77f5e
Author: PySimpleSQL <[email protected]>
Date:   Mon Apr 17 12:43:31 2023 -0400

    refs #281, Pandas partially working

    Sorting code working.  Still need to work out how to sort FK relationships by their description column

commit e3e50eb
Author: PySimpleSQL <[email protected]>
Date:   Mon Apr 17 11:04:31 2023 -0400

    refs #281, Pandas partially working

    Sorting code moved into DataSet.  Still some work to do, but very close to being functional again

commit a529690
Author: PySimpleSQL <[email protected]>
Date:   Mon Apr 17 08:09:36 2023 -0400

    refs #281, Pandas partially working

    Worked towards getting rid of ResultSet entirely and having SQLDriver.execute() returning DataFrames directly with the appropriate attrs set

commit c6a8983
Author: PySimpleSQL <[email protected]>
Date:   Sun Apr 16 19:30:53 2023 -0400

    refs #281 Pandas integration

    A little closer now.  New records insert and mark as virtual.  There was an issue with using .applymap on DataSet.rows, as .applymap returns a Dataset object directly, which was overwriting the ResultSet object.  This fixes that issue.

    Still more to go, but another step closer

commit 0cb39be
Author: ssweber <[email protected]>
Date:   Sun Apr 16 15:12:18 2023 -0400

    Properly insert series back into dataframe

    This fixes it adding that extra column.

commit d1f11bd
Author: PySimpleSQL <[email protected]>
Date:   Sun Apr 16 08:15:41 2023 -0400

    refs #281, Pandas partially working

    More cleanup and experimentation.  There is an issue with saving where sometimes the dict gets an extra key "0" and the update query fails.  Also, even at times that the query goes through, the DataSet does not seem to update immediately to show the difference

commit 0cc1f13
Author: PySimpleSQL <[email protected]>
Date:   Sat Apr 15 20:09:17 2023 -0400

    refs #281, Pandas partially working

    More cleanup

commit bf017ab
Author: PySimpleSQL <[email protected]>
Date:   Sat Apr 15 18:02:33 2023 -0400

    refs #281, Pandas partially working

    Lots of cleanup to do yet!

commit 97e3686
Author: PySimpleSQL <[email protected]>
Date:   Sat Apr 15 16:00:21 2023 -0400

    refs #281, getting a start on converting over to Pandas for ResultSets

    more conversions

commit e9e9190
Merge: 70171b6 dedb62a
Author: PySimpleSQL <[email protected]>
Date:   Sat Apr 15 15:07:02 2023 -0400

    Merge branch 'pytest' into pandas

commit dedb62a
Merge: d494d67 d29cfc0
Author: PySimpleSQL <[email protected]>
Date:   Sat Apr 15 15:05:30 2023 -0400

    Merge branch 'development' into pytest

    # Conflicts:
    #	pysimplesql/pysimplesql.py

commit 70171b6
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 04:25:15 2023 -0400

    refs #281, getting a start on converting over to Pandas for ResultSets

    Got it pretty close to working (at least for the sqlite driver).  More debugging and troubleshooting to go!

commit d494d67
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 01:47:23 2023 -0400

    refs #278 fix ruff errors

    adding # ruff: noqa to test files

commit cfd3fd7
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 01:38:08 2023 -0400

    refs #278 fix ruff error

    Ignore another SIM102 error.  This one would be much messier to combine the if statements.

    Looks like the .ruffignore is not working either!

commit f66000c
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 01:35:41 2023 -0400

    refs #278 fix ruff error

    Ignore another SIM102 error.  This one would be much messier to combine the if statements.

    Looks like the .ruggignore is not working either!

commit d504891
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 01:31:29 2023 -0400

    refs #278 fix ruff error

    Fixed a SIM102 error flagged by ruff.  This commit should also test if the .ruffignore file is working...

commit 8191b8f
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 01:25:21 2023 -0400

    refs #278 Unit Tests ruff ignore

    add a .ruffignore file to ignore the /tests folder

commit 61fc8ec
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 01:21:17 2023 -0400

    refs #278 Unit Test example for ProgressAnimate

    Finished up ProgressAnimate testing file along with improvments to bulletproof ProgressAnimate

commit 7a97927
Merge: 65239d9 2d6938f
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 00:23:56 2023 -0400

    refs #278 Unit Test example for ProgressAnimate

    Not perfect yet, but shows the basic concepts of testing for both no failures and expected failures.  I tried to fix things in ProgressAnimate as I went along so that hopefully you can see the correlation between what was being tested, and the fixes that went in to pass the tests.

    If you haven't used pytest before, there's a few things to do:
    - pip install pytest
    - make sure pysimplesql is reachable as a module.  The easiest way is to do a local installation by running `pip -e .` in the pysimplesql root directory
    - from the commandline, run `pytest` to run all tests.  Or you can run tests for a specific file, I.e. `pytest progressanimate_test.py`
ssweber added a commit that referenced this issue Apr 25, 2023
commit 35f8bf3
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 21 11:36:03 2023 -0400

    Fixes lastrowid not being returned correctly in duplicate

    Old code was trying to get the lastrowid after the entire list of queries ran, which would return None due to the insert being buried in the list of queries.  We now grab it after the insert runs by chacking if it has been set yet, and if the result has a lastrowid

commit 9628f65
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 21 11:29:31 2023 -0400

    refs #281 MSAccess fixes

    Small fixes / ruff fixes

commit 3f24c38
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 21 11:23:28 2023 -0400

    refs #281 MSAccess fixes

    Duplicate now working.  DROP TABLE IF EXISTS does not seem to work reliably through Jackcess, so added a workaround.  The lastrowid was not being returned due to the nature of the executing a list of queries, so grabbed the inserted id after all of the queries were finished.

commit f904950
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 21 10:26:48 2023 -0400

    refs #281 MSAccess fixes

    Duplicate now mostly working (selects wrong item after duplicate still).  Had to remove quote_table stuff from the driver, as the variable is used in other places that do not expect it to be quoted - it's not needed anyway, as this is specific driver code and not generalized for all SQLDrivers

commit c53caa7
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 21 09:39:31 2023 -0400

    refs #281 MSAccess fixes

    override insert_record - Jackcess does not like columns set to None

commit 2179061
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 21 09:26:28 2023 -0400

    refs #281 Pandas integration

    resolved a small merge conflict

commit 3ff3385
Author: PySimpleSQL <[email protected]>
Date:   Thu Apr 20 15:58:42 2023 -0400

    refs #281, Got a little bit of MSAccess working

    Duplicate still broken.  Out of time to look at it for now

commit fc134c3
Merge: 87e9fac 456c5a7
Author: PySimpleSQL <[email protected]>
Date:   Thu Apr 20 15:58:29 2023 -0400

    Merge remote-tracking branch 'origin/pandas' into pandas

    # Conflicts:
    #	pysimplesql/pysimplesql.py

commit 87e9fac
Author: PySimpleSQL <[email protected]>
Date:   Thu Apr 20 15:55:12 2023 -0400

    refs #281, Got a little bit of MSAccess working

    Duplicate still broken.  Out of time to look at it for now

commit 456c5a7
Author: ssweber <[email protected]>
Date:   Thu Apr 20 15:48:17 2023 -0400

    black

commit 3c78b07
Author: ssweber <[email protected]>
Date:   Thu Apr 20 15:47:51 2023 -0400

    Sqlserver conversions

    still need to do sqlserver pk_column... didn't have time to start up docker to test how that get returned

commit a465cd4
Author: ssweber <[email protected]>
Date:   Thu Apr 20 15:43:42 2023 -0400

    More Result.set conversions

    Access has issue with save and duplicate

commit 204842b
Author: PySimpleSQL <[email protected]>
Date:   Thu Apr 20 11:46:07 2023 -0400

    refs #281, Flatfile fixes

    Small fixes to Flatfile driver to work with pandas

commit 2030c32
Author: ssweber <[email protected]>
Date:   Wed Apr 19 16:15:07 2023 -0400

    Safeguard error if query somehow fails

commit e5e1918
Author: ssweber <[email protected]>
Date:   Wed Apr 19 15:39:32 2023 -0400

    Reverting line change

    I think both work correctly, so I'll just keep the one you wrote :)

commit 10427c8
Author: ssweber <[email protected]>
Date:   Wed Apr 19 15:16:26 2023 -0400

    Working mysql/postgres sql drivers

    Also fixed duplicate button always disabled
    Found other places where we needed to look at attrs instead of result.exception

commit 9d86d1b
Author: ssweber <[email protected]>
Date:   Wed Apr 19 13:54:40 2023 -0400

    Update pysimplesql.py

commit b7db10f
Author: ssweber <[email protected]>
Date:   Wed Apr 19 13:53:33 2023 -0400

    Fix for quick_editor, save_record

    Now with updated sqlite driver, this needed to update attrs

commit f26c5b4
Author: ssweber <[email protected]>
Date:   Tue Apr 18 16:47:03 2023 -0400

    Fixed checking for TableHeading

    I think this fixes the quick-editor

commit 6a256a3
Author: ssweber <[email protected]>
Date:   Tue Apr 18 16:23:23 2023 -0400

    Update pysimplesql.py

commit 454a766
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 15:25:14 2023 -0400

    refs #281, set_by_pk improvements

    There were certain situations where set_by_pk would fail if the primary key was not found (like after deleting a virtual record.).  This ensures that an index will be selected even if the pk value is not found

commit 7f159d8
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 15:18:35 2023 -0400

    refs #281, set_by_pk improvements

    There were certain situations where set_by_pk would fail if the primary key was not found (like after deleting a virtual record.).  This ensures that an index will be selected even if the pk value is not found

commit b84643d
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 14:34:25 2023 -0400

    refs #281, Purge virtual working

    DataSet.purge_virtual is now working.  Also added some pandas display options for easier debugging

commit 3ebcd20
Merge: 149bdc7 749c717
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 12:49:42 2023 -0400

    Merge pull request #288

    Moved things from _SortCallbackWrapper to sort

commit 149bdc7
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 12:47:36 2023 -0400

    refs #281, Duplicate record working

     oops, forgot something

commit 749c717
Author: ssweber <[email protected]>
Date:   Tue Apr 18 12:31:24 2023 -0400

    Update pysimplesql.py

commit db4030d
Author: ssweber <[email protected]>
Date:   Tue Apr 18 12:28:07 2023 -0400

    Update pysimplesql.py

commit aa7c8ac
Author: ssweber <[email protected]>
Date:   Tue Apr 18 12:27:04 2023 -0400

    Move from _SortCallbackWrapper to sort

commit 32266f1
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 12:20:38 2023 -0400

    refs #281, Duplicate record working

    Duplicating records working once again

commit 28118ed
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 12:04:34 2023 -0400

    refs #281, Sorting by foreign keys

    Sorting for foreign keys works again.  A temporary column is added that maps the fk to the description column of the parent table, the dataset is sorted on this temporary column, then the temporary column is dropped in place.

commit caa0754
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 11:03:10 2023 -0400

    refs #281, Record search working again

    Searching for records works as expected again

commit ccabe70
Author: PySimpleSQL <[email protected]>
Date:   Tue Apr 18 10:01:56 2023 -0400

    refs #281, Pandas more cleanup

    Cleaned up a lot of the ResultSet references that are no longer valid now that we are working with DataFrames.

    Changed the set_by_pk call to update_elements, otherwise the navigation buttons don't update after sorting

commit 25e5495
Author: ssweber <[email protected]>
Date:   Tue Apr 18 00:19:37 2023 -0400

    fixes navigation buttons being wrong

commit b7f7051
Author: ssweber <[email protected]>
Date:   Tue Apr 18 00:09:37 2023 -0400

    Lots of fixes

    I think this gets us almost all the way there.

    in insert_row, setting the idx is not implemented yet

    Also, ruff is complaining about:
    F405: 'ResultSet' may be undefined ... but I didn't know what to replace that with.

commit a9928e5
Author: ssweber <[email protected]>
Date:   Mon Apr 17 20:36:40 2023 -0400

    small fix

    you're right, somethings still borked with sorting.

    sorry, this at least gets it in a workable state.

commit 50e7430
Author: ssweber <[email protected]>
Date:   Mon Apr 17 17:08:48 2023 -0400

    fixes

commit 76b4835
Author: PySimpleSQL <[email protected]>
Date:   Mon Apr 17 15:48:42 2023 -0400

    refs #281, Pandas partially working

    Pretty big step backwards with this one. Working on cleaning up the sorting code had some unexpected consequences.  I'm out of time for a while, so checking this in for now

commit 0a77f5e
Author: PySimpleSQL <[email protected]>
Date:   Mon Apr 17 12:43:31 2023 -0400

    refs #281, Pandas partially working

    Sorting code working.  Still need to work out how to sort FK relationships by their description column

commit e3e50eb
Author: PySimpleSQL <[email protected]>
Date:   Mon Apr 17 11:04:31 2023 -0400

    refs #281, Pandas partially working

    Sorting code moved into DataSet.  Still some work to do, but very close to being functional again

commit a529690
Author: PySimpleSQL <[email protected]>
Date:   Mon Apr 17 08:09:36 2023 -0400

    refs #281, Pandas partially working

    Worked towards getting rid of ResultSet entirely and having SQLDriver.execute() returning DataFrames directly with the appropriate attrs set

commit c6a8983
Author: PySimpleSQL <[email protected]>
Date:   Sun Apr 16 19:30:53 2023 -0400

    refs #281 Pandas integration

    A little closer now.  New records insert and mark as virtual.  There was an issue with using .applymap on DataSet.rows, as .applymap returns a Dataset object directly, which was overwriting the ResultSet object.  This fixes that issue.

    Still more to go, but another step closer

commit 0cb39be
Author: ssweber <[email protected]>
Date:   Sun Apr 16 15:12:18 2023 -0400

    Properly insert series back into dataframe

    This fixes it adding that extra column.

commit d1f11bd
Author: PySimpleSQL <[email protected]>
Date:   Sun Apr 16 08:15:41 2023 -0400

    refs #281, Pandas partially working

    More cleanup and experimentation.  There is an issue with saving where sometimes the dict gets an extra key "0" and the update query fails.  Also, even at times that the query goes through, the DataSet does not seem to update immediately to show the difference

commit 0cc1f13
Author: PySimpleSQL <[email protected]>
Date:   Sat Apr 15 20:09:17 2023 -0400

    refs #281, Pandas partially working

    More cleanup

commit bf017ab
Author: PySimpleSQL <[email protected]>
Date:   Sat Apr 15 18:02:33 2023 -0400

    refs #281, Pandas partially working

    Lots of cleanup to do yet!

commit 97e3686
Author: PySimpleSQL <[email protected]>
Date:   Sat Apr 15 16:00:21 2023 -0400

    refs #281, getting a start on converting over to Pandas for ResultSets

    more conversions

commit e9e9190
Merge: 70171b6 dedb62a
Author: PySimpleSQL <[email protected]>
Date:   Sat Apr 15 15:07:02 2023 -0400

    Merge branch 'pytest' into pandas

commit dedb62a
Merge: d494d67 d29cfc0
Author: PySimpleSQL <[email protected]>
Date:   Sat Apr 15 15:05:30 2023 -0400

    Merge branch 'development' into pytest

    # Conflicts:
    #	pysimplesql/pysimplesql.py

commit 70171b6
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 04:25:15 2023 -0400

    refs #281, getting a start on converting over to Pandas for ResultSets

    Got it pretty close to working (at least for the sqlite driver).  More debugging and troubleshooting to go!

commit d494d67
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 01:47:23 2023 -0400

    refs #278 fix ruff errors

    adding # ruff: noqa to test files

commit cfd3fd7
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 01:38:08 2023 -0400

    refs #278 fix ruff error

    Ignore another SIM102 error.  This one would be much messier to combine the if statements.

    Looks like the .ruffignore is not working either!

commit f66000c
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 01:35:41 2023 -0400

    refs #278 fix ruff error

    Ignore another SIM102 error.  This one would be much messier to combine the if statements.

    Looks like the .ruggignore is not working either!

commit d504891
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 01:31:29 2023 -0400

    refs #278 fix ruff error

    Fixed a SIM102 error flagged by ruff.  This commit should also test if the .ruffignore file is working...

commit 8191b8f
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 01:25:21 2023 -0400

    refs #278 Unit Tests ruff ignore

    add a .ruffignore file to ignore the /tests folder

commit 61fc8ec
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 01:21:17 2023 -0400

    refs #278 Unit Test example for ProgressAnimate

    Finished up ProgressAnimate testing file along with improvments to bulletproof ProgressAnimate

commit 7a97927
Merge: 65239d9 2d6938f
Author: PySimpleSQL <[email protected]>
Date:   Fri Apr 14 00:23:56 2023 -0400

    refs #278 Unit Test example for ProgressAnimate

    Not perfect yet, but shows the basic concepts of testing for both no failures and expected failures.  I tried to fix things in ProgressAnimate as I went along so that hopefully you can see the correlation between what was being tested, and the fixes that went in to pass the tests.

    If you haven't used pytest before, there's a few things to do:
    - pip install pytest
    - make sure pysimplesql is reachable as a module.  The easiest way is to do a local installation by running `pip -e .` in the pysimplesql root directory
    - from the commandline, run `pytest` to run all tests.  Or you can run tests for a specific file, I.e. `pytest progressanimate_test.py`
@ssweber
Copy link
Collaborator

ssweber commented Apr 26, 2023

I checked all the sql drivers. The only issues I saw revolves around duplicate... either not jumping to the correct row, or like sqlserver, which needs a duplicate rewrite. Maybe there's a more database-agnostic way to accomplish this than the the hack I found on stackoverflow.

At any rate, all the duplicate problems existed before pandas. So I'm cool if you want to merge this back in!

@ssweber
Copy link
Collaborator

ssweber commented Apr 26, 2023

Chatgpt and I rewrote duplicate. I realized columninfo had all the information I needed!

I’ll go back and comment more, but this avoids all the silliness of temp-tables.

it’s now working on sqlserver. I’ll double-check MySQL and Postgres.

Maybe we don’t need a separate one for msaccess?

ssweber referenced this issue Apr 26, 2023
Waaaaaay better. Now sqlserver works.
@PySimpleSQL
Copy link
Owner Author

PySimpleSQL commented Apr 26, 2023 via email

@ssweber
Copy link
Collaborator

ssweber commented Apr 27, 2023

Yeah, hopefully this is more general-purposed.

It uses Dataset.column_info to select all the columns except the pk_column and copies the row right in the same table.

for children, it again uses column_info, but importantly, when selecting columns, sets the fk_column to equal the new parent pk before inserting.

no create/drop necessary :)

———-

it’s been a real pleasure this last week discovering and using some of the gems 💎 you have written. I used column_info to infer checkboxes, and ElementRow for combobox es in the CellEdit logic.

@PySimpleSQL
Copy link
Owner Author

PySimpleSQL commented Apr 27, 2023 via email

ssweber referenced this issue Apr 27, 2023
I hope this looks good to you. Now completely functional on all sqldrivers, and they select the correct pk afterwords!

Since sqlserver and msaccess only needed minor changes, I split out into functions:

get_duplicate_parent_query(self, table, columns, pk_column, current_pk)

get_duplicate_parent_new_pk(self, res, pk_column)
@ssweber
Copy link
Collaborator

ssweber commented Apr 27, 2023

I cleaned that up and tested on all sqldrivers. Works perfectly. I hope it looks OK to you.

Is there anything left for us to do before merging pandas in?

@PySimpleSQL
Copy link
Owner Author

PySimpleSQL commented Apr 27, 2023 via email

@ssweber
Copy link
Collaborator

ssweber commented Apr 27, 2023

I may not understand this well. Are you considering set_index the pk_column? Then iloc[1] would grab the pk=1

i think that removing the auto-created index would be a plus, and more expected.

@PySimpleSQL
Copy link
Owner Author

PySimpleSQL commented Apr 27, 2023 via email

@ssweber
Copy link
Collaborator

ssweber commented Apr 27, 2023

I'll have to see what you mean to understand 😅 But you're typically have a good feel for these things!

@ssweber
Copy link
Collaborator

ssweber commented Apr 27, 2023

Is it worth merging in as-is (it's at a high-level of functionality now) and then working on the iloc to .index transition in a pandas.index branch?

That way I can rebase _EditCell on development, there are a few rough edges on it yet.

@ssweber
Copy link
Collaborator

ssweber commented Apr 27, 2023

Actually, disregard previous. Take your time thinking about it - enjoy your trip.

This isn't holding me up smoothing out _EditCell (I need to stop procrastinating with my actual day-job work!)

@PySimpleSQL
Copy link
Owner Author

PySimpleSQL commented Apr 27, 2023 via email

@ssweber
Copy link
Collaborator

ssweber commented Apr 27, 2023

#297

alright!

@ssweber ssweber closed this as completed Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants