Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage committed Aug 5, 2024
1 parent 2c6a2a4 commit c93407d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/user/initializing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ There are several ways to initialize a `PintArray`s` in a `DataFrame`. Here's th
df
In the first two Series examples above, the data was converted to Float64.
In the first two Series examples above, the data was converted to Float64.

.. ipython:: python
df.dtypes
To avoid this conversion, specify the subdtype (dtype of the magnitudes) in the dtype `"pint[m][Int64]"` when constructing using a `Series`. The default data dtype that pint-pandas converts to can be changed by modifying `pint_pandas.DEFAULT_SUBDTYPE`.

Expand Down
6 changes: 4 additions & 2 deletions pint_pandas/pint_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ class PintArray(ExtensionArray, ExtensionScalarOpsMixin):

def __init__(self, values, dtype=None, copy=False):
# infer subdtype from values if not given in dtype
if (isinstance(dtype, str) and dtype.count("[") <= 1) or isinstance(dtype, _Unit):
if (isinstance(dtype, str) and dtype.count("[") <= 1) or isinstance(
dtype, _Unit
):
_dtype = PintType(dtype)
if isinstance(values, _Quantity):
values = values.m_as(_dtype.units)
Expand All @@ -316,7 +318,7 @@ def __init__(self, values, dtype=None, copy=False):
if dtype is None:
if isinstance(values, _Quantity):
units = values.units
values = pd.array(values.magnitude, copy=copy)
values = pd.array(values, copy=copy)
dtype = PintType(units=units, subdtype=values.dtype)
elif isinstance(values, PintArray):
dtype = values._dtype
Expand Down

0 comments on commit c93407d

Please sign in to comment.