Skip to content

Commit

Permalink
change black
Browse files Browse the repository at this point in the history
  • Loading branch information
mazarimono committed Nov 8, 2023
1 parent 21e45bc commit daad068
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
- name: code formatter
run: |
isort .
black *
black j_realty_api/*.py
32 changes: 15 additions & 17 deletions j_realty_api/j_realty_en.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def get_data(self) -> pd.DataFrame:
try:
df = pd.DataFrame(r.json()["data"])
df["Period"] = df["Period"].map(self.custom_to_datetime)
df['TradePrice'] = df['TradePrice'].astype("Int64")
df['UnitPrice'] = pd.to_numeric(df['UnitPrice'], errors='ignore')
df["TradePrice"] = df["TradePrice"].astype("Int64")
df["UnitPrice"] = pd.to_numeric(df["UnitPrice"], errors="ignore")
return df
except KeyError:
print(
Expand All @@ -129,35 +129,35 @@ def get_data(self) -> pd.DataFrame:
else:
raise Exception(f"Status_code: {r.status_code}")


def to_forex(self, df: pd.DataFrame, currency: str) -> pd.DataFrame:
'''
"""
Params:
df: pd.DataFrame
DataFrame from get_data()
currency: str
select from 3types: "USD", "EUR", "CNY"
Returns:
pd.DataFrame
'''
dates = df['Period'].unique()
"""
dates = df["Period"].unique()
min_date = dates.min().to_timestamp().date()
max_date = dates.max().to_timestamp(how='End').date()
max_date = dates.max().to_timestamp(how="End").date()
min_date_str = self.dt_to_string(min_date)
max_date_str = self.dt_to_string(max_date)
cur = jpyforex.JPYForex(currency=currency, freq='Q', start_date=min_date_str, end_date=max_date_str)
cur = jpyforex.JPYForex(
currency=currency, freq="Q", start_date=min_date_str, end_date=max_date_str
)
data = cur.get_data()
data.index = data.index.to_period('Q')
data.index = data.index.to_period("Q")
forex_data = dict()
for i in data.index:
forex_data[i] = data.loc[i].values[0]
df['forex'] = df['Period'].map(forex_data)
df['ForexTradePrice'] = df.apply(lambda x: x['TradePrice'] / x['forex'], axis=1)
df['ForexUnitPrice'] = df.apply(lambda x: x['UnitPrice'] / x['forex'], axis=1)
df["forex"] = df["Period"].map(forex_data)
df["ForexTradePrice"] = df.apply(lambda x: x["TradePrice"] / x["forex"], axis=1)
df["ForexUnitPrice"] = df.apply(lambda x: x["UnitPrice"] / x["forex"], axis=1)
return df


def custom_to_datetime(self, p_str):
split_str = p_str.split(" ")
year = int(split_str[2])
Expand All @@ -177,19 +177,17 @@ def custom_to_datetime(self, p_str):
else:
raise ValueError(f"invalid quater: {p_str}")


def dt_to_qt(self, year, month):
dt = datetime(year, month, 1)
ts = pd.Timestamp(dt)
qt = ts.to_period("Q")
return qt


def dt_to_string(self, dt: datetime) -> str:
year = dt.year
month = dt.month
date = dt.day
str_dt = f'{year}{month:02}{date:02}'
str_dt = f"{year}{month:02}{date:02}"
return str_dt


Expand Down

0 comments on commit daad068

Please sign in to comment.