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

BUG: allow happi search to match int numerics #261

Merged
merged 3 commits into from
Jun 9, 2022

Conversation

tangkong
Copy link
Contributor

@tangkong tangkong commented Jun 8, 2022

Description

  • If search term is an int, generates regex that also matches its float counterpart

Motivation and Context

closes #256

In building tests I realized happi edit does not allow editing of extraneous information. A portion of the new test has been commented out for when that is fixed. (see #262)

How Has This Been Tested?

Test suite, interactively

Where Has This Been Documented?

This PR

image

@tangkong tangkong marked this pull request as ready for review June 8, 2022 21:22
@tangkong tangkong requested review from klauer and ZLLentz June 8, 2022 21:26
client_args[criteria] = value
continue
else:
value = str(float(value))
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't a floating point value be somewhat problematic for regex mode? The above comment and continue gave me pause to think about it a bit:

  • Say we passed in "3.14" we might match "3514" or "3x14" just the same. . would be interpreted as a regex anychar, wouldn't it?
  • Does float-based value searching also work as a full match or a partial match? That is, if 12345.678 is in the database and I search for 5.678 what happens? (lazy question...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are good points.

  • I think you're right, ints will always get an escaped ., but floats will get passed through as is. Is this a problem though? We could argue if someone is searching in regex mode they should be escaping their . if they need to?
  • The float-based value searching seems to not work with partial matches, though I didn't do that intentionally.

Copy link
Contributor

@klauer klauer Jun 8, 2022

Choose a reason for hiding this comment

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

We could argue if someone is searching in regex mode they should be escaping their . if they need to?

If someone is doing a regex search with a thing that looks like a floating point value... is it a floating point value or a regex?

... I think it's a regex and probably shouldn't go through the float(str(float)) conversion? 🤷

Is this a problem though?

Likely not - just trying to dig into the implications of the changes in my usual excessive way 😁

Copy link
Member

@ZLLentz ZLLentz Jun 8, 2022

Choose a reason for hiding this comment

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

I think this is an annoyance with using regex in general to search for floating point numbers rather than a unique problem to happi

Float-based values not partial matching almost seems like a feature rather than a bug...

Copy link
Member

Choose a reason for hiding this comment

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

That's a good point about the processing of regex, Ken

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Likely not - just trying to dig into the implications of the changes in my usual excessive way 😁

I don't think it's excessive, it's just thorough 😄

Float-based values not partial matching almost seems like a feature rather than a bug...

I wish I could claim credit for that haha

if float(value) == int(float(value)):
# value is an int, allow the float version (optional .0)
logger.debug(f'looking for int value: {value}')
value = f'^{int(float(value))}(\\.0+$)?$'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is good as you have it:

  • Requiring it to match the entire integer value - as marked by ^...$
  • With or without the trailing .0.

# float_result = runner.invoke(happi_cli, ['--path', happi_cfg,
# 'search', '--names', 'z=3.0'])
# assert int_result.output == ''
# assert float_result.output == ''
Copy link
Member

@ZLLentz ZLLentz Jun 8, 2022

Choose a reason for hiding this comment

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

👍 for leaving a test for future use
I think another way to do this is to add the test (as an independent function) and mark it as xfail

@ZLLentz
Copy link
Member

ZLLentz commented Jun 8, 2022

The screenshot in the description above confused the heck out of me because its "after -> before" instead of "before -> after" but I caught myself before making an equally confused comment.

Copy link
Member

@ZLLentz ZLLentz left a comment

Choose a reason for hiding this comment

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

I think this is good

Copy link
Contributor

@klauer klauer left a comment

Choose a reason for hiding this comment

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

My annoying questions shouldn't hold this up. It's a net positive improvement 👍

@tangkong
Copy link
Contributor Author

tangkong commented Jun 9, 2022

I'm going to merge this, but another edge case I didn't consider is scientific notation. client.search_regex won't consider something 100 == 1e2, so we basically pray that the str(float(str)) conversion produces something that matches the database.

At this point, we're patching over an interface that really doesn't seem to handle numerics correctly. This is probably worth a deeper look, perhaps at other search methods on the backends.

@tangkong tangkong merged commit 1953c5b into pcdshub:master Jun 9, 2022
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.

Handle searching numeric values
3 participants