Skip to content

Commit

Permalink
fixed lint
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubervila authored and rcboufleur committed Jun 24, 2024
1 parent e4df0f9 commit 2d60cf6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 72 deletions.
42 changes: 0 additions & 42 deletions python/lsst/consdb/dao/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,45 +326,3 @@ def stm_to_str(self, stm, with_parameters=False):
sql = sql.replace("\n", " ").replace("\r", "")

return sql

# Possible faster solution specifically for postgresql using COPY.
# def import_with_copy_expert(self, sql, data):
# """
# This method is recommended for importing large volumes of data. using the postgresql COPY method.

# The method is useful to handle all the parameters that PostgreSQL makes available
# in COPY statement: https://www.postgresql.org/docs/current/sql-copy.html

# it is necessary that the from clause is reading from STDIN.

# example:
# sql = COPY <table> (<columns) FROM STDIN with (FORMAT CSV, DELIMITER '|', HEADER);

# Parameters:
# sql (str): The sql statement should be in the form COPY table '.
# data (file-like ): a file-like object to read or write
# Returns:
# rowcount (int): the number of rows that the last execute*() produced (for DQL statements like SELECT) or affected (for DML statements like UPDATE or INSERT)

# References:
# https://www.psycopg.org/docs/cursor.html#cursor.copy_from
# https://stackoverflow.com/questions/30050097/copy-data-from-csv-to-postgresql-using-python
# https://stackoverflow.com/questions/13125236/sqlalchemy-psycopg2-and-postgresql-copy
# """

# with warnings.catch_warnings():
# warnings.simplefilter("ignore", category=sa_exc.SAWarning)

# connection = self.get_db_engine().raw_connection()
# try:
# cursor = connection.cursor()
# cursor.copy_expert(sql, data)
# connection.commit()

# cursor.close()
# return cursor.rowcount
# except Exception as e:
# connection.rollback()
# raise (e)
# finally:
# connection.close()
18 changes: 12 additions & 6 deletions python/lsst/consdb/dao/exposure_efd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

class ExposureEfdDao(DBBase):
"""
A class representing a Data Access Object (DAO) for accessing ExposureEFD data.
A class representing a Data Access Object (DAO) for accessing
ExposureEFD data.
Args:
db_uri (str): The URI of the database.
Attributes:
tbl: The table object representing the "ExposureEFD" table in the database.
tbl: The table object representing the "ExposureEFD" table in the
database.
"""

Expand All @@ -28,7 +30,8 @@ def get_by_exposure_id(self, exposure_id: int):
exposure_id (int): The exposure ID.
Returns:
list: A list of dictionaries representing the rows retrieved from the table.
list: A list of dictionaries representing the rows retrieved from
the table.
"""
stm = select(self.tbl.c).where(and_(self.tbl.c.exposure_id == exposure_id))
Expand All @@ -39,14 +42,16 @@ def get_by_exposure_id(self, exposure_id: int):

def get_by_exposure_id_instrument(self, exposure_id: int, instrument: str):
"""
Retrieves rows from the "ExposureEFD" table based on exposure ID and instrument.
Retrieves rows from the "ExposureEFD" table based on exposure ID and
instrument.
Args:
exposure_id (int): The exposure ID.
instrument (str): The instrument name.
Returns:
list: A list of dictionaries representing the rows retrieved from the table.
list: A list of dictionaries representing the rows retrieved from
the table.
"""
stm = select(self.tbl.c).where(
Expand All @@ -73,7 +78,8 @@ def upsert(self, df: pandas.DataFrame, commit_every: int = 100) -> int:
Args:
df (pandas.DataFrame): The DataFrame to be upserted.
commit_every (int, optional): The number of rows to commit at a time. Defaults to 100.
commit_every (int, optional): The number of rows to commit
at a time. Defaults to 100.
Returns:
int: The number of rows upserted.
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/consdb/dao/visit_efd.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def upsert(self, df: pandas.DataFrame, commit_every: int = 100) -> int:
Args:
df (pandas.DataFrame): The DataFrame containing the data to upsert.
commit_every (int, optional): The number of rows to commit at once. Defaults to 100.
commit_every (int, optional): The number of rows to commit at once.
Defaults to 100.
Returns:
int: The number of rows upserted.
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/consdb/efd_transform/config_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Field(BaseModel):
Attributes:
name (str): The name of the field.
is_array (bool, optional): Indicates if the field is an array. Defaults to False.
is_array (bool, optional): Indicates if the field is an array.
Defaults to False.
"""

