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

Resolves issue #179 (https://github.com/alimanfoo/petl/issues/179): sear... #274

Merged
merged 4 commits into from
Jul 30, 2014

Conversation

rogerkwoodley
Copy link
Contributor

Travis tests passed

search complement

searchcomplement() function has been added. For code reusability and to implicitly ensure that the function is the complement of search, the implementation is wrapper of search(), and search() has been extended to allow for complement behavior.

search() (and related views and iterator functions) now includes a 'complement_flag' boolean (default=False). This yields the existing functionality (confirmed with existing unittests).

When complement_flag=True, the iterator function now yields rows that fail the test() lambda function

Docstring modified to describe functionality, mirroring the docstring for search()

unittest added: petl.test.transform.text_regex.test_searchcomplement()

…lement

searchcomplement() function has been added.  For code reusability and to implicitly ensure that the function is the complement of search, the implementation is wrapper of search(), and search() has been extended to allow for complement behavior.

search() (and related views and iterator functions) now includes a 'complement_flag' boolean (default=False).  This yields the existing functionality (confirmed with existing unittests).

When complement_flag=True, the iterator function now yields rows that fail the test() lambda function

Docstring modified to describe functionality, mirroring the docstring for search()

unittest added: petl.test.transform.text_regex.test_searchcomplement()
@alimanfoo
Copy link
Collaborator

Hi Roger, implementation looks good, I'm just thinking about API consistency.

There is a parallel with the petl.select() function, which accepts a "complement" keyword argument. For consistency I suggest renaming the new search "complement_flag" keyword argument to just "complement".

I'm also now wondering in hindsight whether it's worth having a searchcomplement() function at all, as it doesn't add much convenience over calling search(..., complement=True). I don't feel strongly about it, but I could easily live without searchcomplement(), and moving the nice examples from the docstring you created into the existing docstring for search() to describe the behaviour of the "complement" keyword argument.

@rogerkwoodley
Copy link
Contributor Author

I considered the search(..., complement=True) option - it's definitely easy enough to expose either/or/both.

From a consistency perspective, I can see it both ways. I couldn't find an analogous situation in the existing codebase, so we're venturing into new territory a bit :-).

There's already complement(), hashcomplement(), and recordcomplement(). While those are using the term in the more specific set theory concept of the word, there's some consistency in having searchcomplement() as a name.

Specifying it as an optional argument to search() might seem out of place - return X OR return ~X.

I modified the docstring to link between the two :func:, which will hopefully aid the documentation

@@ -293,11 +293,16 @@ def search(table, *args, **kwargs):
| 'mango' | 42 | 'I like them' |
+----------+-------+--------------------------+

The complement of search() (i.e., the rose not found via search())
Copy link
Collaborator

Choose a reason for hiding this comment

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

That which by any other name would smell just as sweet :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah, don't know what I was thinking there

@alimanfoo
Copy link
Collaborator

Thanks Roger, minor slip in the docstring, otherwise looks good to go.

Fixed docstring - although "data rose" sounds like something I should buy my wife, we're actually referring to "data rows" here.
@rogerkwoodley
Copy link
Contributor Author

The last you'll see of the "data rose" : @}-,-`-

alimanfoo added a commit that referenced this pull request Jul 30, 2014
@alimanfoo alimanfoo merged commit 7201b9b into petl-developers:master Jul 30, 2014
@alimanfoo alimanfoo added this to the 0.25 milestone Jul 30, 2014
@alimanfoo
Copy link
Collaborator

I know a bank where the wild thyme blows,
Where oxlips and the nodding violet grows,
Quite over-canopied with luscious woodbine,
With sweet musk-roses and with eglantine:
There sleeps Titania sometime of the night,
Lull'd in these flowers with dances and delight.

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

Successfully merging this pull request may close these issues.

2 participants