GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat: adds condition class and assoc. unit tests by chalmerlowe · Pull Request #2159 · googleapis/python-bigquery
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
Conversation
Linchin
reviewed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for my education, why is
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both Despite the fact that we indicate via typehinting:
neither It is not inherently clear why they believe our typehinting for There are approximately seven similar examples of this problem elsewhere in this file (that predate my taking over the repo) (and there are examples in other files in this codebase). These are the error messages we see: mypypytype
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Linchin
reviewed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not very familiar with Condition, do we need to distinguish between title and description being not set versus being an empty string?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
|
|
||
| def to_api_repr(self) -> Dict[str, Any]: | ||
| """Construct the API resource representation of this Condition.""" | ||
| return self._properties |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We might want to make a deep copy of the dict, similar to other classes, such as Table.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Unless we have a compelling reason to use deepcopy, I am disinclined. Thoughts?
In a previous experimental PR, Tim left a comment about some of the pitfalls of using deep copy, if not necessary.
It might be a bit wasteful to make deepcopy here and in `from_api_repr`. Indeed it's safer, but could add a lot of overhead. IIRC we actually removed some `deepcopy` calls from `SchemaField` because it was slowing down customers who build dynamic schemas in their code.
In all cases we are returning a dict (thus there should not be a significant risk of some underlying nested value being changed by another expression in the code)
I was curious about the overall cost of a deepcopy so I did a fairly simple experiment:
In [1]: import copy
In [2]: api_repr = {
...: "expression": "some_value",
...: "title": "some_value",
...: "unexpected_field": "some_value",
...: }
In [3]: _properties['condition'] = api_repr
From fastest to slowest:
In [4]: %timeit new_prop = _properties
14.4 ns ± 0.0149 ns per loop (mean ± std. dev. of 7 runs, 100,000,000 loops each)
# NOTE: when we use `return _properties`, it is the same as using an alias.
This creates a shallow copy of the dict
In [11]: %timeit new_prop = _properties.copy()
58.6 ns ± 0.228 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
This also creates a shallow copy of the dict
In [9]: %timeit new_prop = copy.copy(_properties)
145 ns ± 0.401 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [5]: %timeit new_prop = copy.deepcopy(_properties)
3 µs ± 16.7 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.