name: str
Expand Down
45 changes: 23 additions & 22 deletions python/lsst/consdb/efd_transform/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def apply(self, method_name: str) -> Union[float, None]:
method_name: Name of the method to apply.
Returns:
The result of the transformation method or None if the method is not found.
The result of the transformation method or None if the
method is not found.
"""
method = getattr(self, method_name, None)
if method:
Expand Down Expand Up @@ -59,7 +60,7 @@ def col_mean(self) -> float:
if numpy.size(self.values) == 0:
return numpy.nan

return numpy.nanmean(self.values, axis=0)
return numpy.nanmean(self.values, axis=0)

def std(self, ddof: Optional[int] = 1) -> float:
"""
Expand All @@ -73,7 +74,7 @@ def std(self, ddof: Optional[int] = 1) -> float:
"""
if numpy.size(self.values) == 0:
return numpy.nan

return numpy.nanstd(self.values, ddof=ddof)

def col_std(self, ddof: Optional[int] = 1) -> float:
Expand All @@ -88,8 +89,8 @@ def col_std(self, ddof: Optional[int] = 1) -> float:
"""
if numpy.size(self.values) == 0:
return numpy.nan
return numpy.nanstd(self.values, ddof=ddof, axis=0)

return numpy.nanstd(self.values, ddof=ddof, axis=0)

def max(self) -> Union[float, int, bool]:
"""
Expand All @@ -113,7 +114,7 @@ def col_max(self) -> Union[float, int, bool]:
if numpy.size(self.values) == 0:
return numpy.nan

return numpy.nanmax(self.values, axis=0)
return numpy.nanmax(self.values, axis=0)

def min(self) -> Union[float, int, bool]:
"""
Expand All @@ -137,7 +138,7 @@ def col_min(self) -> Union[float, int, bool]:
if numpy.size(self.values) == 0:
return numpy.nan

return numpy.nanmin(self.values, axis=0)
return numpy.nanmin(self.values, axis=0)

def logical_and(self) -> Union[bool, numpy.ndarray]:
"""
Expand All @@ -148,7 +149,7 @@ def logical_and(self) -> Union[bool, numpy.ndarray]:
"""
if numpy.size(self.values) == 0:
return numpy.nan

return numpy.all(self.values)

def col_logical_and(self) -> Union[bool, numpy.ndarray]:
Expand All @@ -160,8 +161,8 @@ def col_logical_and(self) -> Union[bool, numpy.ndarray]:
"""
if numpy.size(self.values) == 0:
return numpy.nan
return numpy.all(self.values, axis=0)

return numpy.all(self.values, axis=0)

def logical_or(self) -> Union[bool, numpy.ndarray]:
"""
Expand All @@ -172,7 +173,7 @@ def logical_or(self) -> Union[bool, numpy.ndarray]:
"""
if numpy.size(self.values) == 0:
return numpy.nan

return numpy.any(self.values)

def col_logical_or(self) -> Union[bool, numpy.ndarray]:
Expand All @@ -184,8 +185,8 @@ def col_logical_or(self) -> Union[bool, numpy.ndarray]:
"""
if numpy.size(self.values) == 0:
return numpy.nan
return numpy.any(self.values, axis=0)

return numpy.any(self.values, axis=0)

def logical_not(self) -> numpy.ndarray:
"""
Expand All @@ -196,7 +197,7 @@ def logical_not(self) -> numpy.ndarray:
"""
if numpy.size(self.values) == 0:
return numpy.nan

return ~numpy.all(self.values)

def col_logical_not(self) -> numpy.ndarray:
Expand All @@ -208,8 +209,8 @@ def col_logical_not(self) -> numpy.ndarray:
"""
if numpy.size(self.values) == 0:
return numpy.nan
return ~numpy.all(self.values, axis=0)

return ~numpy.all(self.values, axis=0)

def comma_unique(self) -> str:
"""
Expand All @@ -222,21 +223,21 @@ def comma_unique(self) -> str:
"""
if numpy.size(self.values) == 0:
return numpy.nan
values = self.values.split(',')
return ','.join(numpy.unique(values))
values = self.values.split(",")
return ",".join(numpy.unique(values))

def semicolon_unique(self) -> str:
"""
Returns a string with semicolon-separated unique values.
If the input string is empty, it returns NaN.
This method splits the input string by semicolons and returns a new string
with only the unique values, separated by semicolons.
This method splits the input string by semicolons and returns a
new string with only the unique values, separated by semicolons.
Returns:
str: A string with semicolon-separated unique values.
"""
if numpy.size(self.values) == 0:
return numpy.nan
values = self.values.split(';')
return ';'.join(numpy.unique(values))
values = self.values.split(";")
return ";".join(numpy.unique(values))

0 comments on commit 2d60cf6

Please sign in to comment.