Skip to content
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

Add count and add prefix and sufix implementation #12

Closed
wants to merge 10 commits into from

Conversation

marcosvm13
Copy link

Feature

  • Please insert link to associated issue here:

What does this change introduce?

General

  • Has an example been added to demo the new feature?
  • Have existing examples been updated or tested?
  • Have you added any new Environment Variables/Configuration Options? If yes please tick the boxes below as applicable
    • Addition to reimporter logic within src/pykx/pykx.q and src/pykx/reimporter.py
    • Have updated the src/pykx/util.py logic which is used for environment variable
  • If there have been any dependency updates have they been reflected in all files?
    • pyproject.toml
    • docs/getting-started/installing.md
    • conda-recipe/meta.yaml
    • README.md
  • If any examples have been updated has it's associated .zip been updated

Code

  • Has all temporary code used during development been removed?
  • Has all commented out (unused) code been removed?
  • Where reasonable have you ensured there is no duplication of existing code?
  • If applicable for your use-case have you ensured that the code is performant?

Testing

  • Have unit tests been created or existing ones updated to test this new functionality?

Documentation

  • Has documentation been added for all public code?
  • Has a release note been included for the new feature?
  • Has any documentation which would benefit from this feature been updated to use the most up to date functionality?
  • If a new class has been added has a documentation stub .md file associated with it been created?
  • If any documentation page has been created has it been added to mkdocs.yml
  • Have you checked your changes with a spell checker? (US English)

@github-actions github-actions bot added documentation Improvements or additions to documentation python tests labels Dec 18, 2023
tests/test_pandas_api.py Outdated Show resolved Hide resolved
pcount = df.count(axis=1)

print(pcount)
assert int(qcount[0]) == int(pcount[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we fully compare qcount and pcount instead of just checking the very first index?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the reason we have to decouple pandas cases and q: In accordance with the correspondence between q nulls and Python nulls established in the .pd conversion, the empty string is regarded as a null value for columns of type symbol.


print(pcount)
assert int(qcount[0]) == int(pcount[0])
assert int(qcount[1]) == 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this adds value, since I think it's ok to assume that the pandas implementation is correct.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as before, in the case of symbols we have to write the case by hand because the conversion is not done automatically. I could create an equivalent Pandas table and not use the automatic switch from Pandas to pykx. But perhaps this way the special case becomes clearer. What you prefer.

qcount = tab.count().py()
pcount = df.count()

assert int(qcount["k1"]) == int(pcount["k1"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why not checking the output for both columns k1 and k2?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k2 is not numeric. In this case we could try to test the two objects. But count is a series object (a column table) and the translation does not seem direct to pykx

pcount = df.count()

assert int(qcount["k1"]) == int(pcount["k1"])
assert int(qcount["k2"]) == 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to a previous comment, is this really adding value to the test?

tests/test_pandas_api.py Outdated Show resolved Hide resolved
tests/test_pandas_api.py Show resolved Hide resolved
@@ -2029,3 +2029,136 @@ def test_keyed_loc_fixes(q):
mkt[['k1', 'y']]
with pytest.raises(KeyError):
mkt['k1']


def test_pandas_count(q):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should supply a case where the numeric_only flag is enabled.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a case where numeric_only is added

tests/test_pandas_api.py Show resolved Hide resolved
assert np.isnan(p_m[c]) == np.isnan(q_m[c].py())

q['tab'] = kx.toq(df)
tab = q('1!`idx xcols update idx: til count tab from tab')
Copy link
Member

@neutropolis neutropolis Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tab = q('1!`idx xcols update idx: til count tab from tab')
tab = q('`idx xkey update idx:i from tab')

chraberturas pushed a commit that referenced this pull request Jan 16, 2024
Addition of sensible default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation python tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants