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

DM-33478: Try to speed up PropertySet on macOS ARM #73

Merged
merged 5 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: lint

on:
- push
- pull_request
push:
branches:
- main
pull_request:

jobs:
lint:
Expand All @@ -13,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.8

- name: Install
run: pip install -r <(curl https://raw.githubusercontent.com/lsst/linting/main/requirements.txt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
__all__ = ["getPropertySetState", "getPropertyListState", "setPropertySetState", "setPropertyListState"]

import enum
import math
import numbers
import dataclasses
from collections.abc import Mapping, KeysView, ValuesView, ItemsView
Expand All @@ -37,6 +38,16 @@
from .propertyList import PropertyList
from ..dateTime import DateTime

# Map the type names to the internal type representation.
_TYPE_MAP = {}
for checkType in ("Bool", "Short", "Int", "Long", "LongLong", "UnsignedLongLong",
"Float", "Double", "String", "DateTime",
"PropertySet", "Undef"):
type_obj = getattr(PropertySet, "TYPE_" + checkType)
_TYPE_MAP[type_obj] = checkType
# Store both directions.
_TYPE_MAP[checkType] = type_obj
Copy link

Choose a reason for hiding this comment

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

Just want to make sure that type_obj and checkType can never step on each other, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mypy would have a fit but one of them is a TypeInfo object and the other is a string so they can't stomp on each other.



def getPropertySetState(container, asLists=False):
"""Get the state of a PropertySet in a form that can be pickled.
Expand Down Expand Up @@ -164,13 +175,9 @@ def _propertyContainerElementTypeName(container, name):
except LookupError as e:
# KeyError is more commonly expected when asking for an element
# from a mapping.
raise KeyError(str(e))
for checkType in ("Bool", "Short", "Int", "Long", "LongLong", "UnsignedLongLong",
"Float", "Double", "String", "DateTime",
"PropertySet", "Undef"):
if t == getattr(container, "TYPE_" + checkType):
return checkType
return None
raise KeyError(str(e)) from None

return _TYPE_MAP.get(t, None)


def _propertyContainerGet(container, name, returnStyle):
Expand Down Expand Up @@ -325,9 +332,9 @@ def _choose_int_from_range(int_value, current_type):
f"range value: {int_value}")
return use_type

try:
if container.exists(name):
containerType = _propertyContainerElementTypeName(container, name)
except LookupError:
else:
containerType = None

useTypeMin = _choose_int_from_range(min, containerType)
Expand Down Expand Up @@ -645,12 +652,20 @@ def __eq__(self, other):
return False

for name in self:
if _propertyContainerGet(self, name, returnStyle=ReturnStyle.AUTO) != \
_propertyContainerGet(other, name, returnStyle=ReturnStyle.AUTO):
return False
if self.typeOf(name) != other.typeOf(name):
if (self_typeOf := self.typeOf(name)) != other.typeOf(name):
return False

if (v1 := _propertyContainerGet(self, name, returnStyle=ReturnStyle.AUTO)) != \
(v2 := _propertyContainerGet(other, name, returnStyle=ReturnStyle.AUTO)):
# It is possible that we have floats that are NaN. When
# equating two PropertySets if there are fields with NaN
# these should equate equal.
if self_typeOf in (_TYPE_MAP["Float"], _TYPE_MAP["Double"]) \
and math.isnan(v1) and math.isnan(v2):
pass
else:
return False

return True

def __copy__(self):
Expand Down