Skip to content

Commit 47f838e

Browse files
committed
Simplify import
1 parent bbb902c commit 47f838e

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/physt/compat/pandas.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from typing import TYPE_CHECKING, NoReturn, Optional, Tuple, cast
1111

1212
import numpy as np
13-
import pandas
1413
import pandas as pd
1514
from pandas.api.types import is_numeric_dtype
1615

@@ -27,7 +26,7 @@
2726

2827
@extract_1d_array.register
2928
def _(
30-
series: pandas.Series, *, dropna: bool = True
29+
series: pd.Series, *, dropna: bool = True
3130
) -> Tuple[np.ndarray, Optional[np.ndarray]]:
3231
if not pd.api.types.is_numeric_dtype(series):
3332
raise ValueError(
@@ -85,14 +84,14 @@ def _(
8584
return data_frame.shape[1], array, array_mask
8685

8786

88-
@pandas.api.extensions.register_series_accessor("physt")
87+
@pd.api.extensions.register_series_accessor("physt")
8988
class PhystSeriesAccessor:
9089
"""Histogramming methods for pandas Series.
9190
9291
It exists only for numeric series.
9392
"""
9493

95-
def __init__(self, series: pandas.Series):
94+
def __init__(self, series: pd.Series):
9695
if not is_numeric_dtype(series):
9796
raise AttributeError(
9897
f"Series must be of a numeric type, not {series.dtype}"
@@ -116,11 +115,11 @@ def cut(self, bins=None, **kwargs) -> pd.Series:
116115
return pd.cut(self._series, binning.numpy_bins)
117116

118117

119-
@pandas.api.extensions.register_dataframe_accessor("physt")
118+
@pd.api.extensions.register_dataframe_accessor("physt")
120119
class PhystDataFrameAccessor:
121120
"""Histogramming methods for pandas DataFrames."""
122121

123-
def __init__(self, df: pandas.DataFrame):
122+
def __init__(self, df: pd.DataFrame):
124123
self._df = df
125124

126125
def h1(
@@ -230,17 +229,17 @@ def histogram(self, columns: Any = None, bins: Any = None, **kwargs) -> Histogra
230229

231230
def binning_to_index(
232231
binning: BinningBase, name: Optional[str] = None
233-
) -> pandas.IntervalIndex:
232+
) -> pd.IntervalIndex:
234233
"""Convert physt binning to a pandas interval index."""
235234
# TODO: Check closedness
236-
return pandas.IntervalIndex.from_arrays(
235+
return pd.IntervalIndex.from_arrays(
237236
left=binning.bins[:, 0], right=binning.bins[:, 1], closed="left", name=name
238237
)
239238

240239

241-
def index_to_binning(index: pandas.IntervalIndex) -> BinningBase:
240+
def index_to_binning(index: pd.IntervalIndex) -> BinningBase:
242241
"""Convert an interval index into physt binning."""
243-
if not isinstance(index, pandas.IntervalIndex):
242+
if not isinstance(index, pd.IntervalIndex):
244243
raise TypeError(f"IntervalIndex required, '{type(index)}' passed.")
245244
if not index.closed_left:
246245
raise ValueError("Only `closed_left` indices supported.")
@@ -252,17 +251,17 @@ def index_to_binning(index: pandas.IntervalIndex) -> BinningBase:
252251
return static_binning(bins=bins)
253252

254253

255-
def _h1_to_dataframe(h1: Histogram1D) -> pandas.DataFrame:
254+
def _h1_to_dataframe(h1: Histogram1D) -> pd.DataFrame:
256255
"""Convert histogram to pandas DataFrame."""
257-
return pandas.DataFrame(
256+
return pd.DataFrame(
258257
{"frequency": h1.frequencies, "error": h1.errors},
259258
index=binning_to_index(h1.binning, name=h1.name),
260259
)
261260

262261

263-
def _h1_to_series(h1: Histogram1D) -> pandas.Series:
262+
def _h1_to_series(h1: Histogram1D) -> pd.Series:
264263
"""Convert histogram to pandas Series."""
265-
return pandas.Series(
264+
return pd.Series(
266265
h1.frequencies,
267266
name="frequency",
268267
index=binning_to_index(h1.binning, name=h1.name),

src/physt/statistics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def __eq__(self, other):
9898
)
9999

100100
def __rich_repr__(self):
101+
# Output interesting attributes instead of internal representation
101102
yield "mean", self.mean
102103
yield "std", self.std
103104
yield "min", self.min

0 commit comments

Comments
 (0)