gamsapi 52.5.0__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gams/__init__.py +27 -0
- gams/_version.py +1 -0
- gams/connect/__init__.py +28 -0
- gams/connect/agents/__init__.py +24 -0
- gams/connect/agents/_excel/__init__.py +32 -0
- gams/connect/agents/_excel/excelagent.py +312 -0
- gams/connect/agents/_excel/workbook.py +155 -0
- gams/connect/agents/_sqlconnectors/__init__.py +42 -0
- gams/connect/agents/_sqlconnectors/_accesshandler.py +211 -0
- gams/connect/agents/_sqlconnectors/_databasehandler.py +250 -0
- gams/connect/agents/_sqlconnectors/_mysqlhandler.py +168 -0
- gams/connect/agents/_sqlconnectors/_postgreshandler.py +131 -0
- gams/connect/agents/_sqlconnectors/_pyodbchandler.py +112 -0
- gams/connect/agents/_sqlconnectors/_sqlalchemyhandler.py +74 -0
- gams/connect/agents/_sqlconnectors/_sqlitehandler.py +262 -0
- gams/connect/agents/_sqlconnectors/_sqlserverhandler.py +179 -0
- gams/connect/agents/concatenate.py +440 -0
- gams/connect/agents/connectagent.py +743 -0
- gams/connect/agents/csvreader.py +675 -0
- gams/connect/agents/csvwriter.py +151 -0
- gams/connect/agents/domainwriter.py +143 -0
- gams/connect/agents/excelreader.py +756 -0
- gams/connect/agents/excelwriter.py +467 -0
- gams/connect/agents/filter.py +223 -0
- gams/connect/agents/gamsreader.py +112 -0
- gams/connect/agents/gamswriter.py +239 -0
- gams/connect/agents/gdxreader.py +109 -0
- gams/connect/agents/gdxwriter.py +146 -0
- gams/connect/agents/labelmanipulator.py +303 -0
- gams/connect/agents/projection.py +539 -0
- gams/connect/agents/pythoncode.py +71 -0
- gams/connect/agents/rawcsvreader.py +248 -0
- gams/connect/agents/rawexcelreader.py +312 -0
- gams/connect/agents/schema/CSVReader.yaml +92 -0
- gams/connect/agents/schema/CSVWriter.yaml +44 -0
- gams/connect/agents/schema/Concatenate.yaml +52 -0
- gams/connect/agents/schema/DomainWriter.yaml +25 -0
- gams/connect/agents/schema/ExcelReader.yaml +121 -0
- gams/connect/agents/schema/ExcelWriter.yaml +78 -0
- gams/connect/agents/schema/Filter.yaml +74 -0
- gams/connect/agents/schema/GAMSReader.yaml +20 -0
- gams/connect/agents/schema/GAMSWriter.yaml +47 -0
- gams/connect/agents/schema/GDXReader.yaml +23 -0
- gams/connect/agents/schema/GDXWriter.yaml +32 -0
- gams/connect/agents/schema/LabelManipulator.yaml +99 -0
- gams/connect/agents/schema/Projection.yaml +24 -0
- gams/connect/agents/schema/PythonCode.yaml +6 -0
- gams/connect/agents/schema/RawCSVReader.yaml +34 -0
- gams/connect/agents/schema/RawExcelReader.yaml +42 -0
- gams/connect/agents/schema/SQLReader.yaml +75 -0
- gams/connect/agents/schema/SQLWriter.yaml +103 -0
- gams/connect/agents/sqlreader.py +301 -0
- gams/connect/agents/sqlwriter.py +276 -0
- gams/connect/connectdatabase.py +275 -0
- gams/connect/connectvalidator.py +93 -0
- gams/connect/errors.py +34 -0
- gams/control/__init__.py +136 -0
- gams/control/database.py +2231 -0
- gams/control/execution.py +1900 -0
- gams/control/options.py +2792 -0
- gams/control/workspace.py +1198 -0
- gams/core/__init__.py +24 -0
- gams/core/cfg/__init__.py +26 -0
- gams/core/cfg/_cfgmcc.cp312-win_amd64.pyd +0 -0
- gams/core/cfg/cfgmcc.py +519 -0
- gams/core/dct/__init__.py +26 -0
- gams/core/dct/_dctmcc.cp312-win_amd64.pyd +0 -0
- gams/core/dct/dctmcc.py +574 -0
- gams/core/embedded/__init__.py +26 -0
- gams/core/embedded/gamsemb.py +1024 -0
- gams/core/emp/__init__.py +24 -0
- gams/core/emp/emplexer.py +89 -0
- gams/core/emp/empyacc.py +281 -0
- gams/core/gdx/__init__.py +26 -0
- gams/core/gdx/_gdxcc.cp312-win_amd64.pyd +0 -0
- gams/core/gdx/gdxcc.py +866 -0
- gams/core/gev/__init__.py +26 -0
- gams/core/gev/_gevmcc.cp312-win_amd64.pyd +0 -0
- gams/core/gev/gevmcc.py +855 -0
- gams/core/gmd/__init__.py +26 -0
- gams/core/gmd/_gmdcc.cp312-win_amd64.pyd +0 -0
- gams/core/gmd/gmdcc.py +917 -0
- gams/core/gmo/__init__.py +26 -0
- gams/core/gmo/_gmomcc.cp312-win_amd64.pyd +0 -0
- gams/core/gmo/gmomcc.py +2046 -0
- gams/core/idx/__init__.py +26 -0
- gams/core/idx/_idxcc.cp312-win_amd64.pyd +0 -0
- gams/core/idx/idxcc.py +510 -0
- gams/core/numpy/__init__.py +29 -0
- gams/core/numpy/_gams2numpy.cp312-win_amd64.pyd +0 -0
- gams/core/numpy/gams2numpy.py +1048 -0
- gams/core/opt/__init__.py +26 -0
- gams/core/opt/_optcc.cp312-win_amd64.pyd +0 -0
- gams/core/opt/optcc.py +840 -0
- gams/engine/__init__.py +204 -0
- gams/engine/api/__init__.py +13 -0
- gams/engine/api/auth_api.py +7653 -0
- gams/engine/api/cleanup_api.py +751 -0
- gams/engine/api/default_api.py +887 -0
- gams/engine/api/hypercube_api.py +2629 -0
- gams/engine/api/jobs_api.py +5229 -0
- gams/engine/api/licenses_api.py +2220 -0
- gams/engine/api/namespaces_api.py +7783 -0
- gams/engine/api/usage_api.py +5627 -0
- gams/engine/api/users_api.py +5931 -0
- gams/engine/api_client.py +804 -0
- gams/engine/api_response.py +21 -0
- gams/engine/configuration.py +601 -0
- gams/engine/exceptions.py +216 -0
- gams/engine/models/__init__.py +86 -0
- gams/engine/models/bad_input.py +89 -0
- gams/engine/models/cleanable_job_result.py +104 -0
- gams/engine/models/cleanable_job_result_page.py +113 -0
- gams/engine/models/engine_license.py +107 -0
- gams/engine/models/files_not_found.py +93 -0
- gams/engine/models/forwarded_token_response.py +112 -0
- gams/engine/models/generic_key_value_pair.py +89 -0
- gams/engine/models/hypercube.py +160 -0
- gams/engine/models/hypercube_page.py +111 -0
- gams/engine/models/hypercube_summary.py +91 -0
- gams/engine/models/hypercube_token.py +97 -0
- gams/engine/models/identity_provider.py +107 -0
- gams/engine/models/identity_provider_ldap.py +121 -0
- gams/engine/models/identity_provider_oauth2.py +146 -0
- gams/engine/models/identity_provider_oauth2_scope.py +89 -0
- gams/engine/models/identity_provider_oauth2_with_secret.py +152 -0
- gams/engine/models/identity_provider_oidc.py +133 -0
- gams/engine/models/identity_provider_oidc_with_secret.py +143 -0
- gams/engine/models/inex.py +91 -0
- gams/engine/models/invitation.py +136 -0
- gams/engine/models/invitation_quota.py +106 -0
- gams/engine/models/invitation_token.py +87 -0
- gams/engine/models/job.py +165 -0
- gams/engine/models/job_no_text_entry.py +138 -0
- gams/engine/models/job_no_text_entry_page.py +111 -0
- gams/engine/models/license.py +91 -0
- gams/engine/models/log_piece.py +96 -0
- gams/engine/models/message.py +87 -0
- gams/engine/models/message_and_token.py +99 -0
- gams/engine/models/message_with_webhook_id.py +89 -0
- gams/engine/models/model_auth_token.py +87 -0
- gams/engine/models/model_configuration.py +125 -0
- gams/engine/models/model_default_instance.py +99 -0
- gams/engine/models/model_default_user_instance.py +98 -0
- gams/engine/models/model_hypercube_job.py +106 -0
- gams/engine/models/model_hypercube_usage.py +130 -0
- gams/engine/models/model_instance_info.py +116 -0
- gams/engine/models/model_instance_info_full.py +123 -0
- gams/engine/models/model_instance_pool_info.py +112 -0
- gams/engine/models/model_job_labels.py +179 -0
- gams/engine/models/model_job_usage.py +133 -0
- gams/engine/models/model_pool_usage.py +124 -0
- gams/engine/models/model_usage.py +115 -0
- gams/engine/models/model_user.py +96 -0
- gams/engine/models/model_userinstance_info.py +119 -0
- gams/engine/models/model_userinstancepool_info.py +95 -0
- gams/engine/models/model_version.py +91 -0
- gams/engine/models/models.py +120 -0
- gams/engine/models/namespace.py +104 -0
- gams/engine/models/namespace_quota.py +96 -0
- gams/engine/models/namespace_with_permission.py +96 -0
- gams/engine/models/not_found.py +91 -0
- gams/engine/models/password_policy.py +97 -0
- gams/engine/models/perm_and_username.py +89 -0
- gams/engine/models/quota.py +117 -0
- gams/engine/models/quota_exceeded.py +97 -0
- gams/engine/models/status_code_meaning.py +89 -0
- gams/engine/models/stream_entry.py +89 -0
- gams/engine/models/system_wide_license.py +92 -0
- gams/engine/models/text_entries.py +87 -0
- gams/engine/models/text_entry.py +101 -0
- gams/engine/models/time_span.py +95 -0
- gams/engine/models/time_span_pool_worker.py +99 -0
- gams/engine/models/token_forward_error.py +87 -0
- gams/engine/models/user.py +127 -0
- gams/engine/models/user_group_member.py +96 -0
- gams/engine/models/user_groups.py +108 -0
- gams/engine/models/vapid_info.py +87 -0
- gams/engine/models/webhook.py +138 -0
- gams/engine/models/webhook_parameterized_event.py +99 -0
- gams/engine/py.typed +0 -0
- gams/engine/rest.py +258 -0
- gams/magic/__init__.py +32 -0
- gams/magic/gams_magic.py +142 -0
- gams/magic/interactive.py +402 -0
- gams/tools/__init__.py +30 -0
- gams/tools/errors.py +34 -0
- gams/tools/toolcollection/__init__.py +24 -0
- gams/tools/toolcollection/alg/__init__.py +24 -0
- gams/tools/toolcollection/alg/rank.py +51 -0
- gams/tools/toolcollection/data/__init__.py +24 -0
- gams/tools/toolcollection/data/csvread.py +444 -0
- gams/tools/toolcollection/data/csvwrite.py +311 -0
- gams/tools/toolcollection/data/exceldump.py +47 -0
- gams/tools/toolcollection/data/sqlitewrite.py +276 -0
- gams/tools/toolcollection/gdxservice/__init__.py +24 -0
- gams/tools/toolcollection/gdxservice/gdxencoding.py +104 -0
- gams/tools/toolcollection/gdxservice/gdxrename.py +94 -0
- gams/tools/toolcollection/linalg/__init__.py +24 -0
- gams/tools/toolcollection/linalg/cholesky.py +57 -0
- gams/tools/toolcollection/linalg/eigenvalue.py +56 -0
- gams/tools/toolcollection/linalg/eigenvector.py +58 -0
- gams/tools/toolcollection/linalg/invert.py +55 -0
- gams/tools/toolcollection/linalg/ols.py +138 -0
- gams/tools/toolcollection/tooltemplate.py +321 -0
- gams/tools/toolcollection/win32/__init__.py +24 -0
- gams/tools/toolcollection/win32/excelmerge.py +93 -0
- gams/tools/toolcollection/win32/exceltalk.py +76 -0
- gams/tools/toolcollection/win32/msappavail.py +49 -0
- gams/tools/toolcollection/win32/shellexecute.py +54 -0
- gams/tools/tools.py +116 -0
- gams/transfer/__init__.py +35 -0
- gams/transfer/_abcs/__init__.py +37 -0
- gams/transfer/_abcs/container_abcs.py +433 -0
- gams/transfer/_internals/__init__.py +63 -0
- gams/transfer/_internals/algorithms.py +436 -0
- gams/transfer/_internals/casepreservingdict.py +124 -0
- gams/transfer/_internals/constants.py +270 -0
- gams/transfer/_internals/domainviolation.py +103 -0
- gams/transfer/_internals/specialvalues.py +172 -0
- gams/transfer/containers/__init__.py +26 -0
- gams/transfer/containers/_container.py +1794 -0
- gams/transfer/containers/_io/__init__.py +28 -0
- gams/transfer/containers/_io/containers.py +164 -0
- gams/transfer/containers/_io/gdx.py +1029 -0
- gams/transfer/containers/_io/gmd.py +872 -0
- gams/transfer/containers/_mixins/__init__.py +26 -0
- gams/transfer/containers/_mixins/ccc.py +1274 -0
- gams/transfer/syms/__init__.py +33 -0
- gams/transfer/syms/_methods/__init__.py +24 -0
- gams/transfer/syms/_methods/tables.py +120 -0
- gams/transfer/syms/_methods/toDict.py +115 -0
- gams/transfer/syms/_methods/toList.py +83 -0
- gams/transfer/syms/_methods/toValue.py +60 -0
- gams/transfer/syms/_mixins/__init__.py +32 -0
- gams/transfer/syms/_mixins/equals.py +626 -0
- gams/transfer/syms/_mixins/generateRecords.py +499 -0
- gams/transfer/syms/_mixins/pivot.py +313 -0
- gams/transfer/syms/_mixins/pve.py +627 -0
- gams/transfer/syms/_mixins/sa.py +27 -0
- gams/transfer/syms/_mixins/sapve.py +27 -0
- gams/transfer/syms/_mixins/saua.py +27 -0
- gams/transfer/syms/_mixins/sauapve.py +199 -0
- gams/transfer/syms/_mixins/spve.py +1528 -0
- gams/transfer/syms/_mixins/ve.py +936 -0
- gams/transfer/syms/container_syms/__init__.py +31 -0
- gams/transfer/syms/container_syms/_alias.py +984 -0
- gams/transfer/syms/container_syms/_equation.py +333 -0
- gams/transfer/syms/container_syms/_parameter.py +973 -0
- gams/transfer/syms/container_syms/_set.py +604 -0
- gams/transfer/syms/container_syms/_universe_alias.py +461 -0
- gams/transfer/syms/container_syms/_variable.py +321 -0
- gamsapi-52.5.0.dist-info/METADATA +150 -0
- gamsapi-52.5.0.dist-info/RECORD +257 -0
- gamsapi-52.5.0.dist-info/WHEEL +5 -0
- gamsapi-52.5.0.dist-info/licenses/LICENSE +22 -0
- gamsapi-52.5.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,984 @@
|
|
|
1
|
+
#
|
|
2
|
+
# GAMS - General Algebraic Modeling System Python API
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2017-2026 GAMS Development Corp. <support@gams.com>
|
|
5
|
+
# Copyright (c) 2017-2026 GAMS Software GmbH <support@gams.com>
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
# copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
# SOFTWARE.
|
|
24
|
+
#
|
|
25
|
+
|
|
26
|
+
import pandas as pd
|
|
27
|
+
import weakref
|
|
28
|
+
from gams.core import gdx
|
|
29
|
+
from gams.transfer._abcs import (
|
|
30
|
+
ABCSet,
|
|
31
|
+
ABCAlias,
|
|
32
|
+
ABCUniverseAlias,
|
|
33
|
+
ABCContainer,
|
|
34
|
+
)
|
|
35
|
+
from gams.transfer.syms._mixins import SAMixin, SAPVEMixin, SAUAMixin, SAUAPVEMixin
|
|
36
|
+
from typing import TYPE_CHECKING, Union, Optional, List, Any
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
from gams.transfer import Container
|
|
41
|
+
from gams.transfer import Set
|
|
42
|
+
from gams.transfer._internals import DomainViolation
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class Alias(SAMixin, SAPVEMixin, SAUAMixin, SAUAPVEMixin, ABCAlias):
|
|
46
|
+
"""
|
|
47
|
+
Represents an Alias symbol in GAMS.
|
|
48
|
+
https://www.gams.com/latest/docs/UG_SetDefinition.html#UG_SetDefinition_TheAliasStatementMultipleNamesForASet
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
container : Container
|
|
53
|
+
The container to which the alias belongs.
|
|
54
|
+
name : str
|
|
55
|
+
Name of the alias.
|
|
56
|
+
alias_with : Set
|
|
57
|
+
The set with which the alias will share its data.
|
|
58
|
+
|
|
59
|
+
Examples
|
|
60
|
+
--------
|
|
61
|
+
>>> import gams.transfer as gt
|
|
62
|
+
>>> m = gt.Container()
|
|
63
|
+
>>> i = gt.Set(m, "i")
|
|
64
|
+
>>> j = gt.Alias(m, "j", i)
|
|
65
|
+
|
|
66
|
+
Attributes
|
|
67
|
+
----------
|
|
68
|
+
alias_with : Set Object
|
|
69
|
+
Aliased object
|
|
70
|
+
container : Container object
|
|
71
|
+
Container where the symbol exists
|
|
72
|
+
description : str
|
|
73
|
+
description of symbol
|
|
74
|
+
dimension : int
|
|
75
|
+
The dimension of symbol
|
|
76
|
+
domain : List[Set | Alias | str]
|
|
77
|
+
List of domains given either as string (* for universe set) or as reference to the Set/Alias object
|
|
78
|
+
domain_labels : List[str]
|
|
79
|
+
The column headings for the records DataFrame
|
|
80
|
+
domain_names : List[str]
|
|
81
|
+
String version of domain names
|
|
82
|
+
domain_type : str
|
|
83
|
+
The state of domain links
|
|
84
|
+
is_singleton : bool
|
|
85
|
+
Flag that identifies if the the alias is singleton
|
|
86
|
+
modified : bool
|
|
87
|
+
Flag that identifies if the symbol has been modified
|
|
88
|
+
name : str
|
|
89
|
+
Name of the symbol
|
|
90
|
+
number_records : int
|
|
91
|
+
The number of symbol records
|
|
92
|
+
records : DataFrame
|
|
93
|
+
The main symbol records
|
|
94
|
+
summary : dict
|
|
95
|
+
A dict of only the metadata
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
@classmethod
|
|
99
|
+
def _from_gams(cls, container, name, alias_with):
|
|
100
|
+
# create new symbol object
|
|
101
|
+
obj = Alias.__new__(cls)
|
|
102
|
+
|
|
103
|
+
# set private properties directly
|
|
104
|
+
obj._requires_state_check = False
|
|
105
|
+
obj._container = weakref.proxy(container)
|
|
106
|
+
obj._name = name
|
|
107
|
+
obj._alias_with = alias_with
|
|
108
|
+
obj._modified = True
|
|
109
|
+
|
|
110
|
+
# typing
|
|
111
|
+
obj._gams_type = gdx.GMS_DT_ALIAS
|
|
112
|
+
obj._gams_subtype = 1
|
|
113
|
+
|
|
114
|
+
# add to container
|
|
115
|
+
obj._container.data.update({name: obj})
|
|
116
|
+
obj._container._requires_state_check = True
|
|
117
|
+
|
|
118
|
+
return obj
|
|
119
|
+
|
|
120
|
+
def __new__(cls, *args, **kwargs):
|
|
121
|
+
# fastpath
|
|
122
|
+
if len(args) == len(kwargs) == 0:
|
|
123
|
+
return object.__new__(cls)
|
|
124
|
+
|
|
125
|
+
try:
|
|
126
|
+
container = args[0]
|
|
127
|
+
except IndexError:
|
|
128
|
+
container = kwargs.get("container", None)
|
|
129
|
+
|
|
130
|
+
try:
|
|
131
|
+
name = args[1]
|
|
132
|
+
except IndexError:
|
|
133
|
+
name = kwargs.get("name", None)
|
|
134
|
+
|
|
135
|
+
try:
|
|
136
|
+
symobj = container[name]
|
|
137
|
+
except (KeyError, IndexError, TypeError):
|
|
138
|
+
symobj = None
|
|
139
|
+
|
|
140
|
+
if symobj is None:
|
|
141
|
+
return object.__new__(cls)
|
|
142
|
+
else:
|
|
143
|
+
if isinstance(symobj, cls):
|
|
144
|
+
return symobj
|
|
145
|
+
else:
|
|
146
|
+
raise TypeError(
|
|
147
|
+
f"Cannot overwrite symbol '{symobj.name}' in container because it is not a {cls.__name__} object"
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
def __init__(self, container: "Container", name: str, alias_with: "Set") -> None:
|
|
151
|
+
# does symbol exist
|
|
152
|
+
has_symbol = False
|
|
153
|
+
if isinstance(getattr(self, "container", None), ABCContainer):
|
|
154
|
+
has_symbol = True
|
|
155
|
+
|
|
156
|
+
if has_symbol:
|
|
157
|
+
# reset some properties
|
|
158
|
+
self._requires_state_check = True
|
|
159
|
+
self.container._requires_state_check = True
|
|
160
|
+
self.modified = True
|
|
161
|
+
self.alias_with = alias_with
|
|
162
|
+
|
|
163
|
+
else:
|
|
164
|
+
# populate new symbol properties
|
|
165
|
+
self._requires_state_check = True
|
|
166
|
+
self.container = container
|
|
167
|
+
self.name = name
|
|
168
|
+
self.modified = True
|
|
169
|
+
self.alias_with = alias_with
|
|
170
|
+
self._gams_type = gdx.GMS_DT_ALIAS
|
|
171
|
+
self._gams_subtype = 1
|
|
172
|
+
container.data.update({name: self})
|
|
173
|
+
|
|
174
|
+
def __repr__(self):
|
|
175
|
+
return f"<Alias `{self.name}` ({hex(id(self))})>"
|
|
176
|
+
|
|
177
|
+
def __delitem__(self):
|
|
178
|
+
# TODO: add in some functionality that might relax the symbols down to a different domain
|
|
179
|
+
# This function would mimic the <Container>.removeSymbols() method -- is more pythonic
|
|
180
|
+
del self.container.data[self.name]
|
|
181
|
+
|
|
182
|
+
def equals(
|
|
183
|
+
self,
|
|
184
|
+
other: Union["Set", "Alias"],
|
|
185
|
+
check_uels: bool = True,
|
|
186
|
+
check_element_text: bool = True,
|
|
187
|
+
check_meta_data: bool = True,
|
|
188
|
+
verbose: bool = False,
|
|
189
|
+
) -> bool:
|
|
190
|
+
"""
|
|
191
|
+
Used to compare the symbol to another symbol.
|
|
192
|
+
|
|
193
|
+
Parameters
|
|
194
|
+
----------
|
|
195
|
+
other : Set or Alias
|
|
196
|
+
The other symbol (Set or Alias) to compare with the current alias.
|
|
197
|
+
check_uels : bool, optional
|
|
198
|
+
If True, check both used and unused UELs and confirm same order, otherwise only check used UELs in data and do not check UEL order.
|
|
199
|
+
check_element_text : bool, optional
|
|
200
|
+
If True, check that all set elements have the same descriptive element text, otherwise skip.
|
|
201
|
+
check_meta_data : bool, optional
|
|
202
|
+
If True, check that symbol name and description are the same, otherwise skip.
|
|
203
|
+
verbose : bool, optional
|
|
204
|
+
If True, return an exception from the asserter describing the nature of the difference.
|
|
205
|
+
|
|
206
|
+
Returns
|
|
207
|
+
-------
|
|
208
|
+
bool
|
|
209
|
+
True if the two symbols are equal in the specified aspects; False if they are not equal and verbose is False.
|
|
210
|
+
|
|
211
|
+
Examples
|
|
212
|
+
--------
|
|
213
|
+
>>> m = gt.Container()
|
|
214
|
+
>>> i = gt.Set(m, "i")
|
|
215
|
+
>>> j = gt.Alias(m, "j", i)
|
|
216
|
+
>>> print(i.equals(j)) # Compare the Set 'i' with the Alias 'j'
|
|
217
|
+
True
|
|
218
|
+
|
|
219
|
+
"""
|
|
220
|
+
return self.alias_with.equals(
|
|
221
|
+
other,
|
|
222
|
+
check_uels=check_uels,
|
|
223
|
+
check_element_text=check_element_text,
|
|
224
|
+
check_meta_data=check_meta_data,
|
|
225
|
+
verbose=verbose,
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
def toList(self, include_element_text: bool = False) -> list:
|
|
229
|
+
"""
|
|
230
|
+
Convenience method to return symbol records as a python list
|
|
231
|
+
|
|
232
|
+
Parameters
|
|
233
|
+
----------
|
|
234
|
+
include_element_text : bool, optional
|
|
235
|
+
If True, include the element text as tuples (record, element text).
|
|
236
|
+
If False, return a list of records only.
|
|
237
|
+
|
|
238
|
+
Returns
|
|
239
|
+
-------
|
|
240
|
+
list
|
|
241
|
+
A list containing the records of the symbol.
|
|
242
|
+
|
|
243
|
+
Examples
|
|
244
|
+
--------
|
|
245
|
+
>>> m = gt.Container()
|
|
246
|
+
>>> i = gt.Set(m, "i", records=["new-york", "chicago", "topeka"])
|
|
247
|
+
>>> j = gt.Alias(m, "j", i)
|
|
248
|
+
>>> print(j.toList())
|
|
249
|
+
['new-york', 'chicago', 'topeka']
|
|
250
|
+
|
|
251
|
+
"""
|
|
252
|
+
return self.alias_with.toList(include_element_text=include_element_text)
|
|
253
|
+
|
|
254
|
+
def pivot(
|
|
255
|
+
self,
|
|
256
|
+
index: Optional[Union[List[str], str]] = None,
|
|
257
|
+
columns: Optional[Union[List[str], str]] = None,
|
|
258
|
+
fill_value: Optional[Union[int, float]] = None,
|
|
259
|
+
) -> pd.DataFrame:
|
|
260
|
+
"""
|
|
261
|
+
Convenience function to pivot records into a new shape (only symbols with > 1D can be pivoted).
|
|
262
|
+
|
|
263
|
+
Parameters
|
|
264
|
+
----------
|
|
265
|
+
index : List[str] | str, optional
|
|
266
|
+
If index is None then it is set to dimensions [0..dimension-1]
|
|
267
|
+
columns : List[str] | str, optional
|
|
268
|
+
If columns is None then it is set to the last dimension.
|
|
269
|
+
fill_value : int | float, optional
|
|
270
|
+
Missing values in the pivot will take the value provided by fill_value
|
|
271
|
+
|
|
272
|
+
Returns
|
|
273
|
+
-------
|
|
274
|
+
DataFrame
|
|
275
|
+
A new DataFrame containing the pivoted data.
|
|
276
|
+
|
|
277
|
+
Examples
|
|
278
|
+
--------
|
|
279
|
+
>>> m = gt.Container()
|
|
280
|
+
>>> i = gt.Set(m, "i", records=["seattle", "san-diego"])
|
|
281
|
+
>>> j = gt.Set(m, "j", records=["new-york", "chicago", "topeka"])
|
|
282
|
+
>>> ij = gt.Set(m, "ij", [i,j], records=[("seattle", "chicago"), ("seattle", "topeka"), ("san-diego", "new-york")])
|
|
283
|
+
>>> routes = gt.Alias(m, name="routes", alias_with=ij)
|
|
284
|
+
>>> print(routes.pivot(fill_value=""))
|
|
285
|
+
chicago topeka new-york
|
|
286
|
+
seattle True True
|
|
287
|
+
san-diego True
|
|
288
|
+
|
|
289
|
+
"""
|
|
290
|
+
return self.alias_with.pivot(
|
|
291
|
+
index=index, columns=columns, fill_value=fill_value
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
def getSparsity(self) -> Union[float, None]:
|
|
295
|
+
"""
|
|
296
|
+
Gets the sparsity of the symbol w.r.t the cardinality
|
|
297
|
+
|
|
298
|
+
Returns
|
|
299
|
+
-------
|
|
300
|
+
float | None
|
|
301
|
+
Sparsity of an alias
|
|
302
|
+
"""
|
|
303
|
+
return self.alias_with.getSparsity()
|
|
304
|
+
|
|
305
|
+
@property
|
|
306
|
+
def is_singleton(self) -> bool:
|
|
307
|
+
"""
|
|
308
|
+
if symbol is a singleton set
|
|
309
|
+
|
|
310
|
+
Returns
|
|
311
|
+
-------
|
|
312
|
+
bool
|
|
313
|
+
True if the alias is singleton; False otherwise
|
|
314
|
+
"""
|
|
315
|
+
return self.alias_with.is_singleton
|
|
316
|
+
|
|
317
|
+
@is_singleton.setter
|
|
318
|
+
def is_singleton(self, is_singleton: bool) -> None:
|
|
319
|
+
self.alias_with.is_singleton = is_singleton
|
|
320
|
+
self.modified = True
|
|
321
|
+
|
|
322
|
+
def getDomainViolations(self) -> Union[List["DomainViolation"], None]:
|
|
323
|
+
"""
|
|
324
|
+
Returns a list of DomainViolation objects if any (None otherwise)
|
|
325
|
+
|
|
326
|
+
Returns
|
|
327
|
+
-------
|
|
328
|
+
List[DomainViolation] | None
|
|
329
|
+
A list of DomainViolation objects if any (None otherwise)
|
|
330
|
+
"""
|
|
331
|
+
return self.alias_with.getDomainViolations()
|
|
332
|
+
|
|
333
|
+
def findDomainViolations(self) -> pd.DataFrame:
|
|
334
|
+
"""
|
|
335
|
+
Get a view of the records DataFrame that contain any domain violations
|
|
336
|
+
|
|
337
|
+
Returns
|
|
338
|
+
-------
|
|
339
|
+
DataFrame
|
|
340
|
+
A DataFrame containing the records that contain any domain violations.
|
|
341
|
+
If there are no violations, an empty DataFrame is returned.
|
|
342
|
+
"""
|
|
343
|
+
return self.alias_with.findDomainViolations()
|
|
344
|
+
|
|
345
|
+
def hasDomainViolations(self) -> bool:
|
|
346
|
+
"""
|
|
347
|
+
Returns True if there are domain violations in the records of the parent set, returns False if not.
|
|
348
|
+
|
|
349
|
+
Returns
|
|
350
|
+
-------
|
|
351
|
+
bool
|
|
352
|
+
True if there are domain violations in the records of the parent set; False otherwise
|
|
353
|
+
"""
|
|
354
|
+
return self.alias_with.hasDomainViolations()
|
|
355
|
+
|
|
356
|
+
def countDomainViolations(self) -> int:
|
|
357
|
+
"""
|
|
358
|
+
Returns the count of how many records in the parent set contain at least one domain violation
|
|
359
|
+
|
|
360
|
+
Returns
|
|
361
|
+
-------
|
|
362
|
+
int
|
|
363
|
+
The count of how many records in the parent set contain at least one domain violation
|
|
364
|
+
"""
|
|
365
|
+
return self.alias_with.countDomainViolations()
|
|
366
|
+
|
|
367
|
+
def dropDomainViolations(self) -> None:
|
|
368
|
+
"""
|
|
369
|
+
Drop records from the parent set that contain a domain violation
|
|
370
|
+
"""
|
|
371
|
+
return self.alias_with.dropDomainViolations()
|
|
372
|
+
|
|
373
|
+
def countDuplicateRecords(self) -> int:
|
|
374
|
+
"""
|
|
375
|
+
Returns the count of how many (case insensitive) duplicate records exist in the parent set
|
|
376
|
+
|
|
377
|
+
Returns
|
|
378
|
+
-------
|
|
379
|
+
int
|
|
380
|
+
The count of how many (case insensitive) duplicate records exist in the parent set
|
|
381
|
+
"""
|
|
382
|
+
return self.alias_with.countDuplicateRecords()
|
|
383
|
+
|
|
384
|
+
def findDuplicateRecords(self, keep: Union[str, bool] = "first") -> pd.DataFrame:
|
|
385
|
+
"""
|
|
386
|
+
Get a view of the records DataFrame that contain any domain violations.
|
|
387
|
+
|
|
388
|
+
Parameters
|
|
389
|
+
----------
|
|
390
|
+
keep : str, optional
|
|
391
|
+
Specifies how to handle duplicates. Options are:
|
|
392
|
+
- 'first' (default): Keeps the first occurrence and removes subsequent duplicates.
|
|
393
|
+
- 'last': Keeps the last occurrence and removes previous duplicates.
|
|
394
|
+
- False: Keeps all duplicates.
|
|
395
|
+
|
|
396
|
+
Returns
|
|
397
|
+
-------
|
|
398
|
+
DataFrame
|
|
399
|
+
A DataFrame of the records that contain any domain violations.
|
|
400
|
+
If there are no duplicates, an empty DataFrame is returned.
|
|
401
|
+
"""
|
|
402
|
+
return self.alias_with.findDuplicateRecords(keep=keep)
|
|
403
|
+
|
|
404
|
+
def hasDuplicateRecords(self) -> bool:
|
|
405
|
+
"""
|
|
406
|
+
Returns True if there are (case insensitive) duplicate records in the parent set, returns False if not.
|
|
407
|
+
|
|
408
|
+
Returns
|
|
409
|
+
-------
|
|
410
|
+
bool
|
|
411
|
+
True if there are (case insensitive) duplicate records in the parent set; False otherwise
|
|
412
|
+
"""
|
|
413
|
+
return self.alias_with.hasDuplicateRecords()
|
|
414
|
+
|
|
415
|
+
def dropDuplicateRecords(self, keep: Union[str, bool] = "first") -> None:
|
|
416
|
+
"""
|
|
417
|
+
Drop records with (case insensitive) duplicate domains from the parent set
|
|
418
|
+
|
|
419
|
+
Parameters
|
|
420
|
+
----------
|
|
421
|
+
keep : str, optional
|
|
422
|
+
Specifies how to handle duplicates. Options are:
|
|
423
|
+
- 'first' (default): keeps the first instance of a duplicate record
|
|
424
|
+
- 'last': keeps the last instance of a record
|
|
425
|
+
- False: drops all duplicates including the first and last
|
|
426
|
+
"""
|
|
427
|
+
return self.alias_with.dropDuplicateRecords(keep=keep)
|
|
428
|
+
|
|
429
|
+
def _getUELCodes(self, dimension, ignore_unused=False):
|
|
430
|
+
return self.alias_with._getUELCodes(dimension, ignore_unused=ignore_unused)
|
|
431
|
+
|
|
432
|
+
def getUELs(
|
|
433
|
+
self,
|
|
434
|
+
dimensions: Optional[Union[List[int], int]] = None,
|
|
435
|
+
codes: Optional[Union[List[int], int]] = None,
|
|
436
|
+
ignore_unused: bool = False,
|
|
437
|
+
) -> List[str]:
|
|
438
|
+
"""
|
|
439
|
+
Gets UELs from the parent set dimensions. If dimensions is None then get UELs from all dimensions (maintains order).
|
|
440
|
+
The argument codes accepts a list of str UELs and will return the corresponding int; must specify a single dimension if passing codes.
|
|
441
|
+
|
|
442
|
+
Parameters
|
|
443
|
+
----------
|
|
444
|
+
dimensions : List[int] | int, optional
|
|
445
|
+
codes : List[int] | int, optional
|
|
446
|
+
ignore_unused : bool, optional
|
|
447
|
+
|
|
448
|
+
Returns
|
|
449
|
+
-------
|
|
450
|
+
List[str]
|
|
451
|
+
Returns only UELs in the data if ignore_unused=True, otherwise return all UELs.
|
|
452
|
+
"""
|
|
453
|
+
return self.alias_with.getUELs(
|
|
454
|
+
dimensions=dimensions, codes=codes, ignore_unused=ignore_unused
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
def lowerUELs(self, dimensions: Optional[Union[List[int], int]] = None) -> "Alias":
|
|
458
|
+
"""
|
|
459
|
+
Lowercase the UELs of an Alias.
|
|
460
|
+
|
|
461
|
+
Parameters
|
|
462
|
+
----------
|
|
463
|
+
dimensions : List[int] | int, optional
|
|
464
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
465
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
466
|
+
|
|
467
|
+
Returns
|
|
468
|
+
-------
|
|
469
|
+
Alias
|
|
470
|
+
The Alias with lowercase UELs.
|
|
471
|
+
"""
|
|
472
|
+
self.alias_with.lowerUELs(dimensions=dimensions)
|
|
473
|
+
return self
|
|
474
|
+
|
|
475
|
+
def upperUELs(self, dimensions: Optional[Union[List[int], int]] = None) -> "Alias":
|
|
476
|
+
"""
|
|
477
|
+
Uppercase the UELs of an Alias.
|
|
478
|
+
|
|
479
|
+
Parameters
|
|
480
|
+
----------
|
|
481
|
+
dimensions : List[int] | int, optional
|
|
482
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
483
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
484
|
+
|
|
485
|
+
Returns
|
|
486
|
+
-------
|
|
487
|
+
Alias
|
|
488
|
+
The Alias with uppercase UELs.
|
|
489
|
+
"""
|
|
490
|
+
self.alias_with.upperUELs(dimensions=dimensions)
|
|
491
|
+
return self
|
|
492
|
+
|
|
493
|
+
def lstripUELs(self, dimensions: Optional[Union[List[int], int]] = None) -> "Alias":
|
|
494
|
+
"""
|
|
495
|
+
Remove leading whitespaces from the UELs of an Alias.
|
|
496
|
+
|
|
497
|
+
Parameters
|
|
498
|
+
----------
|
|
499
|
+
dimensions : List[int] | int, optional
|
|
500
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
501
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
502
|
+
|
|
503
|
+
Returns
|
|
504
|
+
-------
|
|
505
|
+
Alias
|
|
506
|
+
The Alias with processed UELs.
|
|
507
|
+
"""
|
|
508
|
+
self.alias_with.lstripUELs(dimensions=dimensions)
|
|
509
|
+
return self
|
|
510
|
+
|
|
511
|
+
def rstripUELs(self, dimensions: Optional[Union[List[int], int]] = None) -> "Alias":
|
|
512
|
+
"""
|
|
513
|
+
Remove trailing whitespaces from the UELs of an Alias.
|
|
514
|
+
|
|
515
|
+
Parameters
|
|
516
|
+
----------
|
|
517
|
+
dimensions : List[int] | int, optional
|
|
518
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
519
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
520
|
+
|
|
521
|
+
Returns
|
|
522
|
+
-------
|
|
523
|
+
Alias
|
|
524
|
+
The Alias with processed UELs.
|
|
525
|
+
"""
|
|
526
|
+
self.alias_with.rstripUELs(dimensions=dimensions)
|
|
527
|
+
return self
|
|
528
|
+
|
|
529
|
+
def stripUELs(self, dimensions: Optional[Union[List[int], int]] = None) -> "Alias":
|
|
530
|
+
"""
|
|
531
|
+
Remove leading and trailing whitespaces from the UELs of an Alias.
|
|
532
|
+
|
|
533
|
+
Parameters
|
|
534
|
+
----------
|
|
535
|
+
dimensions : List[int] | int, optional
|
|
536
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
537
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
538
|
+
|
|
539
|
+
Returns
|
|
540
|
+
-------
|
|
541
|
+
Alias
|
|
542
|
+
The Alias with processed UELs.
|
|
543
|
+
"""
|
|
544
|
+
self.alias_with.stripUELs(dimensions=dimensions)
|
|
545
|
+
return self
|
|
546
|
+
|
|
547
|
+
def capitalizeUELs(
|
|
548
|
+
self, dimensions: Optional[Union[List[int], int]] = None
|
|
549
|
+
) -> "Alias":
|
|
550
|
+
"""
|
|
551
|
+
Capitalizes the first character of UELs of an Alias
|
|
552
|
+
|
|
553
|
+
Parameters
|
|
554
|
+
----------
|
|
555
|
+
dimensions : List[int] | int, optional
|
|
556
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
557
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
558
|
+
|
|
559
|
+
Returns
|
|
560
|
+
-------
|
|
561
|
+
Alias
|
|
562
|
+
The Alias with processed UELs.
|
|
563
|
+
"""
|
|
564
|
+
self.alias_with.capitalizeUELs(dimensions=dimensions)
|
|
565
|
+
return self
|
|
566
|
+
|
|
567
|
+
def casefoldUELs(
|
|
568
|
+
self, dimensions: Optional[Union[List[int], int]] = None
|
|
569
|
+
) -> "Alias":
|
|
570
|
+
"""
|
|
571
|
+
Casefolds the UELs of an Alias
|
|
572
|
+
|
|
573
|
+
Parameters
|
|
574
|
+
----------
|
|
575
|
+
dimensions : List[int] | int, optional
|
|
576
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
577
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
578
|
+
|
|
579
|
+
Returns
|
|
580
|
+
-------
|
|
581
|
+
Alias
|
|
582
|
+
The Alias with processed UELs.
|
|
583
|
+
"""
|
|
584
|
+
self.alias_with.casefoldUELs(dimensions=dimensions)
|
|
585
|
+
return self
|
|
586
|
+
|
|
587
|
+
def titleUELs(self, dimensions: Optional[Union[List[int], int]] = None) -> "Alias":
|
|
588
|
+
"""
|
|
589
|
+
Converts the UELs of an Alias to title style; new-york -> New-York
|
|
590
|
+
|
|
591
|
+
Parameters
|
|
592
|
+
----------
|
|
593
|
+
dimensions : List[int] | int, optional
|
|
594
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
595
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
596
|
+
|
|
597
|
+
Returns
|
|
598
|
+
-------
|
|
599
|
+
Alias
|
|
600
|
+
The Alias with processed UELs.
|
|
601
|
+
"""
|
|
602
|
+
self.alias_with.titleUELs(dimensions=dimensions)
|
|
603
|
+
return self
|
|
604
|
+
|
|
605
|
+
def ljustUELs(
|
|
606
|
+
self,
|
|
607
|
+
length: int,
|
|
608
|
+
fill_character: Optional[str] = None,
|
|
609
|
+
dimensions: Optional[Union[List[int], int]] = None,
|
|
610
|
+
) -> "Alias":
|
|
611
|
+
"""
|
|
612
|
+
Left-justifies the UELs of an Alias, padding them with a specified fill character to reach the desired length.
|
|
613
|
+
|
|
614
|
+
Parameters
|
|
615
|
+
----------
|
|
616
|
+
length : int
|
|
617
|
+
The target length to which UELs will be left-justified.
|
|
618
|
+
|
|
619
|
+
fill_character : str, optional
|
|
620
|
+
The character used for padding the UELs to the specified length. If not provided, it defaults to a whitespace.
|
|
621
|
+
|
|
622
|
+
dimensions : List[int] | int, optional
|
|
623
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
624
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
625
|
+
|
|
626
|
+
Returns
|
|
627
|
+
-------
|
|
628
|
+
Alias
|
|
629
|
+
The Alias with processed UELs.
|
|
630
|
+
"""
|
|
631
|
+
self.alias_with.ljustUELs(
|
|
632
|
+
length, fill_character=fill_character, dimensions=dimensions
|
|
633
|
+
)
|
|
634
|
+
return self
|
|
635
|
+
|
|
636
|
+
def rjustUELs(
|
|
637
|
+
self,
|
|
638
|
+
length: int,
|
|
639
|
+
fill_character: Optional[str] = None,
|
|
640
|
+
dimensions: Optional[Union[List[int], int]] = None,
|
|
641
|
+
) -> "Alias":
|
|
642
|
+
"""
|
|
643
|
+
Left-justifies the UELs of an Alias, padding them with a specified fill character to reach the desired length.
|
|
644
|
+
|
|
645
|
+
Parameters
|
|
646
|
+
----------
|
|
647
|
+
length : int
|
|
648
|
+
The target length to which UELs will be left-justified.
|
|
649
|
+
|
|
650
|
+
fill_character : str, optional
|
|
651
|
+
The character used for padding the UELs to the specified length. If not provided, it defaults to a whitespace.
|
|
652
|
+
|
|
653
|
+
dimensions : List[int] | int, optional
|
|
654
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
655
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
656
|
+
|
|
657
|
+
Returns
|
|
658
|
+
-------
|
|
659
|
+
Alias
|
|
660
|
+
The Alias with processed UELs.
|
|
661
|
+
"""
|
|
662
|
+
self.alias_with.rjustUELs(
|
|
663
|
+
length, fill_character=fill_character, dimensions=dimensions
|
|
664
|
+
)
|
|
665
|
+
return self
|
|
666
|
+
|
|
667
|
+
def setUELs(
|
|
668
|
+
self,
|
|
669
|
+
uels: Union[List[str], str],
|
|
670
|
+
dimensions: Optional[Union[List[int], int]] = None,
|
|
671
|
+
rename: bool = False,
|
|
672
|
+
) -> None:
|
|
673
|
+
"""
|
|
674
|
+
Set the UELs for parent set dimensions. If dimensions is None then set UELs for all dimensions.
|
|
675
|
+
If rename=True, then the old UEL names will be renamed with the new UEL names. ** All trailing whitespace is trimmed **
|
|
676
|
+
|
|
677
|
+
Parameters
|
|
678
|
+
----------
|
|
679
|
+
uels : List[str] | str
|
|
680
|
+
UELs to be set
|
|
681
|
+
dimensions : List[int] | int, optional
|
|
682
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
683
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
684
|
+
rename : bool, optional
|
|
685
|
+
If True, then the old UEL names will be renamed with the new UEL names. By default False
|
|
686
|
+
"""
|
|
687
|
+
return self.alias_with.setUELs(uels=uels, dimensions=dimensions, rename=rename)
|
|
688
|
+
|
|
689
|
+
def reorderUELs(
|
|
690
|
+
self,
|
|
691
|
+
uels: Optional[Union[List[str], str]] = None,
|
|
692
|
+
dimensions: Optional[Union[List[int], int]] = None,
|
|
693
|
+
) -> None:
|
|
694
|
+
"""
|
|
695
|
+
Reorders the UELs in the parent set dimensions. If uels is None, reorder UELs to data order and append any unused categories.
|
|
696
|
+
If dimensions is None then reorder UELs in all dimensions of the parent set.
|
|
697
|
+
|
|
698
|
+
Parameters
|
|
699
|
+
----------
|
|
700
|
+
uels : List[str] | str, optional
|
|
701
|
+
dimensions : List[int] | int, optional
|
|
702
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
703
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
704
|
+
"""
|
|
705
|
+
return self.alias_with.reorderUELs(uels=uels, dimensions=dimensions)
|
|
706
|
+
|
|
707
|
+
def addUELs(
|
|
708
|
+
self,
|
|
709
|
+
uels: Union[List[str], str],
|
|
710
|
+
dimensions: Optional[Union[List[int], int]] = None,
|
|
711
|
+
) -> None:
|
|
712
|
+
"""
|
|
713
|
+
Adds UELs to the parent set dimensions. If dimensions is None then add UELs to all dimensions. ** All trailing whitespace is trimmed **
|
|
714
|
+
|
|
715
|
+
Parameters
|
|
716
|
+
----------
|
|
717
|
+
uels : List[str] | str
|
|
718
|
+
UELs to be added
|
|
719
|
+
dimensions : List[int] | int, optional
|
|
720
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
721
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
722
|
+
"""
|
|
723
|
+
return self.alias_with.addUELs(uels=uels, dimensions=dimensions)
|
|
724
|
+
|
|
725
|
+
def removeUELs(
|
|
726
|
+
self,
|
|
727
|
+
uels: Optional[Union[List[str], str]] = None,
|
|
728
|
+
dimensions: Optional[Union[List[int], int]] = None,
|
|
729
|
+
) -> None:
|
|
730
|
+
"""
|
|
731
|
+
Removes UELs that appear in the parent set dimensions, If uels is None then remove all unused UELs (categories). If dimensions is None then operate on all dimensions.
|
|
732
|
+
|
|
733
|
+
Parameters
|
|
734
|
+
----------
|
|
735
|
+
uels : List[str] | str, optional
|
|
736
|
+
UELs to be removed
|
|
737
|
+
dimensions : List[int] | int, optional
|
|
738
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
739
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
740
|
+
"""
|
|
741
|
+
return self.alias_with.removeUELs(uels=uels, dimensions=dimensions)
|
|
742
|
+
|
|
743
|
+
def renameUELs(
|
|
744
|
+
self,
|
|
745
|
+
uels: Union[List[str], str],
|
|
746
|
+
dimensions: Optional[Union[List[int], int]] = None,
|
|
747
|
+
allow_merge: bool = False,
|
|
748
|
+
) -> None:
|
|
749
|
+
"""
|
|
750
|
+
Renames UELs (case-sensitive) that appear in the parent set dimensions. If dimensions is None then operate on all dimensions of the symbol.
|
|
751
|
+
If allow_merge=True, the categorical object will be re-created to offer additional data flexibility. ** All trailing whitespace is trimmed **
|
|
752
|
+
|
|
753
|
+
Parameters
|
|
754
|
+
----------
|
|
755
|
+
uels : List[str] | str
|
|
756
|
+
UELs to be renamed
|
|
757
|
+
dimensions : List[int] | int, optional
|
|
758
|
+
Dimensions of the Alias to be processed. You can provide a single dimension as an int
|
|
759
|
+
or a list of dimensions. If not specified, it will process all dimensions.
|
|
760
|
+
allow_merge : bool
|
|
761
|
+
If True, the categorical object will be re-created to offer additional data flexibility
|
|
762
|
+
"""
|
|
763
|
+
return self.alias_with.renameUELs(
|
|
764
|
+
uels=uels, dimensions=dimensions, allow_merge=allow_merge
|
|
765
|
+
)
|
|
766
|
+
|
|
767
|
+
def _assert_valid_records(self):
|
|
768
|
+
self.alias_with._assert_valid_records()
|
|
769
|
+
|
|
770
|
+
def _assert_is_valid(self):
|
|
771
|
+
if self._requires_state_check:
|
|
772
|
+
if self.container is None:
|
|
773
|
+
raise Exception(
|
|
774
|
+
"Symbol is not currently linked to a container, "
|
|
775
|
+
"must add it to a container in order to be valid"
|
|
776
|
+
)
|
|
777
|
+
|
|
778
|
+
if self.alias_with is None:
|
|
779
|
+
raise Exception(
|
|
780
|
+
"Alias symbol is not valid because it is not currently linked to a parent set"
|
|
781
|
+
)
|
|
782
|
+
|
|
783
|
+
if not self.alias_with.isValid():
|
|
784
|
+
raise Exception(
|
|
785
|
+
"Alias symbol is not valid because parent "
|
|
786
|
+
f"set '{self.alias_with.name}' is not valid"
|
|
787
|
+
)
|
|
788
|
+
# if no exceptions, then turn self._requires_state_check 'off'
|
|
789
|
+
self._requires_state_check = False
|
|
790
|
+
|
|
791
|
+
@property
|
|
792
|
+
def alias_with(self) -> "Set":
|
|
793
|
+
"""
|
|
794
|
+
Returns the aliased object
|
|
795
|
+
|
|
796
|
+
Returns
|
|
797
|
+
-------
|
|
798
|
+
Set
|
|
799
|
+
The aliased Set
|
|
800
|
+
"""
|
|
801
|
+
return self._alias_with
|
|
802
|
+
|
|
803
|
+
@alias_with.setter
|
|
804
|
+
def alias_with(self, alias_with):
|
|
805
|
+
if isinstance(alias_with, ABCUniverseAlias):
|
|
806
|
+
raise TypeError(
|
|
807
|
+
"Cannot create an Alias to a UniverseAlias, create a new UniverseAlias symbol instead."
|
|
808
|
+
)
|
|
809
|
+
|
|
810
|
+
if not isinstance(alias_with, (ABCSet, ABCAlias)):
|
|
811
|
+
raise TypeError("Symbol 'alias_with' must be type Set or Alias")
|
|
812
|
+
|
|
813
|
+
if isinstance(alias_with, ABCAlias):
|
|
814
|
+
parent = alias_with
|
|
815
|
+
while not isinstance(parent, ABCSet):
|
|
816
|
+
parent = parent.alias_with
|
|
817
|
+
alias_with = parent
|
|
818
|
+
|
|
819
|
+
# check to see if _alias_with is being changed
|
|
820
|
+
if getattr(self, "_alias_with", None) != alias_with:
|
|
821
|
+
self._requires_state_check = True
|
|
822
|
+
self._alias_with = alias_with
|
|
823
|
+
self.modified = True
|
|
824
|
+
|
|
825
|
+
if isinstance(self.container, ABCContainer):
|
|
826
|
+
self.container._requires_state_check = True
|
|
827
|
+
self.container.modified = True
|
|
828
|
+
|
|
829
|
+
@property
|
|
830
|
+
def domain_names(self) -> List[str]:
|
|
831
|
+
"""
|
|
832
|
+
Returns the string version of domain names
|
|
833
|
+
|
|
834
|
+
Returns
|
|
835
|
+
-------
|
|
836
|
+
List[str]
|
|
837
|
+
A list of string version of domain names
|
|
838
|
+
"""
|
|
839
|
+
return self.alias_with.domain_names
|
|
840
|
+
|
|
841
|
+
@property
|
|
842
|
+
def domain(self) -> List[Union["Set", str]]:
|
|
843
|
+
"""
|
|
844
|
+
Returns list of domains given either as string (* for universe set) or as reference to the Set/Alias object
|
|
845
|
+
|
|
846
|
+
Returns
|
|
847
|
+
-------
|
|
848
|
+
List[Set | str]
|
|
849
|
+
A list of domains given either as string (* for universe set) or as reference to the Set/Alias object
|
|
850
|
+
"""
|
|
851
|
+
return self.alias_with.domain
|
|
852
|
+
|
|
853
|
+
@domain.setter
|
|
854
|
+
def domain(self, domain):
|
|
855
|
+
self.alias_with.domain = domain
|
|
856
|
+
self.modified = True
|
|
857
|
+
self.container.modified = True
|
|
858
|
+
|
|
859
|
+
@property
|
|
860
|
+
def domain_type(self) -> Union[str, None]:
|
|
861
|
+
"""
|
|
862
|
+
Returns the state of domain links
|
|
863
|
+
|
|
864
|
+
Returns
|
|
865
|
+
-------
|
|
866
|
+
str
|
|
867
|
+
none, relaxed or regular
|
|
868
|
+
"""
|
|
869
|
+
return self.alias_with.domain_type
|
|
870
|
+
|
|
871
|
+
@property
|
|
872
|
+
def description(self) -> str:
|
|
873
|
+
"""
|
|
874
|
+
Returns description of symbol
|
|
875
|
+
|
|
876
|
+
Returns
|
|
877
|
+
-------
|
|
878
|
+
str
|
|
879
|
+
Description of symbol
|
|
880
|
+
"""
|
|
881
|
+
return self.alias_with.description
|
|
882
|
+
|
|
883
|
+
@description.setter
|
|
884
|
+
def description(self, description):
|
|
885
|
+
self.alias_with.description = description
|
|
886
|
+
self.modified = True
|
|
887
|
+
self.container.modified = True
|
|
888
|
+
|
|
889
|
+
@property
|
|
890
|
+
def dimension(self) -> int:
|
|
891
|
+
"""
|
|
892
|
+
Returns the dimension of symbol
|
|
893
|
+
|
|
894
|
+
Returns
|
|
895
|
+
-------
|
|
896
|
+
int
|
|
897
|
+
Dimension of symbol
|
|
898
|
+
"""
|
|
899
|
+
return self.alias_with.dimension
|
|
900
|
+
|
|
901
|
+
@dimension.setter
|
|
902
|
+
def dimension(self, dimension):
|
|
903
|
+
self.alias_with.dimension = dimension
|
|
904
|
+
self.modified = True
|
|
905
|
+
self.container.modified = True
|
|
906
|
+
|
|
907
|
+
@property
|
|
908
|
+
def records(self) -> Union[pd.DataFrame, None]:
|
|
909
|
+
"""
|
|
910
|
+
Returns the main symbol records
|
|
911
|
+
|
|
912
|
+
Returns
|
|
913
|
+
-------
|
|
914
|
+
DataFrame | None
|
|
915
|
+
The main symbol records, None if no records were set
|
|
916
|
+
"""
|
|
917
|
+
return self.alias_with.records
|
|
918
|
+
|
|
919
|
+
@records.setter
|
|
920
|
+
def records(self, records):
|
|
921
|
+
self.alias_with.records = records
|
|
922
|
+
self.modified = True
|
|
923
|
+
self.container.modified = True
|
|
924
|
+
|
|
925
|
+
def setRecords(self, records: Any, uels_on_axes: bool = False) -> None:
|
|
926
|
+
"""
|
|
927
|
+
main convenience method to set standard pandas.DataFrame formatted records.
|
|
928
|
+
If uels_on_axes=True setRecords will assume that all domain information is contained in the axes of the pandas object – data will be flattened (if necessary).
|
|
929
|
+
|
|
930
|
+
Parameters
|
|
931
|
+
----------
|
|
932
|
+
records : Any
|
|
933
|
+
uels_on_axes : bool, optional
|
|
934
|
+
"""
|
|
935
|
+
self.alias_with.setRecords(records, uels_on_axes=uels_on_axes)
|
|
936
|
+
|
|
937
|
+
@property
|
|
938
|
+
def number_records(self) -> int:
|
|
939
|
+
"""
|
|
940
|
+
Returns the number of symbol records
|
|
941
|
+
|
|
942
|
+
Returns
|
|
943
|
+
-------
|
|
944
|
+
int
|
|
945
|
+
Number of symbol records
|
|
946
|
+
"""
|
|
947
|
+
return self.alias_with.number_records
|
|
948
|
+
|
|
949
|
+
@property
|
|
950
|
+
def domain_labels(self) -> Union[List[str], None]:
|
|
951
|
+
"""
|
|
952
|
+
Returns the column headings for the records DataFrame
|
|
953
|
+
|
|
954
|
+
Returns
|
|
955
|
+
-------
|
|
956
|
+
Union[List[str], None]
|
|
957
|
+
Column headings for the records DataFrame
|
|
958
|
+
"""
|
|
959
|
+
return self.alias_with.domain_labels
|
|
960
|
+
|
|
961
|
+
@domain_labels.setter
|
|
962
|
+
def domain_labels(self, labels):
|
|
963
|
+
self.alias_with.domain_labels = labels
|
|
964
|
+
|
|
965
|
+
@property
|
|
966
|
+
def summary(self) -> dict:
|
|
967
|
+
"""
|
|
968
|
+
Returns a dict of only the metadata
|
|
969
|
+
|
|
970
|
+
Returns
|
|
971
|
+
-------
|
|
972
|
+
dict
|
|
973
|
+
Outputs a dict of only the metadata
|
|
974
|
+
"""
|
|
975
|
+
return {
|
|
976
|
+
"name": self.name,
|
|
977
|
+
"description": self.description,
|
|
978
|
+
"alias_with": self.alias_with.name,
|
|
979
|
+
"is_singleton": self.is_singleton,
|
|
980
|
+
"domain": self.domain_names,
|
|
981
|
+
"domain_type": self.domain_type,
|
|
982
|
+
"dimension": self.dimension,
|
|
983
|
+
"number_records": self.number_records,
|
|
984
|
+
}
|