27from ._schema
import Field, Schema
28from ._table
import SchemaMapper
35 doReplace=False, parse_strict="raise"):
36 """Add an un-mapped field to the output Schema.
41 The string name of the `Field`,
or a fully-constructed
42 `Field` object. If the latter, all other arguments
43 besides doReplace are ignored.
45 The type of field to create. Valid types are the keys of the
48 Documentation
for the field.
50 Units
for the field,
or an empty string
if unitless.
52 Size of the field; valid
for string
and array fields only.
54 If a field
with this name already exists, replace it instead of
57 One of
'raise' (default),
'warn',
or 'strict', indicating how to
58 handle unrecognized unit strings. See also astropy.units.Unit.
63 The key of the field added.
65 if isinstance(field, str):
66 field = Field[type](field, doc=doc, units=units,
67 size=size, parse_strict=parse_strict)
68 return field._addTo(self.editOutputSchema(), doReplace)
70 def addMapping(self, input, output=None, doReplace=True):
71 """Add a mapped field to the output schema.
76 A `Key` from the input schema whose values will be mapped to the new
79 A `Field` object that describes the new field to be added to the
80 output schema,
or the name of the field (
with documentation
and
81 units copied
from the input schema). May be
None to copy everything
82 from the input schema.
84 If a field
with this name already exists
in the output schema,
90 The key
for the new mapped field.
95 if output
is True or output
is False:
98 return input._addMappingTo(self, output, doReplace)
101 """SchemaMappers are equal if their respective input and output
102 schemas are identical, and they have the same mappings defined.
104 Note: It was simpler to implement equality
in python than
in C++.
106 iSchema = self.getInputSchema()
107 oSchema = self.getOutputSchema()
108 if (
not (iSchema.compare(other.getInputSchema(), Schema.IDENTICAL) == Schema.IDENTICAL
109 and oSchema.compare(other.getOutputSchema(), Schema.IDENTICAL) == Schema.IDENTICAL)):
113 if self.isMapped(item.key)
and other.isMapped(item.key):
114 if (self.getMapping(item.key) == other.getMapping(item.key)):
118 elif (
not self.isMapped(item.key))
and (
not other.isMapped(item.key)):
126 """To support pickle."""
128 for item
in self.getInputSchema():
130 key = self.getMapping(item.key)
134 mappings[item.key] = self.getOutputSchema().find(key).field
135 return (makeSchemaMapper, (self.getInputSchema(), self.getOutputSchema(), mappings))
139 """Build a mapper from two Schemas and the mapping between them.
145 The input schema for the mapper.
147 The output schema
for the mapper.
149 The mappings to define between the input
and output schema.
154 The constructed SchemaMapper.
157 for key, value
in mappings.items():
158 mapper.addMapping(key, value)
addOutputField(self, field, type=None, doc=None, units="", size=None, doReplace=False, parse_strict="raise")
addMapping(self, input, output=None, doReplace=True)
A class used as a handle to a particular field in a table.
Defines the fields and offsets for a table.
A mapping between the keys of two Schemas, used to copy data between them.
Reports invalid arguments.
Reports attempts to access elements using an invalid key.
makeSchemaMapper(input, output, mappings)
A description of a field in a table.