Conversation

jimfulton

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #628 🦕

@product-auto-labelproduct-auto-label bot added the api: bigqueryIssues related to the googleapis/python-bigquery API.label Apr 26, 2021
@google-clagoogle-cla bot added the cla: yesThis human has signed the Contributor License Agreement.label Apr 26, 2021
Jim Fulton added 2 commits April 27, 2021 07:19
Because we don't want to accidentally create a giant bytes.
if isinstance(data, int):
# This is not the conversion we're looking for, because it
# will simply create a bytes object of the given size.
raise TypeError("cannot convert 'decimal.Decimal' object to binary")
Copy link
Contributor

Choose a reason for hiding this comment

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

isinstance is checking for int, but the error says decimal.Decimal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -13,6 +13,7 @@
# limitations under the License.

import datetime
import pytest
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We usually put pytest in the second grouping of imports rather than with the built-ins. We do try to follow PEP-8 advice.

Imports should be grouped in the following order:

  1. Standard library imports.
  2. Related third party imports.
  3. Local application/library specific imports.

You should put a blank line between each group of imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


self.assertEqual(types.Binary(C()), b"Google")

for bad in 42, 42.0, None:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expect the tests for "bad inputs" to be in a separate test function.

Ideally both of these (good inputs, bad inputs) would be parameterized in pytest-style tests. I think we can actually mix those in to the same file, so we can do that without refactoring everything, especially since these tests don't require any of the setup from the unit test class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@jimfultonjimfulton marked this pull request as ready for review April 27, 2021 19:52
@jimfultonjimfulton requested review from a team and stephaniewang526 and removed request for a team April 27, 2021 19:52
@tswasttswast merged commit 4396e70 into master Apr 27, 2021
@tswasttswast deleted the riversnake-fix-628 branch April 27, 2021 20:15
gcf-merge-on-green bot pushed a commit that referenced this pull request Apr 29, 2021
Sign up for free to join this conversation on . Already have an account? Sign in to comment
api: bigqueryIssues related to the googleapis/python-bigquery API.cla: yesThis human has signed the Contributor License Agreement.
None yet

Successfully merging this pull request may close these issues.

The DB API Binary function should accept bytes.