Best Python code snippet using pandera_python
io.py
Source:io.py
...268)269MULTIINDEX_TEMPLATE = """270MultiIndex(indexes=[{indexes}])271"""272def _format_checks(checks_dict):273 if checks_dict is None:274 return "None"275 checks = []276 for check_name, check_kwargs in checks_dict.items():277 if check_kwargs is None:278 warnings.warn(279 f"Check {check_name} cannot be serialized. "280 "This check will be ignored"281 )282 else:283 args = ", ".join(284 f"{k}={v.__repr__()}" for k, v in check_kwargs.items()285 )286 checks.append(f"Check.{check_name}({args})")287 return f"[{', '.join(checks)}]"288def _format_index(index_statistics):289 index = []290 for properties in index_statistics:291 dtype = properties.get("dtype")292 index_code = INDEX_TEMPLATE.format(293 dtype=f"{_get_qualified_name(dtype.__class__)}",294 checks=(295 "None"296 if properties["checks"] is None297 else _format_checks(properties["checks"])298 ),299 nullable=properties["nullable"],300 coerce=properties["coerce"],301 name=(302 "None"303 if properties["name"] is None304 else f"\"{properties['name']}\""305 ),306 )307 index.append(index_code.strip())308 if len(index) == 1:309 return index[0]310 return MULTIINDEX_TEMPLATE.format(indexes=",".join(index)).strip()311def _format_script(script):312 formatter = partial(black.format_str, mode=black.FileMode(line_length=80))313 return formatter(script)314def to_script(dataframe_schema, path_or_buf=None):315 """Write :class:`~pandera.schemas.DataFrameSchema` to a python script.316 :param dataframe_schema: schema to write to file or dump to string.317 :param path_or_buf: filepath or buf stream to write to. If None, outputs318 string representation of the script.319 :returns: yaml string if stream is None, otherwise returns None.320 """321 statistics = get_dataframe_schema_statistics(dataframe_schema)322 columns = {}323 for colname, properties in statistics["columns"].items():324 dtype = properties.get("dtype")325 column_code = COLUMN_TEMPLATE.format(326 dtype=(327 None if dtype is None else _get_qualified_name(dtype.__class__)328 ),329 checks=_format_checks(properties["checks"]),330 nullable=properties["nullable"],331 unique=properties["unique"],332 coerce=properties["coerce"],333 required=properties["required"],334 regex=properties["regex"],335 )336 columns[colname] = column_code.strip()337 index = (338 None339 if statistics["index"] is None340 else _format_index(statistics["index"])341 )342 column_str = ", ".join(f"'{k}': {v}" for k, v in columns.items())343 script = SCRIPT_TEMPLATE.format(...
sdcard.py
Source:sdcard.py
...123 :exception DeviceException: When unable to mount.124 """125 126 self._sd.mount(directory)127 def _format_checks(self):128 if self._sd.exists is False:129 raise SDCardInstallerError('No disk on %s' % self._sd.name)130 if self._sd.is_mounted:131 if self._interactive:132 ret = self._sd.confirmed_unmount()133 if ret is False:134 raise SDCardInstallerError('User canceled')135 else:136 self._sd.unmount()137 if self._sd.size_cyl == 0:138 raise SDCardInstallerError('%s size is 0' % self._sd.name)139 if self._sd.size_cyl < self._sd.min_cyl_size():140 raise SDCardInstallerError('Size of partitions is too large to '141 'fit in %s' % self._sd.name)142 143 def _format_confirms(self):144 if self._sd.confirm_size_gb(WARN_DEVICE_SIZE_GB) is False:145 raise SDCardInstallerError('User canceled')146 msg = ('You are about to repartition %s (all your data will be lost)' 147 % self._sd.name)148 confirmed = self._e.prompt_user(msg, WARN_COLOR)149 if not confirmed:150 raise SDCardInstallerError('User canceled')151 152 def format(self):153 """154 Creates and formats the partitions in the SD card.155 156 :returns: Returns true on success; false otherwise.157 :exception DeviceException: On failure formatting the device.158 :exception SDCardInstallerError: On failure executing this action. 159 """160 161 if not self.dryrun:162 self._format_checks()163 if self._interactive:164 self._format_confirms()165 self._l.info('Formatting %s (this may take a while)' % self._sd.name)166 self._sd.wipe_bootloader_env()167 self._sd.create_partitions()168 self._sd.format_partitions()169 def release(self):170 """171 Unmounts all partitions and release the given device.172 173 :exception DeviceException: On failure releasing the device.174 """175 176 self._sd.unmount()...
usb.py
Source:usb.py
...146 :exception DeviceException: When unable to mount.147 """148 149 self._usb.mount(directory)150 def _format_checks(self):151 if self._usb.exists is False:152 raise USBInstallerError('No disk on %s' % self._usb.name)153 if self._usb.is_mounted:154 if self._interactive:155 ret = self._usb.confirmed_unmount()156 if ret is False:157 raise USBInstallerError('User canceled')158 else:159 self._usb.unmount()160 if self._usb.size_cyl == 0:161 raise USBInstallerError('%s size is 0' % self._usb.name)162 if self._usb.size_cyl < self._usb.min_cyl_size():163 raise USBInstallerError('Size of partitions is too large to '164 'fit in %s' % self._usb.name)165 166 def _format_confirms(self):167 if self._usb.confirm_size_gb(WARN_DEVICE_SIZE_GB) is False:168 raise USBInstallerError('User canceled')169 msg = ('You are about to repartition %s (all your data will be lost)' 170 % self._usb.name)171 confirmed = self._e.prompt_user(msg, WARN_COLOR)172 if not confirmed:173 raise USBInstallerError('User canceled')174 175 def format(self):176 """177 Creates and formats the partitions in the SD card.178 179 :returns: Returns true on success; false otherwise.180 :exception DeviceException: On failure formatting the device.181 :exception USBInstallerError: On failure executing this action. 182 """183 184 if not self.dryrun:185 self._format_checks()186 if self._interactive:187 self._format_confirms()188 self._l.info('Formatting %s (this may take a while)' % self._usb.name)189 self._usb.create_partitions()190 self._usb.format_partitions()191 def release(self):192 """193 Unmounts all partitions and release the given device.194 195 :exception DeviceException: On failure releasing the device.196 """197 198 self._usb.unmount()199 self._usb.optimize_filesystems()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!